diff options
author | Louis Williams <louis.williams@mongodb.com> | 2018-02-14 17:11:57 -0500 |
---|---|---|
committer | Louis Williams <louis.williams@mongodb.com> | 2018-02-26 10:27:50 -0500 |
commit | 0ef1e13db4f3d217ddc6de7ffc46842a4fc9889a (patch) | |
tree | bbd42d12014ee743bd8388ee3e0052ba27800617 | |
parent | 35212ca1250977a64f190a8de3572a35a88343c6 (diff) | |
download | mongo-0ef1e13db4f3d217ddc6de7ffc46842a4fc9889a.tar.gz |
SERVER-33122 Add option to disable WiredTiger cursor caching
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp | 46 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h | 2 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp index 31889025b92..79b4ad90630 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp @@ -38,6 +38,7 @@ #include "mongo/base/error_codes.h" #include "mongo/db/global_settings.h" #include "mongo/db/repl/repl_settings.h" +#include "mongo/db/server_parameters.h" #include "mongo/db/storage/journal_listener.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" @@ -48,13 +49,32 @@ namespace mongo { +AtomicInt32 kWiredTigerCursorCacheSize(10000); + +class WiredTigerCursorCacheSize + : public ExportedServerParameter<std::int32_t, ServerParameterType::kStartupAndRuntime> { +public: + WiredTigerCursorCacheSize() + : ExportedServerParameter<std::int32_t, ServerParameterType::kStartupAndRuntime>( + ServerParameterSet::getGlobal(), + "wiredTigerCursorCacheSize", + &kWiredTigerCursorCacheSize) {} + + virtual Status validate(const std::int32_t& potentialNewValue) { + if (potentialNewValue < 0) { + return Status(ErrorCodes::BadValue, + str::stream() + << "wiredTigerCursorCacheSize must be greater than or equal " + << "to 0, but attempted to set to: " + << potentialNewValue); + } + + return Status::OK(); + } +} WiredTigerCursorCacheSizeSetting; + WiredTigerSession::WiredTigerSession(WT_CONNECTION* conn, uint64_t epoch, uint64_t cursorEpoch) - : _epoch(epoch), - _cursorEpoch(cursorEpoch), - _session(NULL), - _cursorGen(0), - _cursorsCached(0), - _cursorsOut(0) { + : _epoch(epoch), _cursorEpoch(cursorEpoch), _session(NULL), _cursorGen(0), _cursorsOut(0) { invariantWTOK(conn->open_session(conn, NULL, "isolation=snapshot", &_session)); } @@ -67,7 +87,6 @@ WiredTigerSession::WiredTigerSession(WT_CONNECTION* conn, _cache(cache), _session(NULL), _cursorGen(0), - _cursorsCached(0), _cursorsOut(0) { invariantWTOK(conn->open_session(conn, NULL, "isolation=snapshot", &_session)); } @@ -85,7 +104,6 @@ WT_CURSOR* WiredTigerSession::getCursor(const std::string& uri, uint64_t id, boo WT_CURSOR* c = i->_cursor; _cursors.erase(i); _cursorsOut++; - _cursorsCached--; return c; } } @@ -109,17 +127,11 @@ void WiredTigerSession::releaseCursor(uint64_t id, WT_CURSOR* cursor) { // Cursors are pushed to the front of the list and removed from the back _cursors.push_front(WiredTigerCachedCursor(id, _cursorGen++, cursor)); - _cursorsCached++; - - // "Old" is defined as not used in the last N**2 operations, if we have N cursors cached. - // The reasoning here is to imagine a workload with N tables performing operations randomly - // across all of them (i.e., each cursor has 1/N chance of used for each operation). We - // would like to cache N cursors in that case, so any given cursor could go N**2 operations - // in between use. - while (_cursorGen - _cursors.back()._gen > 10000) { + + std::uint64_t cursorCacheSize = static_cast<std::uint64_t>(kWiredTigerCursorCacheSize.load()); + while (!_cursors.empty() && _cursorGen - _cursors.back()._gen > cursorCacheSize) { cursor = _cursors.back()._cursor; _cursors.pop_back(); - _cursorsCached--; invariantWTOK(cursor->close(cursor)); } } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h index 12c61fb0db3..4df2d7e5db7 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h @@ -137,7 +137,7 @@ private: WT_SESSION* _session; // owned CursorCache _cursors; // owned uint64_t _cursorGen; - int _cursorsCached, _cursorsOut; + int _cursorsOut; }; /** |