fix(logging): shrink the log writer queue from 128000 to 16384 lines (#7211)

tracing-appender's default non-blocking queue holds 128 000 lines and is allocated up front (about 4 MB) for a backlog the writer thread never builds. The log writer uses a 16 384-line queue.

Co-authored-by: Pecnikas <[email protected]>
Цей коміт міститься в:
Ivan authored and GitHub committed 2026-12-01 19:22:17 +08:00
1 джерело 4276250056
коміт 281c2ff1e5
1 file changed
+7 -1
+7 -1
Переглянути файл
@@ -15,6 +15,8 @@ use tracing_subscriber::{EnvFilter, Layer};
const PREFIX: &str = "openidea";
const SUFFIX: &str = "log";
/// Lines waiting for the log writer thread before new ones are dropped.
const LOG_QUEUE_LINES: usize = 16_384;
static LOG_DIR: OnceLock<PathBuf> = OnceLock::new();
static GUARD: OnceLock<WorkerGuard> = OnceLock::new();
@@ -38,7 +40,11 @@ pub fn init(identifier: &str) {
.max_log_files(7)
.build(&dir)
.ok()?;
let (writer, guard) = tracing_appender::non_blocking(appender);
// The default queue holds 128 000 lines and is filled when it is created: 4 MB of memory for a
// backlog the writer thread never builds.
let (writer, guard) = tracing_appender::non_blocking::NonBlockingBuilder::default()
.buffered_lines_limit(LOG_QUEUE_LINES)
.finish(appender);
let _ = GUARD.set(guard);
log_panics(dir.clone());
let _ = LOG_DIR.set(dir);