Skip to content

Commit

Permalink
Create topkeys benchmark
Browse files Browse the repository at this point in the history
Topkeys was recently enhanced to add JSON support, however we are
seeing larger than expected amounts of time in top key
tracking. Create a simple benchmark to assist in measurement /
optimization.

Change-Id: I14a317e86319df88e4a349147840c3e8d8c8004a
Reviewed-on: http://review.couchbase.org/57039
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: buildbot <build@couchbase.com>
  • Loading branch information
daverigby authored and trondn committed Nov 16, 2015
1 parent 0fc0ce9 commit 424d4d8
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Expand Up @@ -12,3 +12,4 @@ ADD_SUBDIRECTORY(logger_test)
ADD_SUBDIRECTORY(sizes)
ADD_SUBDIRECTORY(mcbp)
ADD_SUBDIRECTORY(testapp)
ADD_SUBDIRECTORY(topkeys)
7 changes: 7 additions & 0 deletions tests/topkeys/CMakeLists.txt
@@ -0,0 +1,7 @@
ADD_EXECUTABLE(memcached_topkeys_bench
${PROJECT_SOURCE_DIR}/daemon/topkeys.cc
topkeys_bench.cc)
TARGET_LINK_LIBRARIES(memcached_topkeys_bench cJSON gtest gtest_main platform)
ADD_TEST(NAME memcached_topkeys_bench
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND memcached_topkeys_bench)
57 changes: 57 additions & 0 deletions tests/topkeys/topkeys_bench.cc
@@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
* Copyright 2015 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "daemon/topkeys.h"

#include <gtest/gtest.h>
#include <memory>


class TopKeysTest : public ::testing::Test {
protected:
void SetUp() {
topkeys.reset(new TopKeys(10));
}

std::unique_ptr<TopKeys> topkeys;
};

static void dump_key(const char* key, const uint16_t klen,
const char* val, const uint32_t vlen,
const void* cookie) {
size_t* count = static_cast<size_t*>(const_cast<void*>(cookie));
(*count)++;
}

TEST_F(TopKeysTest, Basic) {
// build list of keys
std::vector<std::string> keys;
for (int ii = 0; ii < 160; ii++) {
keys.emplace_back("topkey_test_" + std::to_string(ii));
}

// loop inserting keys
for (int jj = 0; jj < 20000; jj++) {
for (auto& key : keys) {
topkeys->updateKey(key.c_str(), key.size(), jj);
}
}

// Verify we hit all shards inside TopKeys
size_t count = 0;
topkeys->stats(&count, 0, dump_key);
EXPECT_EQ(80, count);
}

0 comments on commit 424d4d8

Please sign in to comment.