summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Guo <robert.guo@10gen.com>2015-09-21 16:32:37 -0400
committerRobert Guo <robert.guo@10gen.com>2015-09-29 13:46:10 -0400
commitc2265fdcc431b7ab15ff4da0f22615ccc7f9b4f7 (patch)
tree89e4b711d31e0a8500f0fb0b2731f6bc93e38f53
parentd2d653a4c728e4bd636a8055c8f665bd3489b335 (diff)
downloadmongo-c2265fdcc431b7ab15ff4da0f22615ccc7f9b4f7.tar.gz
SERVER-20560 Standalone Perf Test for the Networking Interface
-rw-r--r--src/mongo/client/remote_command_runner_impl.cpp10
-rw-r--r--src/mongo/executor/SConscript14
-rw-r--r--src/mongo/executor/network_interface_perf_test.cpp122
3 files changed, 136 insertions, 10 deletions
diff --git a/src/mongo/client/remote_command_runner_impl.cpp b/src/mongo/client/remote_command_runner_impl.cpp
index 486e039b148..65865525f38 100644
--- a/src/mongo/client/remote_command_runner_impl.cpp
+++ b/src/mongo/client/remote_command_runner_impl.cpp
@@ -31,7 +31,6 @@
#include "mongo/client/remote_command_runner_impl.h"
#include "mongo/base/status_with.h"
-#include "mongo/db/commands.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/query/cursor_response.h"
#include "mongo/db/query/getmore_request.h"
@@ -67,15 +66,6 @@ StatusWith<Milliseconds> getTimeoutMillis(const Date_t expDate, const Date_t now
}
/**
- * Updates command output document with status.
- */
-BSONObj getCommandResultFromStatus(const Status& status) {
- BSONObjBuilder result;
- Command::appendCommandStatus(result, status);
- return result.obj();
-}
-
-/**
* Peeks at error in cursor. If an error has occurred, converts the {$err: "...", code: N}
* cursor error to a Status.
*/
diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript
index ea5ee99b427..116f77a83c1 100644
--- a/src/mongo/executor/SConscript
+++ b/src/mongo/executor/SConscript
@@ -174,6 +174,20 @@ env.CppIntegrationTest(
],
)
+env.CppIntegrationTest(
+ target='network_interface_perf_test',
+ source=[
+ 'network_interface_perf_test.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init',
+ '$BUILD_DIR/mongo/rpc/command_status',
+ 'network_interface_asio',
+ 'network_interface_impl',
+ ],
+)
+
+
env.Library(
target='network_interface_factory',
source=[
diff --git a/src/mongo/executor/network_interface_perf_test.cpp b/src/mongo/executor/network_interface_perf_test.cpp
new file mode 100644
index 00000000000..90926f9ade9
--- /dev/null
+++ b/src/mongo/executor/network_interface_perf_test.cpp
@@ -0,0 +1,122 @@
+/**
+ * Copyright (C) 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kNetwork
+
+#include "mongo/platform/basic.h"
+
+#include <exception>
+
+#include "mongo/base/status_with.h"
+#include "mongo/bson/bsonmisc.h"
+#include "mongo/client/connection_string.h"
+#include "mongo/executor/async_stream_factory.h"
+#include "mongo/executor/async_stream_interface.h"
+#include "mongo/executor/async_timer_asio.h"
+#include "mongo/executor/network_interface_asio.h"
+#include "mongo/executor/network_interface_asio_test_utils.h"
+#include "mongo/executor/network_interface_impl.h"
+#include "mongo/executor/task_executor.h"
+#include "mongo/stdx/memory.h"
+#include "mongo/unittest/integration_test.h"
+#include "mongo/unittest/unittest.h"
+#include "mongo/util/assert_util.h"
+#include "mongo/util/log.h"
+#include "mongo/util/net/hostandport.h"
+#include "mongo/util/scopeguard.h"
+#include "mongo/util/timer.h"
+
+namespace mongo {
+namespace executor {
+namespace {
+
+const std::size_t numOperations = 16384;
+
+
+int timeNetworkTestMillis(std::size_t operations, NetworkInterface* net) {
+ net->startup();
+ auto guard = MakeGuard([&] { net->shutdown(); });
+
+ auto fixture = unittest::getFixtureConnectionString();
+ auto server = fixture.getServers()[0];
+
+ std::atomic<int> remainingOps(operations);
+ stdx::mutex mtx;
+ stdx::condition_variable cv;
+ Timer t;
+
+ // This lambda function is declared here since it is mutually recursive with another callback
+ // function
+ stdx::function<void()> func;
+
+ const auto bsonObjPing = BSON("ping" << 1);
+
+ const auto callback = [&](StatusWith<RemoteCommandResponse> resp) {
+ uassertStatusOK(resp);
+ if (--remainingOps) {
+ return func();
+ }
+ stdx::unique_lock<stdx::mutex> lk(mtx);
+ cv.notify_one();
+ };
+
+ func = [&]() {
+ net->startCommand(makeCallbackHandle(),
+ {server, "admin", bsonObjPing, bsonObjPing, Milliseconds(-1)},
+ callback);
+ };
+
+ func();
+
+ stdx::unique_lock<stdx::mutex> lk(mtx);
+ cv.wait(lk, [&] { return remainingOps.load() == 0; });
+
+ return t.millis();
+}
+
+TEST(NetworkInterfaceASIO, SerialPerf) {
+ NetworkInterfaceASIO::Options options{};
+ options.streamFactory = stdx::make_unique<AsyncStreamFactory>();
+ options.timerFactory = stdx::make_unique<AsyncTimerFactoryASIO>();
+ NetworkInterfaceASIO netAsio{std::move(options)};
+
+ int duration = timeNetworkTestMillis(numOperations, &netAsio);
+ int result = numOperations * 1000 / duration;
+ log() << "THROUGHPUT asio ping ops/s: " << result << std::endl;
+}
+
+TEST(NetworkInterfaceImpl, SerialPerf) {
+ NetworkInterfaceImpl netImpl{};
+ int duration = timeNetworkTestMillis(numOperations, &netImpl);
+ int result = numOperations * 1000 / duration;
+ log() << "THROUGHPUT impl ping ops/s: " << result << std::endl;
+}
+
+} // namespace
+} // namespace executor
+} // namespace mongo