From 1705d14b8fef5ebb826a74549d609c6ab6cb63f7 Mon Sep 17 00:00:00 2001 From: Siyuan Ren Date: Fri, 6 May 2022 22:56:32 +0800 Subject: [PATCH] Allow overriding num shards by env variable. --- sources/file_table.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sources/file_table.cpp b/sources/file_table.cpp index 893d9504..d095a740 100644 --- a/sources/file_table.cpp +++ b/sources/file_table.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -320,15 +321,11 @@ ShardedFileTableImpl::ShardedFileTableImpl(int version, unsigned iv_size, unsigned max_padding_size) { - unsigned num_shards = 8; - auto cpu_count = std::thread::hardware_concurrency(); - if (cpu_count <= 2) + unsigned num_shards = 4; + const char* env_shards = std::getenv("SECUREFS_NUM_FILE_TABLE_SHARDS"); + if (env_shards) { - num_shards = 2; - } - else - { - num_shards = std::min(64u, 1u << static_cast(std::ceil(std::log2(cpu_count)))); + num_shards = std::max(2ul, std::strtoul(env_shards, nullptr, 0)); } TRACE_LOG("Use %u shards of FileTableImpls.", num_shards);