Skip to content

Perf[MQB]: separate BlobSpPools and BufferFactories per FileStore thread #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@
#include <bmqscm_version.h>

// BDE
#include <bdlbb_pooledblobbufferfactory.h>
#include <bsls_assert.h>

namespace BloombergLP {
namespace bmqp {

namespace {
const int k_BLOBBUFFER_SIZE = 4 * 1024;
const int k_BLOB_POOL_GROWTH_STRATEGY = 1024;

/// Create a new blob at the specified `arena` address, using the specified
/// `bufferFactory` and `allocator`.
void createBlob(bdlbb::BlobBufferFactory* bufferFactory,
void* arena,
bslma::Allocator* allocator)
void createBlob(
const bsl::shared_ptr<bdlbb::BlobBufferFactory>& bufferFactory_sp,
void* arena,
bslma::Allocator* allocator)
{
new (arena) bdlbb::Blob(bufferFactory, allocator);
new (arena) bdlbb::Blob(bufferFactory_sp.get(), allocator);
}

} // close unnamed namespace
Expand All @@ -42,6 +45,26 @@ void createBlob(bdlbb::BlobBufferFactory* bufferFactory,
// class BlobPoolUtil
// ------------------

BlobPoolUtil::BlobSpPoolSp
BlobPoolUtil::createBlobPool(bslma::Allocator* allocator)
{
bslma::Allocator* alloc = bslma::Default::allocator(allocator);

bsl::shared_ptr<bdlbb::BlobBufferFactory> bufferFactory_sp =
bsl::allocate_shared<bdlbb::PooledBlobBufferFactory>(
alloc,
k_BLOBBUFFER_SIZE,
bsls::BlockGrowth::BSLS_CONSTANT);

return bsl::allocate_shared<BlobSpPool>(
alloc,
bdlf::BindUtil::bind(&createBlob,
bufferFactory_sp,
bdlf::PlaceHolders::_1, // arena
bdlf::PlaceHolders::_2), // allocator
k_BLOB_POOL_GROWTH_STRATEGY);
}

BlobPoolUtil::BlobSpPoolSp
BlobPoolUtil::createBlobPool(bdlbb::BlobBufferFactory* blobBufferFactory_p,
bslma::Allocator* allocator)
Expand All @@ -51,10 +74,14 @@ BlobPoolUtil::createBlobPool(bdlbb::BlobBufferFactory* blobBufferFactory_p,

bslma::Allocator* alloc = bslma::Default::allocator(allocator);

bsl::shared_ptr<bdlbb::BlobBufferFactory> bufferFactory_sp(
blobBufferFactory_p,
bslstl::SharedPtrNilDeleter());

return bsl::allocate_shared<BlobSpPool>(
alloc,
bdlf::BindUtil::bind(&createBlob,
blobBufferFactory_p,
bufferFactory_sp,
bdlf::PlaceHolders::_1, // arena
bdlf::PlaceHolders::_2), // allocator
k_BLOB_POOL_GROWTH_STRATEGY);
Expand Down
2 changes: 2 additions & 0 deletions src/groups/bmq/bmqp/bmqp_blobpoolutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct BlobPoolUtil {
static BlobSpPoolSp
createBlobPool(bdlbb::BlobBufferFactory* blobBufferFactory_p,
bslma::Allocator* allocator = 0);

static BlobSpPoolSp createBlobPool(bslma::Allocator* allocator = 0);
};

} // close package namespace
Expand Down
7 changes: 6 additions & 1 deletion src/groups/mqb/mqbc/mqbc_storagemanager.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ struct TestHelper {
const mqbcfg::PartitionConfig& partitionCfg =
d_cluster_mp->_clusterDefinition().partitionConfig();

bmqp::BlobPoolUtil::BlobSpPoolSp blobSpPool_sp =
bmqp::BlobPoolUtil::createBlobPool(
&d_cluster_mp->_clusterData()->bufferFactory(),
bmqtst::TestHelperUtil::allocator());

mqbs::DataStoreConfig dsCfg;
dsCfg.setScheduler(&d_cluster_mp->_scheduler())
.setBufferFactory(&d_cluster_mp->_clusterData()->bufferFactory())
Expand Down Expand Up @@ -894,7 +899,7 @@ struct TestHelper {
d_cluster_mp->dispatcher(),
&d_cluster_mp->netCluster(),
&d_cluster_mp->_clusterData()->stats(),
&d_cluster_mp->_clusterData()->blobSpPool(),
blobSpPool_sp,
&d_cluster_mp->_clusterData()->stateSpPool(),
&threadPool,
d_cluster_mp->isCSLModeEnabled(),
Expand Down
54 changes: 32 additions & 22 deletions src/groups/mqb/mqbc/mqbc_storageutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,26 @@ int StorageUtil::assignPartitionDispatcherThreads(
mqbi::DispatcherClientType::e_QUEUE);
BSLS_ASSERT_SAFE(numProcessors > 0);

bslma::Allocator* baseAllocator = allocators->baseAllocator();
bsl::vector<bslma::Allocator*> queueThreadAllocators(numProcessors,
baseAllocator);
bsl::vector<bmqp::BlobPoolUtil::BlobSpPoolSp> blobSpPools(numProcessors,
baseAllocator);

// Allocater per-thread resources
for (int i = 0; i < numProcessors; ++i) {
bmqu::MemOutStream allocatorName(baseAllocator);
allocatorName << "QueueDispatcherThread" << i;

bslma::Allocator* queueThreadAllocator = allocators->get(
allocatorName.str());
queueThreadAllocators.at(i) = queueThreadAllocator;
blobSpPools.at(i) = bmqp::BlobPoolUtil::createBlobPool(
queueThreadAllocator);
}

for (int i = 0; i < config.numPartitions(); ++i) {
int processorId = i % numProcessors;
const int processorId = i % numProcessors;
mqbs::DataStoreConfig dsCfg;
dsCfg.setScheduler(&clusterData->scheduler())
.setBufferFactory(&clusterData->bufferFactory())
Expand All @@ -1250,27 +1268,19 @@ int StorageUtil::assignPartitionDispatcherThreads(
dsCfg.setQueueDeletionCb(queueDeletionCb.value());
}

// Get named allocator from associated bmqma::CountingAllocatorStore
bslma::Allocator* fileStoreAllocator = allocators->get(
bsl::string("Partition") + bsl::to_string(i));

bsl::shared_ptr<mqbs::FileStore> fsSp(
new (*fileStoreAllocator)
mqbs::FileStore(dsCfg,
processorId,
dispatcher,
clusterData->membership().netCluster(),
&clusterData->stats(),
blobSpPool,
&clusterData->stateSpPool(),
threadPool,
cluster.isCSLModeEnabled(),
cluster.isFSMWorkflow(),
replicationFactor,
fileStoreAllocator),
fileStoreAllocator);

(*fileStores)[i] = fsSp;
(*fileStores)[i] = bsl::allocate_shared<mqbs::FileStore>(
queueThreadAllocators.at(processorId),
dsCfg,
processorId,
dispatcher,
clusterData->membership().netCluster(),
&clusterData->stats(),
blobSpPools.at(processorId),
&clusterData->stateSpPool(),
threadPool,
cluster.isCSLModeEnabled(),
cluster.isFSMWorkflow(),
replicationFactor);
}

return rc_SUCCESS;
Expand Down
21 changes: 11 additions & 10 deletions src/groups/mqb/mqbs/mqbs_filestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3947,7 +3947,8 @@ void FileStore::processReceiptEvent(unsigned int primaryLeaseId,
if (itNode == d_nodes.end()) {
// no prior history about this node
d_nodes.insert(
bsl::make_pair(nodeId, NodeContext(d_blobSpPool_p, recordKey)));
bsl::make_pair(nodeId,
NodeContext(d_blobSpPool_sp.get(), recordKey)));
from = d_unreceipted.begin();
}
else if (itNode->second.d_key < recordKey) {
Expand Down Expand Up @@ -5207,7 +5208,7 @@ void FileStore::aliasMessage(bsl::shared_ptr<bdlbb::Blob>* appData,

bdlbb::BlobBuffer optionsBlobBuffer(optionsBufferSp, optionsSize);

*options = d_blobSpPool_p->getObject();
*options = d_blobSpPool_sp->getObject();
(*options)->appendDataBuffer(optionsBlobBuffer);
}

Expand All @@ -5218,7 +5219,7 @@ void FileStore::aliasMessage(bsl::shared_ptr<bdlbb::Blob>* appData,
bdlbb::BlobBuffer appDataBlobBuffer(appDataBufferSp,
record.d_appDataUnpaddedLen);

*appData = d_blobSpPool_p->getObject();
*appData = d_blobSpPool_sp->getObject();
(*appData)->appendDataBuffer(appDataBlobBuffer);
}

Expand All @@ -5238,7 +5239,7 @@ FileStore::FileStore(const DataStoreConfig& config,
mqbi::Dispatcher* dispatcher,
mqbnet::Cluster* cluster,
mqbstat::ClusterStats* clusterStats,
BlobSpPool* blobSpPool,
BlobSpPoolSp blobSpPool_sp,
StateSpPool* statePool,
bdlmt::FixedThreadPool* miscWorkThreadPool,
bool isCSLModeEnabled,
Expand All @@ -5252,7 +5253,7 @@ FileStore::FileStore(const DataStoreConfig& config,
, d_partitionDescription(allocator)
, d_dispatcherClientData()
, d_clusterStats_p(clusterStats)
, d_blobSpPool_p(blobSpPool)
, d_blobSpPool_sp(blobSpPool_sp)
, d_statePool_p(statePool)
, d_aliasedBufferDeleterSpPool(1024, d_allocators.get("AliasedBufferDeleters"))
, d_isOpen(false)
Expand Down Expand Up @@ -5282,7 +5283,7 @@ FileStore::FileStore(const DataStoreConfig& config,
, d_nagglePacketCount(k_NAGLE_PACKET_COUNT)
, d_storageEventBuilder(FileStoreProtocol::k_VERSION,
bmqp::EventType::e_STORAGE,
d_blobSpPool_p,
d_blobSpPool_sp.get(),
allocator)
{
// PRECONDITIONS
Expand Down Expand Up @@ -6578,9 +6579,9 @@ FileStore::generateReceipt(NodeContext* nodeContext,
if (itNode == d_nodes.end()) {
// no prior history about this node
itNode = d_nodes
.insert(
bsl::make_pair(nodeId,
NodeContext(d_blobSpPool_p, key)))
.insert(bsl::make_pair(
nodeId,
NodeContext(d_blobSpPool_sp.get(), key)))
.first;
}
nodeContext = &itNode->second;
Expand Down Expand Up @@ -6610,7 +6611,7 @@ FileStore::generateReceipt(NodeContext* nodeContext,
// The pointer `nodeContext->d_blob_sp` might be in a write queue, so
// it's not safe to modify or replace the blob under this pointer.
// Instead, we get another shared pointer to another blob.
nodeContext->d_blob_sp = d_blobSpPool_p->getObject();
nodeContext->d_blob_sp = d_blobSpPool_sp->getObject();
bmqp::ProtocolUtil::buildReceipt(nodeContext->d_blob_sp.get(),
d_config.partitionId(),
primaryLeaseId,
Expand Down
6 changes: 3 additions & 3 deletions src/groups/mqb/mqbs/mqbs_filestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore {

public:
// TYPES

typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool;
typedef bmqp::BlobPoolUtil::BlobSpPoolSp BlobSpPoolSp;

/// Pool of shared pointers to AtomicStates
typedef bdlcc::SharedObjectPool<
Expand Down Expand Up @@ -290,7 +290,7 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore {
// used to report partition level
// metrics.

mutable BlobSpPool* d_blobSpPool_p;
mutable BlobSpPoolSp d_blobSpPool_sp;
// Pool of shared pointers to blobs to
// use.

Expand Down Expand Up @@ -697,7 +697,7 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore {
mqbi::Dispatcher* dispatcher,
mqbnet::Cluster* cluster,
mqbstat::ClusterStats* clusterStats,
BlobSpPool* blobSpPool,
BlobSpPoolSp blobSpPool,
StateSpPool* statePool,
bdlmt::FixedThreadPool* miscWorkThreadPool,
bool isCSLModeEnabled,
Expand Down
2 changes: 1 addition & 1 deletion src/groups/mqb/mqbs/mqbs_filestore.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ struct Tester {
&d_dispatcher,
d_cluster_mp.get(),
&d_clusterStats,
d_blobSpPool_sp.get(),
d_blobSpPool_sp,
&d_statePool,
&d_miscWorkThreadPool,
false, // isCSLModeEnabled
Expand Down
Loading