diff options
author | David Storch <david.storch@10gen.com> | 2014-11-17 22:16:15 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2014-11-17 22:16:15 -0500 |
commit | b32c91b8cb3a6bd214f31a962a6ef4556225bfc4 (patch) | |
tree | f2e120d92b1b1f03320cbc3219705ed33d3fc8b5 | |
parent | d0cd11123e114ea8cea33e37d06d1cf43c41727b (diff) | |
download | mongo-b32c91b8cb3a6bd214f31a962a6ef4556225bfc4.tar.gz |
SERVER-16159 MMAP v1 does timing-based yields for inserts
-rw-r--r-- | src/mongo/db/commands/write_commands/batch_executor.cpp | 17 | ||||
-rw-r--r-- | src/mongo/db/query/plan_yield_policy.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/query/query_knobs.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/query/query_knobs.h | 8 | ||||
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 4 |
5 files changed, 32 insertions, 6 deletions
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp index 0d11cf33bb7..ca479ffab33 100644 --- a/src/mongo/db/commands/write_commands/batch_executor.cpp +++ b/src/mongo/db/commands/write_commands/batch_executor.cpp @@ -38,6 +38,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" +#include "mongo/db/global_environment_experiment.h" #include "mongo/db/instance.h" #include "mongo/db/introspect.h" #include "mongo/db/lasterror.h" @@ -50,6 +51,7 @@ #include "mongo/db/ops/insert.h" #include "mongo/db/ops/update_executor.h" #include "mongo/db/ops/update_lifecycle_impl.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/repl_coordinator_global.h" #include "mongo/db/repl/repl_settings.h" @@ -843,14 +845,25 @@ namespace mongo { ExecInsertsState state(_txn, &request); normalizeInserts(request, &state.normalizedInserts); - ElapsedTracker elapsedTracker(128, 10); // 128 hits or 10 ms, matching RunnerYieldPolicy's + // Yield frequency is based on the same constants used by PlanYieldPolicy. + ElapsedTracker elapsedTracker(internalQueryExecYieldIterations, + internalQueryExecYieldPeriodMS); for (state.currIndex = 0; state.currIndex < state.request->sizeWriteOps(); ++state.currIndex) { if (elapsedTracker.intervalHasElapsed()) { - // Consider yielding between inserts. + // Consider yielding between inserts. We never yield for storage engines that + // support document-level locking. TODO: as an optimization, this should only + // yield if another thread is waiting for our lock. + if (!supportsDocLocking() && state.hasLock()) { + // Release our locks. They get reacquired when insertOne() calls + // ExecInsertsState::lockAndCheck(). Since the lock manager guarantees FIFO + // queues waiting on locks, there is no need to explicitly sleep or give up + // control of the processor here. + state.unlock(); + } _txn->checkForInterrupt(); elapsedTracker.resetLastTime(); diff --git a/src/mongo/db/query/plan_yield_policy.cpp b/src/mongo/db/query/plan_yield_policy.cpp index a5aa97ed6ea..63abf57105a 100644 --- a/src/mongo/db/query/plan_yield_policy.cpp +++ b/src/mongo/db/query/plan_yield_policy.cpp @@ -31,15 +31,14 @@ #include "mongo/db/query/plan_yield_policy.h" #include "mongo/db/global_environment_experiment.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_yield.h" #include "mongo/db/storage/record_fetcher.h" namespace mongo { - // Yield every 128 cycles or 10ms. These values were inherited from v2.6, which just copied - // them from v2.4. PlanYieldPolicy::PlanYieldPolicy(PlanExecutor* exec) - : _elapsedTracker(128, 10), + : _elapsedTracker(internalQueryExecYieldIterations, internalQueryExecYieldPeriodMS), _planYielding(exec) { } bool PlanYieldPolicy::shouldYield() { diff --git a/src/mongo/db/query/query_knobs.cpp b/src/mongo/db/query/query_knobs.cpp index 054c9fc2d44..b269e87f314 100644 --- a/src/mongo/db/query/query_knobs.cpp +++ b/src/mongo/db/query/query_knobs.cpp @@ -64,4 +64,8 @@ namespace mongo { MONGO_EXPORT_SERVER_PARAMETER(internalQueryExecMaxBlockingSortBytes, int, 32 * 1024 * 1024); + // Yield every 128 cycles or 10ms. + MONGO_EXPORT_SERVER_PARAMETER(internalQueryExecYieldIterations, int, 128); + MONGO_EXPORT_SERVER_PARAMETER(internalQueryExecYieldPeriodMS, int, 10); + } // namespace mongo diff --git a/src/mongo/db/query/query_knobs.h b/src/mongo/db/query/query_knobs.h index 453a5e372c7..b2363fb326b 100644 --- a/src/mongo/db/query/query_knobs.h +++ b/src/mongo/db/query/query_knobs.h @@ -98,4 +98,12 @@ namespace mongo { extern int internalQueryExecMaxBlockingSortBytes; + // Yield after this many "should yield?" checks. Only applies to storage engines that + // do not support doc-level locking. + extern int internalQueryExecYieldIterations; + + // Yield if it's been at least this many milliseconds since we last yielded. Only applies + // to storage engines that do not support doc-level locking. + extern int internalQueryExecYieldPeriodMS; + } // namespace mongo diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 82b5b919246..9d8ef7d998f 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -64,6 +64,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/ops/delete.h" #include "mongo/db/query/internal_plans.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/db/range_deleter_service.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/repl_coordinator_global.h" @@ -554,7 +555,8 @@ namespace mongo { return false; } - ElapsedTracker tracker (128, 10); // same as ClientCursor::_yieldSometimesTracker + ElapsedTracker tracker(internalQueryExecYieldIterations, + internalQueryExecYieldPeriodMS); int allocSize; { |