From 575726358c72772b7be00d0f8eaff76506118f7a Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 3 May 2021 17:27:43 +0200 Subject: [PATCH] Tune Sled configuration - Make sled cache size and flush interval configurable - Set less agressive default values: - cache size 128MB instead of 1GB - Flush interval 2 seconds instead of .5 seconds --- src/garage/server.rs | 7 ++++++- src/util/config.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/garage/server.rs b/src/garage/server.rs index 97a9bec21..3004d3d23 100644 --- a/src/garage/server.rs +++ b/src/garage/server.rs @@ -40,7 +40,12 @@ pub async fn run_server(config_file: PathBuf) -> Result<(), Error> { info!("Opening database..."); let mut db_path = config.metadata_dir.clone(); db_path.push("db"); - let db = sled::open(&db_path).expect("Unable to open sled DB"); + let db = sled::Config::default() + .path(&db_path) + .cache_capacity(config.sled_cache_capacity) + .flush_every_ms(Some(config.sled_flush_every_ms)) + .open() + .expect("Unable to open sled DB"); info!("Initialize RPC server..."); let mut rpc_server = RpcServer::new(config.rpc_bind_addr.clone(), config.rpc_tls.clone()); diff --git a/src/util/config.rs b/src/util/config.rs index bb70467be..093b38505 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -26,6 +26,14 @@ pub struct Config { /// Consul service name to use pub consul_service_name: Option, + /// Sled cache size, in bytes + #[serde(default = "default_sled_cache_capacity")] + pub sled_cache_capacity: u64, + + /// Sled flush interval in milliseconds + #[serde(default = "default_sled_flush_every_ms")] + pub sled_flush_every_ms: u64, + /// Max number of concurrent RPC request #[serde(default = "default_max_concurrent_rpc_requests")] pub max_concurrent_rpc_requests: usize, @@ -86,6 +94,12 @@ pub struct WebConfig { pub index: String, } +fn default_sled_cache_capacity() -> u64 { + 128 * 1024 * 1024 +} +fn default_sled_flush_every_ms() -> u64 { + 2000 +} fn default_max_concurrent_rpc_requests() -> usize { 12 }