@@ -14,10 +14,26 @@ pub const DEFAULT_MAX_SYNC_BACKOFF: u32 = 2;
1414#[ cfg( not( test) ) ]
1515pub const DEFAULT_MAX_SYNC_BACKOFF : u32 = 15 ;
1616
17- const fn default_apply_queue ( ) -> usize {
17+ const fn default_apply_batch_min ( ) -> usize {
1818 100
1919}
2020
21+ const fn default_apply_batch_step ( ) -> usize {
22+ 500
23+ }
24+
25+ const fn default_apply_batch_max ( ) -> usize {
26+ 16_000
27+ }
28+
29+ const fn default_batch_threshold_ratio ( ) -> f64 {
30+ 0.9
31+ }
32+
33+ const fn default_cache_size_kib ( ) -> i64 {
34+ -1048576 // 1 GB (negative value means KiB)
35+ }
36+
2137const fn default_reaper_interval ( ) -> usize {
2238 3600
2339}
@@ -129,6 +145,11 @@ pub struct DbConfig {
129145 pub schema_paths : Vec < Utf8PathBuf > ,
130146 #[ serde( default ) ]
131147 pub subscriptions_path : Option < Utf8PathBuf > ,
148+ /// SQLite page cache size in KiB for writes (negative value).
149+ /// Default: -1048576 (1 GB). Larger values improve write performance but use more RAM.
150+ /// WARNING: Setting this too low (<100MB) can severely degrade performance.
151+ #[ serde( default = "default_cache_size_kib" ) ]
152+ pub cache_size_kib : i64 ,
132153}
133154
134155impl DbConfig {
@@ -227,20 +248,34 @@ pub struct PerfConfig {
227248 pub bcast_channel_len : usize ,
228249 #[ serde( default = "default_small_channel" ) ]
229250 pub foca_channel_len : usize ,
230- #[ serde( default = "default_apply_timeout" ) ]
231- pub apply_queue_timeout : usize ,
232- #[ serde( default = "default_apply_queue" ) ]
233- pub apply_queue_len : usize ,
234251 #[ serde( default = "default_wal_threshold" ) ]
235252 pub wal_threshold_mb : usize ,
236- #[ serde( default = "default_processing_queue" ) ]
237- pub processing_queue_len : usize ,
238253 #[ serde( default = "default_sql_tx_timeout" ) ]
239254 pub sql_tx_timeout : usize ,
240255 #[ serde( default = "default_min_sync_backoff" ) ]
241256 pub min_sync_backoff : u32 ,
242257 #[ serde( default = "default_max_sync_backoff" ) ]
243258 pub max_sync_backoff : u32 ,
259+ // How many unapplied changesets corrosion will buffer before starting to drop them
260+ #[ serde( default = "default_processing_queue" ) ]
261+ pub processing_queue_len : usize ,
262+ // How many ms corrosion will wait before proceeding to apply a batch of changes
263+ // We wait either for apply_queue_timeout or untill at least apply_queue_min_batch_size changes accumulate
264+ #[ serde( default = "default_apply_timeout" ) ]
265+ pub apply_queue_timeout : usize ,
266+ // Minimum amount of changes corrosion will try to apply at once in the same transaction
267+ #[ serde( default = "default_apply_batch_min" ) ]
268+ pub apply_queue_min_batch_size : usize ,
269+ // batch_size = clamp(min_batch_size, step_base * 2 ** floor(log2(x/step_base)), max_batch_size)
270+ #[ serde( default = "default_apply_batch_step" ) ]
271+ pub apply_queue_step_base : usize ,
272+ // Maximum amount of changes corrosion will try to apply at once in the same transaction
273+ #[ serde( default = "default_apply_batch_max" ) ]
274+ pub apply_queue_max_batch_size : usize ,
275+ // Threshold ratio (0.0-1.0) for immediate batch spawning when queue reaches this fraction of batch size
276+ // It's used to decide whether to wait for more changes for apply_queue_timeout ms or spawn a batch immediately
277+ #[ serde( default = "default_batch_threshold_ratio" ) ]
278+ pub apply_queue_batch_threshold_ratio : f64 ,
244279}
245280
246281impl Default for PerfConfig {
@@ -255,13 +290,16 @@ impl Default for PerfConfig {
255290 clearbuf_channel_len : default_mid_channel ( ) ,
256291 bcast_channel_len : default_mid_channel ( ) ,
257292 foca_channel_len : default_small_channel ( ) ,
258- apply_queue_timeout : default_apply_timeout ( ) ,
259- apply_queue_len : default_apply_queue ( ) ,
260293 wal_threshold_mb : default_wal_threshold ( ) ,
261- processing_queue_len : default_processing_queue ( ) ,
262294 sql_tx_timeout : default_sql_tx_timeout ( ) ,
263295 min_sync_backoff : default_min_sync_backoff ( ) ,
264296 max_sync_backoff : default_max_sync_backoff ( ) ,
297+ processing_queue_len : default_processing_queue ( ) ,
298+ apply_queue_timeout : default_apply_timeout ( ) ,
299+ apply_queue_min_batch_size : default_apply_batch_min ( ) ,
300+ apply_queue_step_base : default_apply_batch_step ( ) ,
301+ apply_queue_max_batch_size : default_apply_batch_max ( ) ,
302+ apply_queue_batch_threshold_ratio : default_batch_threshold_ratio ( ) ,
265303 }
266304 }
267305}
@@ -446,6 +484,7 @@ impl ConfigBuilder {
446484 path : db_path,
447485 schema_paths : self . schema_paths ,
448486 subscriptions_path : None ,
487+ cache_size_kib : default_cache_size_kib ( ) ,
449488 } ,
450489 api : ApiConfig {
451490 bind_addr : self . api_addr ,
0 commit comments