From 9ead395bffc4052d0689f04d1ddb02e2cc42757e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <bkchr@users.noreply.github.com>
Date: Tue, 26 Nov 2019 13:25:43 +0100
Subject: [PATCH] Give `state_col` 90% of memory budget and fix other col
 calculation (#4208)

* Give `state_col` 90% of memory budget and fix other col calculation

* Set default db cache size to 1024
---
 substrate/client/cli/src/lib.rs    | 2 +-
 substrate/client/cli/src/params.rs | 4 ++--
 substrate/client/db/src/utils.rs   | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/substrate/client/cli/src/lib.rs b/substrate/client/cli/src/lib.rs
index 5d67f42c630..203ca049511 100644
--- a/substrate/client/cli/src/lib.rs
+++ b/substrate/client/cli/src/lib.rs
@@ -733,7 +733,7 @@ where
 
 	config.database = DatabaseConfig::Path {
 		path: config.in_chain_config_dir(DEFAULT_DB_CONFIG_PATH).expect("We provided a base_path."),
-		cache_size: cli.database_cache_size,
+		cache_size: Some(cli.database_cache_size),
 	};
 	config.state_cache_size = cli.state_cache_size;
 
diff --git a/substrate/client/cli/src/params.rs b/substrate/client/cli/src/params.rs
index 15ec2fa113c..1324d3419f8 100644
--- a/substrate/client/cli/src/params.rs
+++ b/substrate/client/cli/src/params.rs
@@ -385,8 +385,8 @@ pub struct RunCmd {
 	pub light: bool,
 
 	/// Limit the memory the database cache can use.
-	#[structopt(long = "db-cache", value_name = "MiB")]
-	pub database_cache_size: Option<u32>,
+	#[structopt(long = "db-cache", value_name = "MiB", default_value = "1024")]
+	pub database_cache_size: u32,
 
 	/// Specify the state cache size.
 	#[structopt(long = "state-cache-size", value_name = "Bytes", default_value = "67108864")]
diff --git a/substrate/client/db/src/utils.rs b/substrate/client/db/src/utils.rs
index 6b636c0c779..516f3d11b05 100644
--- a/substrate/client/db/src/utils.rs
+++ b/substrate/client/db/src/utils.rs
@@ -215,8 +215,8 @@ pub fn open_database(
 			let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS));
 
 			if let Some(cache_size) = cache_size {
-				let state_col_budget = (*cache_size as f64 * 0.7) as usize;
-				let other_col_budget = cache_size - state_col_budget;
+				let state_col_budget = (*cache_size as f64 * 0.9) as usize;
+				let other_col_budget = (cache_size - state_col_budget) / (NUM_COLUMNS as usize - 1);
 
 				let mut memory_budget = std::collections::HashMap::new();
 				for i in 0..NUM_COLUMNS {
-- 
GitLab