Skip to content

Commit 27f9a8b

Browse files
committed
Rename channels CLI option and use the common buffer size option for both threaded and non-threaded variants
1 parent d03a638 commit 27f9a8b

3 files changed

Lines changed: 19 additions & 31 deletions

File tree

crates/cli-flags/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,10 @@ wasmtime_option_group! {
511511
/// Enable threaded (async) recording writer. Decouples serialization from file I/O
512512
/// by shipping buffers to a background thread.
513513
pub threaded: Option<bool>,
514-
/// Buffer capacity (in bytes) for the threaded writer before shipping to the
515-
/// background thread. Defaults to 64 KiB. Only used when `threaded` is enabled.
516-
pub threaded_buffer_capacity: Option<usize>,
517-
/// Channel bound for the threaded writer (max number of buffers queued).
518-
/// Defaults to 8. Only used when `threaded` is enabled.
519-
pub threaded_channel_bound: Option<usize>,
514+
/// Maximum number of buffers queued for the background writer thread.
515+
/// Higher values tolerate more disk latency at the cost of memory. Defaults to 8.
516+
/// Only used when `threaded` is enabled.
517+
pub channels: Option<usize>,
520518
}
521519

522520
enum Record {

crates/wasmtime/src/runtime/rr/threaded_writer.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,11 @@ impl SharedError {
6767
/// Configuration for [`ThreadedWriter`].
6868
pub struct ThreadedWriterConfig {
6969
/// Size (in bytes) of each local buffer before it is shipped to the
70-
/// background thread. Defaults to 64 KiB.
70+
/// background thread.
7171
pub buffer_capacity: usize,
7272
/// Maximum number of buffers that can be queued in the channel before the
7373
/// foreground blocks. Defaults to 8.
74-
pub channel_bound: usize,
75-
}
76-
77-
impl Default for ThreadedWriterConfig {
78-
fn default() -> Self {
79-
Self {
80-
buffer_capacity: 64 * 1024,
81-
channel_bound: 8,
82-
}
83-
}
74+
pub channels: usize,
8475
}
8576

8677
/// A writer that buffers serialized bytes in memory and ships them to a
@@ -117,7 +108,7 @@ impl ThreadedWriter {
117108
/// Spawns a background thread named `"rr-record-writer"` that receives
118109
/// buffers over a bounded channel and writes them to `writer`.
119110
pub fn new(writer: Box<dyn RecordWriter>, config: ThreadedWriterConfig) -> Self {
120-
let (tx, rx) = mpsc::sync_channel::<WriterMsg>(config.channel_bound);
111+
let (tx, rx) = mpsc::sync_channel::<WriterMsg>(config.channels);
121112
let (recycle_tx, recycle_rx) = mpsc::channel::<Vec<u8>>();
122113
let shared_error = SharedError::new();
123114
let bg_error = Arc::clone(&shared_error);
@@ -265,7 +256,7 @@ mod tests {
265256
let writer = SharedVecWriter(Arc::clone(&shared));
266257
let config = ThreadedWriterConfig {
267258
buffer_capacity: 32,
268-
channel_bound: 4,
259+
channels: 4,
269260
};
270261
let mut tw = ThreadedWriter::new(Box::new(writer), config);
271262

@@ -283,11 +274,11 @@ mod tests {
283274
let writer = SharedVecWriter(Arc::clone(&shared));
284275
let config = ThreadedWriterConfig {
285276
buffer_capacity: 64,
286-
channel_bound: 2,
277+
channels: 2,
287278
};
288279
let mut tw = ThreadedWriter::new(Box::new(writer), config);
289280

290-
// Write more data than buffer_capacity * channel_bound
281+
// Write more data than buffer_capacity * channels
291282
let data: Vec<u8> = (0..1024).map(|i| (i % 256) as u8).collect();
292283
tw.write_all(&data).unwrap();
293284
tw.flush().unwrap();
@@ -319,7 +310,7 @@ mod tests {
319310
let writer = FailingWriter { remaining: 16 };
320311
let config = ThreadedWriterConfig {
321312
buffer_capacity: 32,
322-
channel_bound: 2,
313+
channels: 2,
323314
};
324315
let mut tw = ThreadedWriter::new(Box::new(writer), config);
325316

@@ -341,7 +332,10 @@ mod tests {
341332
fn empty_write() {
342333
let shared = Arc::new(Mutex::new(Vec::new()));
343334
let writer = SharedVecWriter(Arc::clone(&shared));
344-
let config = ThreadedWriterConfig::default();
335+
let config = ThreadedWriterConfig {
336+
buffer_capacity: 64,
337+
channels: 4,
338+
};
345339
let mut tw = ThreadedWriter::new(Box::new(writer), config);
346340

347341
tw.flush().unwrap();

src/commands/run.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,12 @@ pub mod rr_impl {
139139
if path.trim().is_empty() {
140140
store.record(io::sink(), settings)?;
141141
} else {
142-
let file = io::BufWriter::with_capacity(
143-
record.buffer_size.unwrap_or(8 * 1024), // Default to 8 KiB buffer
144-
fs::File::create(&path)?,
145-
);
142+
let buffer_capacity = record.buffer_size.unwrap_or(8 * 1024); // Default to 8 KiB buffer
143+
let file = io::BufWriter::with_capacity(buffer_capacity, fs::File::create(&path)?);
146144
if record.threaded.unwrap_or(false) {
147145
let config = ThreadedWriterConfig {
148-
buffer_capacity: record
149-
.threaded_buffer_capacity
150-
.unwrap_or(64 * 1024),
151-
channel_bound: record.threaded_channel_bound.unwrap_or(8),
146+
buffer_capacity,
147+
channels: record.channels.unwrap_or(8),
152148
};
153149
let writer = ThreadedWriter::new(Box::new(file), config);
154150
store.record(writer, settings)?;

0 commit comments

Comments
 (0)