Skip to content

Commit 83eb181

Browse files
authored
perf(cs): make inputBuffer size progressive (#764)
The current implementation of the WriteHighLevelOp class always asks for maxBlocksPerHddWriteJob_ blocks for its next inputBuffer_, i.e the structure to land the upcoming data blocks to be written to the drive. This can became a significant waste of memory when the write high level operation only writes 1 block, but asks for 32, if the MAX_BLOCKS_PER_HDD_WRITE_JOB is set to that number, for instance. The change proposed targets asking for smaller initial input buffers, to limit the memory wasted. Considering the previous case, the write high level operation will ask for 4, 8, 16, 32 and continue asking for input buffers of 32 blocks. The main downside is a possible increase in the number of drive operations in certain scenarios. Signed-off-by: Dave <dave@leil.io>
1 parent b6ebcdf commit 83eb181

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/chunkserver/chunk_high_level_ops.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ void WriteHighLevelOp::prepareInputBufferForWrite(bool isForward) {
466466
if (inputBuffer_ == nullptr) {
467467
inputBuffer_ = getWriteInputBufferPool().get(
468468
isForward ? kSauWriteDataPrefixSizeForward : kSauWriteDataPrefixSize,
469-
maxBlocksPerHddWriteJob_);
469+
nextInputBufferBlockCount_);
470+
471+
nextInputBufferBlockCount_ =
472+
std::min<uint16_t>(nextInputBufferBlockCount_ * 2, maxBlocksPerHddWriteJob_);
470473
}
471474

472475
inputBuffer_->addNewWriteOperation();
@@ -573,6 +576,8 @@ void WriteHighLevelOp::cleanup() {
573576
partiallyCompletedWrites_.clear();
574577
chunkId_ = 0;
575578
chunkVersion_ = 0;
579+
nextInputBufferBlockCount_ =
580+
std::min(kDefaultInitialNextInputBufferBlockCount, maxBlocksPerHddWriteJob_);
576581
chunkType_ = slice_traits::standard::ChunkPartType();
577582
}
578583

src/chunkserver/chunk_high_level_ops.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,15 @@ class ReadHighLevelOp : public HighLevelOp {
207207
/// @brief High-level operation for writing data to a chunk.
208208
class WriteHighLevelOp : public HighLevelOp {
209209
public:
210+
/// @brief Default initial number of blocks for the next input buffer, which can be adjusted
211+
/// based on the max blocks per HDD write job.
212+
constexpr static uint16_t kDefaultInitialNextInputBufferBlockCount = 4;
213+
210214
WriteHighLevelOp(ChunkserverEntry *parent, uint16_t maxBlocksPerHddWriteJob)
211-
: HighLevelOp(parent), maxBlocksPerHddWriteJob_(maxBlocksPerHddWriteJob) {}
215+
: HighLevelOp(parent),
216+
maxBlocksPerHddWriteJob_(maxBlocksPerHddWriteJob),
217+
nextInputBufferBlockCount_(
218+
std::min(kDefaultInitialNextInputBufferBlockCount, maxBlocksPerHddWriteJob)) {}
212219

213220
/// Sets up and starts the write high level operation.
214221
/// Enqueues a job_open for the chunk.
@@ -299,10 +306,13 @@ class WriteHighLevelOp : public HighLevelOp {
299306

300307
/// Prepares the input buffer for a write operation.
301308
void prepareInputBufferForWrite(bool isForward);
302-
303-
///< Number of blocks to write to the device in one write job.
309+
310+
/// Number of blocks to write to the device in one write job.
304311
uint16_t maxBlocksPerHddWriteJob_;
305312

313+
/// Size in blocks of the next input buffer.
314+
uint16_t nextInputBufferBlockCount_;
315+
306316
/// Indicates if the chunk is locked for writing. If true, master will be waiting for the lock
307317
/// to be released when the write operation finishes.
308318
bool isChunkLocked_ = false;

0 commit comments

Comments
 (0)