Skip to content

Commit f52c13a

Browse files
committed
Expose config of write buffer size
1 parent 88664fd commit f52c13a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

crates/commitlog/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ pub struct Options {
8989
/// Has no effect if the `fallocate` feature is not enabled.
9090
#[cfg_attr(feature = "serde", serde(default = "Options::default_preallocate_segments"))]
9191
pub preallocate_segments: bool,
92+
/// Size in bytes of the memory buffer holding commit data before flushing
93+
/// to storage.
94+
///
95+
/// Default: 4KiB
96+
#[cfg_attr(feature = "serde", serde(default = "Options::default_write_buffer_size"))]
97+
pub write_buffer_size: usize,
9298
}
9399

94100
impl Default for Options {
@@ -102,13 +108,15 @@ impl Options {
102108
pub const DEFAULT_OFFSET_INDEX_INTERVAL_BYTES: NonZeroU64 = NonZeroU64::new(4096).expect("4096 > 0, qed");
103109
pub const DEFAULT_OFFSET_INDEX_REQUIRE_SEGMENT_FSYNC: bool = false;
104110
pub const DEFAULT_PREALLOCATE_SEGMENTS: bool = false;
111+
pub const DEFAULT_WRITE_BUFFER_SIZE: usize = 4 * 1024;
105112

106113
pub const DEFAULT: Self = Self {
107114
log_format_version: DEFAULT_LOG_FORMAT_VERSION,
108115
max_segment_size: Self::default_max_segment_size(),
109116
offset_index_interval_bytes: Self::default_offset_index_interval_bytes(),
110117
offset_index_require_segment_fsync: Self::default_offset_index_require_segment_fsync(),
111118
preallocate_segments: Self::default_preallocate_segments(),
119+
write_buffer_size: Self::default_write_buffer_size(),
112120
};
113121

114122
pub const fn default_log_format_version() -> u8 {
@@ -131,6 +139,10 @@ impl Options {
131139
Self::DEFAULT_PREALLOCATE_SEGMENTS
132140
}
133141

142+
pub const fn default_write_buffer_size() -> usize {
143+
Self::DEFAULT_WRITE_BUFFER_SIZE
144+
}
145+
134146
/// Compute the length in bytes of an offset index based on the settings in
135147
/// `self`.
136148
pub fn offset_index_len(&self) -> u64 {

crates/commitlog/src/repo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn create_segment_writer<R: Repo>(
214214
records: Vec::new(),
215215
epoch,
216216
},
217-
inner: io::BufWriter::new(storage),
217+
inner: io::BufWriter::with_capacity(opts.write_buffer_size, storage),
218218

219219
min_tx_offset: offset,
220220
bytes_written: Header::LEN as u64,

0 commit comments

Comments
 (0)