summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2014-11-13 15:23:36 -0500
committerGeert Bosch <geert@mongodb.com>2014-11-14 15:42:49 -0500
commit3d754a25fb3a14c4ddd47b5257b86e775fb17091 (patch)
tree9efe6c2ec4bd0c23b90ed3a1d56a6dd4a1af6f75
parent6334d8898369773c99be56ec1a4363ae5ee0e54d (diff)
downloadmongo-3d754a25fb3a14c4ddd47b5257b86e775fb17091.tar.gz
SERVER-16096: Add test case for locker perf
-rw-r--r--src/mongo/db/concurrency/lock_state_test.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp
index 2f23711c76c..d0d1fb48003 100644
--- a/src/mongo/db/concurrency/lock_state_test.cpp
+++ b/src/mongo/db/concurrency/lock_state_test.cpp
@@ -26,15 +26,20 @@
* it in the license file.
*/
+#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
+
#include "mongo/platform/basic.h"
#include <vector>
#include "mongo/db/concurrency/lock_mgr_test_help.h"
#include "mongo/unittest/unittest.h"
-
+#include "mongo/util/log.h"
namespace mongo {
+namespace {
+ const int NUM_PERF_ITERS = 1000*1000; // numeber of iterations to use for lock perf
+}
TEST(LockerImpl, LockNoConflict) {
const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));
@@ -208,4 +213,60 @@ namespace mongo {
locker.unlockAll();
}
+ TEST(Locker, PerformanceBoostSharedMutex) {
+ for (int numLockers = 1; numLockers <= 64; numLockers = numLockers * 2) {
+ boost::mutex mtx;
+
+ // Do some warm-up loops
+ for (int i = 0; i < 1000; i++) {
+ mtx.lock();
+ mtx.unlock();
+ }
+
+ // Measure the number of loops
+ //
+ Timer t;
+
+ for (int i = 0; i < NUM_PERF_ITERS; i++) {
+ mtx.lock();
+ mtx.unlock();
+ }
+
+ log() << numLockers
+ << " locks took: "
+ << static_cast<double>(t.micros()) * 1000.0 / static_cast<double>(NUM_PERF_ITERS)
+ << " ns";
+ }
+ }
+
+ TEST(Locker, PerformanceLocker) {
+ for (int numLockers = 1; numLockers <= 64; numLockers = numLockers * 2) {
+ std::vector<boost::shared_ptr<LockerForTests> > lockers(numLockers);
+ for (int i = 0; i < numLockers; i++) {
+ lockers[i].reset(new LockerForTests(LockerId(100 + i)));
+ }
+
+ LockerImpl<false> locker(1);
+
+ // Do some warm-up loops
+ for (int i = 0; i < 1000; i++) {
+ locker.lockGlobal(MODE_IS);
+ locker.unlockAll();
+ }
+
+ // Measure the number of loops
+ Timer t;
+
+ for (int i = 0; i < NUM_PERF_ITERS; i++) {
+ locker.lockGlobal(MODE_IS);
+ locker.unlockAll();
+ }
+
+ log() << numLockers
+ << " locks took: "
+ << static_cast<double>(t.micros()) * 1000.0 / static_cast<double>(NUM_PERF_ITERS)
+ << " ns";
+ }
+ }
+
} // namespace mongo