Skip to content

Commit ccd96b5

Browse files
committed
Perform self-profile compression in a separate thread
1 parent e0cae3e commit ccd96b5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

collector/src/bin/collector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,9 @@ fn build_async_runtime() -> Runtime {
18161816
// We want to minimize noise from the runtime
18171817
builder
18181818
.worker_threads(1)
1819-
.max_blocking_threads(1)
1819+
.max_blocking_threads(8)
1820+
// Do not keep blocking threads alive for long
1821+
.thread_keep_alive(Duration::from_secs(1))
18201822
.enable_time()
18211823
.enable_io();
18221824
builder.build().expect("built runtime")

collector/src/self_profile.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,19 @@ impl SelfProfileStorage for S3SelfProfileStorage {
202202
data.len()
203203
);
204204
let start = Instant::now();
205-
let mut data = snap::read::FrameEncoder::new(&data[..]);
206-
let mut compressed = Vec::new();
207-
data.read_to_end(&mut compressed)
208-
.context("cannot compress self-profile data")?;
205+
206+
// This is synchronous and blocks the event loop, so we should do it on a
207+
// worker thread
208+
let compressed = tokio::task::spawn_blocking(move || {
209+
let mut data = snap::read::FrameEncoder::new(&data[..]);
210+
let mut compressed = Vec::new();
211+
212+
data.read_to_end(&mut compressed)
213+
.context("cannot compress self-profile data")?;
214+
anyhow::Ok(compressed)
215+
})
216+
.await??;
217+
209218
log::trace!(
210219
"Compress self-profile duration: {}, size: {}",
211220
start.elapsed().as_secs_f64(),

0 commit comments

Comments
 (0)