Skip to main content

rustfs_config/constants/
runtime.rs

1//  Copyright 2024 RustFS Team
2//
3//  Licensed under the Apache License, Version 2.0 (the "License");
4//  you may not use this file except in compliance with the License.
5//  You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14
15use crate::MI_B;
16
17// Tokio runtime ENV keys
18pub const ENV_WORKER_THREADS: &str = "RUSTFS_RUNTIME_WORKER_THREADS";
19pub const ENV_MAX_BLOCKING_THREADS: &str = "RUSTFS_RUNTIME_MAX_BLOCKING_THREADS";
20pub const ENV_THREAD_PRINT_ENABLED: &str = "RUSTFS_RUNTIME_THREAD_PRINT_ENABLED";
21pub const ENV_THREAD_STACK_SIZE: &str = "RUSTFS_RUNTIME_THREAD_STACK_SIZE";
22pub const ENV_THREAD_KEEP_ALIVE: &str = "RUSTFS_RUNTIME_THREAD_KEEP_ALIVE";
23pub const ENV_GLOBAL_QUEUE_INTERVAL: &str = "RUSTFS_RUNTIME_GLOBAL_QUEUE_INTERVAL";
24pub const ENV_THREAD_NAME: &str = "RUSTFS_RUNTIME_THREAD_NAME";
25pub const ENV_MAX_IO_EVENTS_PER_TICK: &str = "RUSTFS_RUNTIME_MAX_IO_EVENTS_PER_TICK";
26pub const ENV_RNG_SEED: &str = "RUSTFS_RUNTIME_RNG_SEED";
27/// Event polling interval
28pub const ENV_EVENT_INTERVAL: &str = "RUSTFS_RUNTIME_EVENT_INTERVAL";
29
30// Dial9 Tokio Telemetry Configuration
31pub const ENV_RUNTIME_DIAL9_ENABLED: &str = "RUSTFS_RUNTIME_DIAL9_ENABLED";
32pub const ENV_RUNTIME_DIAL9_OUTPUT_DIR: &str = "RUSTFS_RUNTIME_DIAL9_OUTPUT_DIR";
33pub const ENV_RUNTIME_DIAL9_FILE_PREFIX: &str = "RUSTFS_RUNTIME_DIAL9_FILE_PREFIX";
34pub const ENV_RUNTIME_DIAL9_MAX_FILE_SIZE: &str = "RUSTFS_RUNTIME_DIAL9_MAX_FILE_SIZE";
35pub const ENV_RUNTIME_DIAL9_ROTATION_COUNT: &str = "RUSTFS_RUNTIME_DIAL9_ROTATION_COUNT";
36/// Accepted but not honoured: dial9's S3 uploader depends on a vulnerable
37/// rustls-webpki. Setting this logs a warning. See rustfs/backlog#1157.
38pub const ENV_RUNTIME_DIAL9_S3_BUCKET: &str = "RUSTFS_RUNTIME_DIAL9_S3_BUCKET";
39/// Accepted but not honoured; see [`ENV_RUNTIME_DIAL9_S3_BUCKET`].
40pub const ENV_RUNTIME_DIAL9_S3_PREFIX: &str = "RUSTFS_RUNTIME_DIAL9_S3_PREFIX";
41// Note: there are deliberately no task-dump knobs. dial9 only captures task
42// dumps for futures spawned through `dial9::spawn`, and RustFS
43// spawns with `tokio::spawn` throughout, so the switch could never do anything.
44// Measured: 0 dumps via tokio::spawn vs 14709 via dial9::spawn on an identical
45// workload. See rustfs/backlog#1157 (D9-16).
46
47// Default values for Tokio runtime
48pub const DEFAULT_WORKER_THREADS: usize = 16;
49pub const DEFAULT_MAX_BLOCKING_THREADS: usize = 1024;
50pub const DEFAULT_THREAD_PRINT_ENABLED: bool = false;
51pub const DEFAULT_THREAD_STACK_SIZE: usize = MI_B; // 1 MiB
52pub const DEFAULT_THREAD_KEEP_ALIVE: u64 = 60; // seconds
53pub const DEFAULT_GLOBAL_QUEUE_INTERVAL: u32 = 31;
54pub const DEFAULT_THREAD_NAME: &str = "rustfs-worker";
55pub const DEFAULT_MAX_IO_EVENTS_PER_TICK: usize = 1024;
56/// Event polling default (Tokio default 61)
57pub const DEFAULT_EVENT_INTERVAL: u32 = 61;
58pub const DEFAULT_RNG_SEED: Option<u64> = None; // None means random
59
60/// Dedicated blocking thread pool for fsync/fdatasync operations.
61/// When > 1, fsync operations are isolated from the main blocking pool to
62/// prevent device-bound fsync from starving read operations (pread/stat/open).
63/// Default 64 isolates fsync from the main blocking pool to prevent device-bound fsync from starving read I/O.
64pub const ENV_FSYNC_BLOCKING_THREADS: &str = "RUSTFS_RUNTIME_FSYNC_BLOCKING_THREADS";
65pub const DEFAULT_FSYNC_BLOCKING_THREADS: usize = 64;
66
67// Dial9 Tokio Telemetry Default values
68pub const DEFAULT_RUNTIME_DIAL9_ENABLED: bool = false; // Disabled by default
69pub const DEFAULT_RUNTIME_DIAL9_OUTPUT_DIR: &str = "/var/log/rustfs/telemetry";
70pub const DEFAULT_RUNTIME_DIAL9_FILE_PREFIX: &str = "rustfs-tokio";
71pub const DEFAULT_RUNTIME_DIAL9_MAX_FILE_SIZE: u64 = 100 * 1024 * 1024; // 100MB
72pub const DEFAULT_RUNTIME_DIAL9_ROTATION_COUNT: usize = 10;
73// Note: S3 bucket/prefix have no default; absence means upload is disabled (modeled as Option<String>)
74
75/// Maximum transition workers used as a local fallback when runtime env is unset.
76pub const DEFAULT_TRANSITION_WORKERS_CAP: i64 = 16;
77/// Absolute upper bound for transition workers accepted from runtime env.
78pub const DEFAULT_TRANSITION_WORKERS_ABSOLUTE_MAX: i64 = 32;
79/// Default capacity for the transition queue.
80pub const DEFAULT_TRANSITION_QUEUE_CAPACITY: usize = 1000;
81/// Default send timeout for transition queue enqueue attempts, in milliseconds.
82pub const DEFAULT_TRANSITION_QUEUE_SEND_TIMEOUT_MS: usize = 100;
83/// Test-only fault injection env var that forces the immediate transition enqueue timeout path.
84pub const ENV_TEST_FORCE_IMMEDIATE_TRANSITION_ENQUEUE_TIMEOUT: &str = "RUSTFS_TEST_FORCE_IMMEDIATE_TRANSITION_ENQUEUE_TIMEOUT";
85/// Test-only fault injection env var that forces a number of IAM bootstrap failures.
86pub const ENV_TEST_IAM_FAIL_INIT_ATTEMPTS: &str = "RUSTFS_TEST_IAM_FAIL_INIT_ATTEMPTS";
87/// Test-only env var that overrides the deferred IAM retry interval in debug builds.
88pub const ENV_TEST_IAM_RETRY_INTERVAL_MS: &str = "RUSTFS_TEST_IAM_RETRY_INTERVAL_MS";
89/// Runtime env var controlling the transition worker count.
90pub const ENV_TRANSITION_WORKERS: &str = "RUSTFS_MAX_TRANSITION_WORKERS";
91/// Runtime env var controlling the ILM expiry worker count. A set, parsable,
92/// non-zero value wins; anything else falls back to `min(cpus, 16)`.
93pub const ENV_MAX_EXPIRY_WORKERS: &str = "RUSTFS_MAX_EXPIRY_WORKERS";
94/// Runtime env var controlling the absolute maximum transition workers.
95pub const ENV_TRANSITION_WORKERS_ABSOLUTE_MAX: &str = "RUSTFS_ABSOLUTE_MAX_WORKERS";
96/// Runtime env var controlling the transition queue capacity.
97pub const ENV_TRANSITION_QUEUE_CAPACITY: &str = "RUSTFS_TRANSITION_QUEUE_CAPACITY";
98/// Runtime env var controlling the transition queue send timeout in milliseconds.
99pub const ENV_TRANSITION_QUEUE_SEND_TIMEOUT_MS: &str = "RUSTFS_TRANSITION_QUEUE_SEND_TIMEOUT_MS";
100
101// Allocator reclaim configuration
102pub const ENV_ALLOCATOR_RECLAIM_ENABLED: &str = "RUSTFS_ALLOCATOR_RECLAIM_ENABLED";
103pub const ENV_ALLOCATOR_RECLAIM_INTERVAL_SECS: &str = "RUSTFS_ALLOCATOR_RECLAIM_INTERVAL_SECS";
104pub const ENV_ALLOCATOR_RECLAIM_FORCE: &str = "RUSTFS_ALLOCATOR_RECLAIM_FORCE";
105pub const ENV_ALLOCATOR_RECLAIM_IDLE_INTERVALS: &str = "RUSTFS_ALLOCATOR_RECLAIM_IDLE_INTERVALS";
106pub const DEFAULT_ALLOCATOR_RECLAIM_ENABLED: bool = true;
107pub const DEFAULT_ALLOCATOR_RECLAIM_INTERVAL_SECS: u64 = 30;
108pub const DEFAULT_ALLOCATOR_RECLAIM_FORCE: bool = true;
109pub const DEFAULT_ALLOCATOR_RECLAIM_IDLE_INTERVALS: u64 = 3;
110
111// File page-cache reclaim configuration
112pub const ENV_OBJECT_FILE_CACHE_RECLAIM_WRITE_ENABLE: &str = "RUSTFS_OBJECT_FILE_CACHE_RECLAIM_WRITE_ENABLE";
113pub const ENV_OBJECT_FILE_CACHE_RECLAIM_READ_ENABLE: &str = "RUSTFS_OBJECT_FILE_CACHE_RECLAIM_READ_ENABLE";
114pub const ENV_OBJECT_FILE_CACHE_RECLAIM_THRESHOLD: &str = "RUSTFS_OBJECT_FILE_CACHE_RECLAIM_THRESHOLD";
115pub const DEFAULT_OBJECT_FILE_CACHE_RECLAIM_WRITE_ENABLE: bool = false;
116pub const DEFAULT_OBJECT_FILE_CACHE_RECLAIM_READ_ENABLE: bool = true;
117pub const DEFAULT_OBJECT_FILE_CACHE_RECLAIM_THRESHOLD: usize = 4 * 1024 * 1024;
118
119/// Threshold for small object seek support in bytes.
120///
121/// When an object response is smaller than this size, rustfs may provide
122/// in-memory seek support. Runtime GET logic also enforces a hard safety cap
123/// (`64 MiB`) to prevent large-download memory spikes even if this threshold
124/// is configured higher.
125///
126/// Default is set to 10 MiB.
127pub const ENV_OBJECT_SEEK_SUPPORT_THRESHOLD: &str = "RUSTFS_OBJECT_SEEK_SUPPORT_THRESHOLD";
128pub const DEFAULT_OBJECT_SEEK_SUPPORT_THRESHOLD: usize = 10 * 1024 * 1024;
129
130// Object data cache configuration
131
132/// Enables the in-memory object body cache, which serves whole-object GET
133/// responses without an erasure read.
134///
135/// # Timing side channel
136///
137/// A cache hit skips the erasure read, bitrot verification and decode, so it is
138/// reliably faster than a miss. Any principal authorized to read an object can
139/// therefore infer, by timing a single GET, whether *someone* read that object
140/// within the entry's lifetime (see `RUSTFS_OBJECT_DATA_CACHE_TTL_SECS` and
141/// `..._TIME_TO_IDLE_SECS`).
142///
143/// This never crosses an authorization boundary — the probe requires read
144/// access to the exact bucket and object, checked before the cache is consulted
145/// — but it does disclose co-tenants' recent access patterns on objects the
146/// observer may already read. Leave the cache disabled where access-pattern
147/// confidentiality matters, such as a bucket shared read-only between competing
148/// tenants. Timing noise is not a viable mitigation: it would cost exactly the
149/// latency the cache exists to save.
150pub const ENV_OBJECT_DATA_CACHE_ENABLE: &str = "RUSTFS_OBJECT_DATA_CACHE_ENABLE";
151pub const ENV_OBJECT_DATA_CACHE_MODE: &str = "RUSTFS_OBJECT_DATA_CACHE_MODE";
152pub const ENV_OBJECT_DATA_CACHE_MAX_BYTES: &str = "RUSTFS_OBJECT_DATA_CACHE_MAX_BYTES";
153pub const ENV_OBJECT_DATA_CACHE_MAX_MEMORY_PERCENT: &str = "RUSTFS_OBJECT_DATA_CACHE_MAX_MEMORY_PERCENT";
154pub const ENV_OBJECT_DATA_CACHE_MAX_ENTRY_BYTES: &str = "RUSTFS_OBJECT_DATA_CACHE_MAX_ENTRY_BYTES";
155pub const ENV_OBJECT_DATA_CACHE_TTL_SECS: &str = "RUSTFS_OBJECT_DATA_CACHE_TTL_SECS";
156pub const ENV_OBJECT_DATA_CACHE_TIME_TO_IDLE_SECS: &str = "RUSTFS_OBJECT_DATA_CACHE_TIME_TO_IDLE_SECS";
157pub const ENV_OBJECT_DATA_CACHE_MIN_FREE_MEMORY_PERCENT: &str = "RUSTFS_OBJECT_DATA_CACHE_MIN_FREE_MEMORY_PERCENT";
158pub const ENV_OBJECT_DATA_CACHE_FILL_CONCURRENCY_PER_CPU: &str = "RUSTFS_OBJECT_DATA_CACHE_FILL_CONCURRENCY_PER_CPU";
159pub const ENV_OBJECT_DATA_CACHE_FILL_CONCURRENCY_MAX: &str = "RUSTFS_OBJECT_DATA_CACHE_FILL_CONCURRENCY_MAX";
160pub const ENV_OBJECT_DATA_CACHE_IDENTITY_KEYS_MAX: &str = "RUSTFS_OBJECT_DATA_CACHE_IDENTITY_KEYS_MAX";