Skip to content

Commit

Permalink
SERVER-29838 Implement basic adaptive ServiceExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
jbreams committed Aug 2, 2017
1 parent c99aaa0 commit 20c85d4
Show file tree
Hide file tree
Showing 17 changed files with 1,127 additions and 428 deletions.
173 changes: 131 additions & 42 deletions etc/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2434,15 +2434,6 @@ tasks:
resmoke_args: --suites=core --storageEngine=mmapv1
run_multiple_jobs: true

- <<: *task_template
name: jsCore_async
commands:
- func: "do setup"
- func: "run tests"
vars:
resmoke_args: --suites=core --storageEngine=wiredTiger --serviceExecutor=fixedForTesting
run_multiple_jobs: true

- <<: *task_template
name: jsCore_inMem
commands:
Expand Down Expand Up @@ -2919,16 +2910,6 @@ tasks:
vars:
resmoke_args: --suites=parallel --storageEngine=wiredTiger

- <<: *task_template
name: parallel_async
depends_on:
- name: jsCore_async
commands:
- func: "do setup"
- func: "run tests"
vars:
resmoke_args: --suites=parallel --storageEngine=wiredTiger --serviceExecutor=fixedForTesting

- <<: *task_template
name: parallel_compatibility
depends_on:
Expand Down Expand Up @@ -3264,15 +3245,6 @@ tasks:
resmoke_args: --suites=ssl
run_multiple_jobs: true

- <<: *task_template
name: ssl_async
commands:
- func: "do setup"
- func: "run tests"
vars:
resmoke_args: --suites=ssl --serviceExecutor=fixedForTesting
run_multiple_jobs: true

- <<: *task_template
name: sslSpecial
commands:
Expand All @@ -3282,15 +3254,6 @@ tasks:
resmoke_args: --suites=ssl_special
run_multiple_jobs: true

- <<: *task_template
name: sslSpecial_async
commands:
- func: "do setup"
- func: "run tests"
vars:
resmoke_args: --suites=ssl_special --serviceExecutor=fixedForTesting
run_multiple_jobs: true

- <<: *task_template
name: tool
commands:
Expand Down Expand Up @@ -5609,11 +5572,12 @@ buildvariants:
num_jobs_available: $(grep -c ^processor /proc/cpuinfo)
ext: zip
use_scons_cache: true
test_flags: --serviceExecutor=adaptive
tasks:
- name: compile
distros:
- windows-64-vs2015-large
- name: jsCore_async
- name: jsCore

- name: enterprise-windows-64-2k8-inmem
display_name: Enterprise Windows 2008R2 (inMemory)
Expand Down Expand Up @@ -9287,12 +9251,137 @@ buildvariants:
num_jobs_available: $(($(grep -c ^processor /proc/cpuinfo) / 3)) # Avoid starting too many mongod's under {A,UB}SAN build.
build_mongoreplay: false
hang_analyzer_dump_core: false
test_flags: --serviceExecutor=adaptive
tasks:
- name: compile
- name: jsCore_async
- name: parallel_async
- name: ssl_async
- name: sslSpecial_async
- name: compile_all
- name: aggregation
- name: aggregation_WT
- name: aggregation_WT_ese
- name: aggregation_auth
- name: aggregation_facet_unwind_passthrough_WT
- name: aggregation_read_concern_majority_passthrough_WT
- name: aggregation_sharded_collections_passthrough_WT
# TODO Put back when SERVER-30471 is done
# - name: audit
# - name: audit_WT
# - name: auth
# - name: auth_WT
# - name: auth_audit
# - name: auth_audit_WT
- name: bulk_gle_passthrough
- name: bulk_gle_passthrough_WT
- name: causally_consistent_jscore_passthrough_WT
- name: causally_consistent_jscore_passthrough_auth_WT
- name: concurrency
- name: concurrency_WT
- name: concurrency_replication
- name: concurrency_replication_WT
- name: concurrency_sharded
- name: concurrency_sharded_WT
- name: concurrency_simultaneous
- name: concurrency_simultaneous_WT
- name: dbtest
- name: dbtest_WT
- name: disk
- name: disk_WT
- name: dur_jscore_passthrough
- name: durability
- name: ese_WT
- name: failpoints
- name: failpoints_auth
- name: gle_auth
- name: gle_auth_WT
- name: gle_auth_basics_passthrough
- name: gle_auth_basics_passthrough_WT
- name: gle_auth_basics_passthrough_write_cmd
- name: gle_auth_basics_passthrough_write_cmd_WT
- name: gle_auth_write_cmd
- name: gle_auth_write_cmd_WT
- name: integration_tests_replset
- name: integration_tests_sharded
- name: integration_tests_standalone
- name: jsCore
- name: jsCore_WT
- name: jsCore_WT_ese
- name: jsCore_inMem
- name: jsCore_auth
- name: jsCore_compatibility
- name: jsCore_compatibility_WT
- name: jsCore_decimal
- name: jsCore_decimal_WT
- name: jsCore_minimum_batch_size_WT
- name: jsCore_op_query
- name: jsCore_op_query_WT
- name: mmap
- name: mongosTest
- name: multiversion
- name: multiversion_auth
- name: multiversion_WT
- name: multiversion_multistorage_engine
- name: noPassthrough
- name: noPassthroughWithMongod
- name: noPassthroughWithMongod_WT
- name: noPassthrough_WT
- name: parallel
- name: parallel_WT
- name: parallel_compatibility
- name: parallel_compatibility_WT
- name: read_concern_linearizable_passthrough
- name: read_concern_linearizable_passthrough_WT
- name: read_concern_majority_passthrough_WT
- name: read_only
- name: read_only_WT
- name: read_only_sharded
- name: read_only_sharded_WT
# TODO Put back when SERVER-30471 is done
# - name: replica_sets
# - name: replica_sets_WT
# - name: replica_sets_WT_ese
# - name: replica_sets_auth
# - name: replica_sets_pv0
- name: replica_sets_jscore_passthrough
- name: replica_sets_jscore_passthrough_WT
- name: replica_sets_initsync_jscore_passthrough
- name: replica_sets_initsync_jscore_passthrough_WT
- name: replica_sets_initsync_static_jscore_passthrough
- name: replica_sets_initsync_static_jscore_passthrough_WT
- name: replica_sets_resync_static_jscore_passthrough
- name: replica_sets_resync_static_jscore_passthrough_WT
- name: replica_sets_kill_secondaries_jscore_passthrough_WT
- name: master_slave
- name: master_slave_WT
- name: master_slave_auth
- name: master_slave_jscore_passthrough
- name: master_slave_jscore_passthrough_WT
- name: sasl
- name: sharded_collections_jscore_passthrough
- name: sharded_collections_jscore_passthrough_WT
- name: sharding
- name: sharding_WT
- name: sharding_WT_ese
- name: sharding_auth
- name: sharding_auth_audit_WT
- name: sharding_gle_auth_basics_passthrough
- name: sharding_gle_auth_basics_passthrough_WT
- name: sharding_gle_auth_basics_passthrough_write_cmd
- name: sharding_gle_auth_basics_passthrough_write_cmd_WT
- name: sharding_last_stable_mongos_and_mixed_shards
- name: sharding_jscore_passthrough
- name: sharding_jscore_passthrough_WT
- name: sharding_jscore_op_query_passthrough_WT
- name: sharding_jscore_passthrough_wire_ops_WT
- name: sharding_op_query_WT
- name: slow1
- name: slow1_WT
- name: serial_run
- name: serial_run_WT
- name: snmp
- name: snmp_WT
- name: ssl
- name: sslSpecial
- name: tool
- name: tool_WT

- name: enterprise-ubuntu-dynamic-1604-64-bit
display_name: "* Shared Library Enterprise Ubuntu 16.04"
Expand Down
8 changes: 2 additions & 6 deletions jstests/noPassthrough/transportlayer_boot_cmdline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@
var baseDir = "jstests_transportlayer_boot_cmdline";
var dbpath = MongoRunner.dataPath + baseDir + "/";

var m = MongoRunner.runMongod({dbpath: dbpath, transportLayer: 'legacy'});
assert(m, 'MongoDB with transportLayer=legacy failed to start up');
MongoRunner.stopMongod(m);

m = MongoRunner.runMongod(
var m = MongoRunner.runMongod(
{dbpath: dbpath, transportLayer: 'legacy', serviceExecutor: 'synchronous'});
assert(m,
'MongoDB with transportLayer=legacy and serviceExecutor=synchronous failed to start up');
MongoRunner.stopMongod(m);

m = MongoRunner.runMongod(
{dbpath: dbpath, transportLayer: 'legacy', serviceExecutor: 'fixedForTesting'});
{dbpath: dbpath, transportLayer: 'legacy', serviceExecutor: 'adaptive'});
assert.isnull(
m,
'MongoDB with transportLayer=legacy and serviceExecutor=fixedForTesting managed to startup which is an unsupported combination');
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/server_options_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ Status storeServerOptions(const moe::Environment& params) {
"must be \"synchronous\""};
}
} else {
const auto valid = {"synchronous"_sd, "fixedForTesting"_sd};
const auto valid = {"synchronous"_sd, "adaptive"_sd};
if (std::find(valid.begin(), valid.end(), value) == valid.end()) {
return {ErrorCodes::BadValue, "Unsupported value for serviceExecutor"};
}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/service_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "mongo/stdx/functional.h"
#include "mongo/stdx/memory.h"
#include "mongo/stdx/mutex.h"
#include "mongo/transport/service_executor_base.h"
#include "mongo/transport/service_executor.h"
#include "mongo/transport/session.h"
#include "mongo/util/clock_source.h"
#include "mongo/util/decorable.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/shell/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ var MongoRunner, _startMongod, startMongoProgram, runMongoProgram, startMongoPro
if (jsTest.options().serviceExecutor &&
(!programVersion || (parseInt(programVersion.split(".")[0]) >= 3 &&
parseInt(programVersion.split(".")[1]) >= 5))) {
if (!argArrayContains("serviceExecutor")) {
if (!argArrayContains("--serviceExecutor")) {
argArray.push(...["--serviceExecutor", jsTest.options().serviceExecutor]);
}
}
Expand Down
45 changes: 31 additions & 14 deletions src/mongo/transport/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@ env.Library(
)

env.Library(
target='transport_layer_manager',
target='transport_layer_mock',
source=[
'transport_layer_manager.cpp',
'transport_layer_mock.cpp',
],
LIBDEPS=[
'transport_layer',
],
LIBDEPS_PRIVATE=[
'service_executor',
'transport_layer_common',
],
)

env.Library(
target='transport_layer_mock',
tlEnv = env.Clone()
tlEnv.InjectThirdPartyIncludePaths(libraries=['asio'])

tlEnv.Library(
target='transport_layer_manager',
source=[
'transport_layer_mock.cpp',
'transport_layer_manager.cpp',
],
LIBDEPS=[
'transport_layer_common',
'transport_layer',
],
LIBDEPS_PRIVATE=[
'service_executor',
'$BUILD_DIR/third_party/shim_asio',
],
)

tlEnv = env.Clone()
tlEnv.InjectThirdPartyIncludePaths(libraries=['asio'])
tlEnv.Library(
target='transport_layer',
source=[
Expand All @@ -67,15 +69,16 @@ tlEnv.Library(
'$BUILD_DIR/mongo/db/server_options_core',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/db/stats/counters',
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/third_party/shim_asio',
],
)

tlEnv.Library(
target='service_executor',
source=[
'service_executor_base.cpp',
'service_executor_fixed.cpp',
'service_executor_adaptive.cpp',
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/service_context',
Expand All @@ -86,6 +89,20 @@ tlEnv.Library(
],
)

tlEnv.CppUnitTest(
target='service_executor_adaptive_test',
source=[
'service_executor_adaptive_test.cpp',
],
LIBDEPS=[
'service_executor',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/unittest/unittest',
'$BUILD_DIR/mongo/util/clock_source_mock',
'$BUILD_DIR/third_party/shim_asio',
],
)

env.Library(
target='service_entry_point_test_suite',
source=[
Expand Down
9 changes: 8 additions & 1 deletion src/mongo/transport/service_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class ServiceExecutor {
public:
virtual ~ServiceExecutor() = default;
using Task = stdx::function<void()>;
enum ScheduleFlags {
EmptyFlags = 0,
DeferredTask = 1,
};

/*
* Starts the ServiceExecutor. This may create threads even if no tasks are scheduled.
Expand All @@ -56,8 +60,11 @@ class ServiceExecutor {
*
* This is guaranteed to unwind the stack before running the task, although the task may be
* run later in the same thread.
*
* If defer is true, then the executor may defer execution of this Task until an available
* thread is available.
*/
virtual Status schedule(Task task) = 0;
virtual Status schedule(Task task, ScheduleFlags flags) = 0;

/*
* Stops and joins the ServiceExecutor. Any outstanding tasks will not be executed, and any
Expand Down
Loading

0 comments on commit 20c85d4

Please sign in to comment.