Skip to content

Commit

Permalink
Allow overriding num shards by env variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed May 6, 2022
1 parent 3d8a816 commit 1705d14
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions sources/file_table.cpp
Expand Up @@ -8,6 +8,7 @@

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <queue>
#include <string.h>
Expand Down Expand Up @@ -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<unsigned>(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);

Expand Down

0 comments on commit 1705d14

Please sign in to comment.