diff options
author | Dan Pasette <dan@mongodb.com> | 2016-04-09 16:59:36 -0400 |
---|---|---|
committer | Dan Pasette <dan@mongodb.com> | 2016-04-15 22:23:30 -0400 |
commit | 9406722720821f7152f44ddcfd12a6447ec58ae4 (patch) | |
tree | 2f02b77f919f58bbf291aa122e9ad54b56d57c0a /src | |
parent | 608cdcd96012b4759008b11cbee32b18927f85ba (diff) | |
download | mongo-9406722720821f7152f44ddcfd12a6447ec58ae4.tar.gz |
SERVER-23391 Lower WiredTiger cache size floor
Diffstat (limited to 'src')
4 files changed, 26 insertions, 17 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp index 5ccc1093549..783983aa93b 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp @@ -61,25 +61,12 @@ public: warning() << "Recovering data from the last clean checkpoint."; } - size_t cacheSizeGB = wiredTigerGlobalOptions.cacheSizeGB; - if (cacheSizeGB == 0) { - // Since the user didn't provide a cache size, choose a reasonable default value. - // We want to reserve 1GB for the system and binaries, but it's not bad to - // leave a fair amount left over for pagecache since that's compressed storage. - ProcessInfo pi; - double memSizeMB = pi.getMemSizeMB(); - if (memSizeMB > 0) { - double cacheMB = (memSizeMB - 1024) * 0.6; - cacheSizeGB = static_cast<size_t>(cacheMB / 1024); - if (cacheSizeGB < 1) - cacheSizeGB = 1; - } - } + size_t cacheMB = WiredTigerUtil::getCacheSizeMB(wiredTigerGlobalOptions.cacheSizeGB); const bool ephemeral = false; WiredTigerKVEngine* kv = new WiredTigerKVEngine(getCanonicalName().toString(), params.dbpath, wiredTigerGlobalOptions.engineConfig, - cacheSizeGB, + cacheMB, params.dur, ephemeral, params.repair, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 51749294c3d..d8547c421f9 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -171,7 +171,7 @@ TicketServerParameter openReadTransactionParam(&openReadTransaction, WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, const std::string& path, const std::string& extraOpenOptions, - size_t cacheSizeGB, + size_t cacheSizeMB, bool durable, bool ephemeral, bool repair, @@ -200,7 +200,7 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName, std::stringstream ss; ss << "create,"; - ss << "cache_size=" << cacheSizeGB << "G,"; + ss << "cache_size=" << cacheSizeMB << "M,"; ss << "session_max=20000,"; ss << "eviction=(threads_max=4),"; ss << "config_base=false,"; diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index ef81ff1acc3..c747087fbf8 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -45,6 +45,7 @@ #include "mongo/util/assert_util.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" +#include "mongo/util/processinfo.h" #include "mongo/util/scopeguard.h" namespace mongo { @@ -317,6 +318,20 @@ int64_t WiredTigerUtil::getIdentSize(WT_SESSION* s, const std::string& uri) { return result.getValue(); } +size_t WiredTigerUtil::getCacheSizeMB(int requestedCacheSizeGB) { + double cacheSizeMB; + if (requestedCacheSizeGB == 0) { + // Choose a reasonable amount of cache when not explicitly specified by user. + // Set a minimum of 256MB, otherwise use 60% of available memory over 1GB. + ProcessInfo pi; + double memSizeMB = pi.getMemSizeMB(); + cacheSizeMB = std::max((memSizeMB - 1024) * 0.6, 256.0); + } else { + cacheSizeMB = 1024 * requestedCacheSizeGB; + } + return static_cast<size_t>(cacheSizeMB); +} + namespace { int mdb_handle_error(WT_EVENT_HANDLER* handler, WT_SESSION* session, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h index af8b6ee1af2..6f12bd54531 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h @@ -175,6 +175,13 @@ public: static int64_t getIdentSize(WT_SESSION* s, const std::string& uri); + + /** + * Return amount of memory to use for the WiredTiger cache based on either the startup + * option chosen or the amount of available memory on the host. + */ + static size_t getCacheSizeMB(int requestedCacheSizeGB); + /** * Returns a WT_EVENT_HANDER with MongoDB's default handlers. * The default handlers just log so it is recommended that you consider calling them even if |