Revision 0bb555630f5e85a1471843f8dc0dabec297c1c49 authored by Siying Dong on 08 April 2019, 20:24:29 UTC, committed by Facebook Github Bot on 08 April 2019, 20:32:06 UTC
Summary: Create new function NPHash64() and GetSliceNPHash64(), which are currently implemented using murmurhash. Replace the current direct call of murmurhash() to use the new functions if the hash results are not used in on-disk format. This will make it easier to try out or switch to alternative functions in the uses where data format compatibility doesn't need to be considered. This part shouldn't have any performance impact. Also, the sharded cache hash function is changed to the new format, because it falls into this categoery. It doesn't show visible performance impact in db_bench results. CPU showed by perf is increased from about 0.2% to 0.4% in an extreme benchmark setting (4KB blocks, no-compression, everything cached in block cache). We've known that the current hash function used, our own Hash() has serious hash quality problem. It can generate a lots of conflicts with similar input. In this use case, it means extra lock contention for reads from the same file. This slight CPU regression is worthy to me to counter the potential bad performance with hot keys. And hopefully this will get further improved in the future with a better hash function. cache_test's condition is relaxed a little bit to. The new hash is slightly more skewed in this use case, but I manually checked the data and see the hash results are still in a reasonable range. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5155 Differential Revision: D14834821 Pulled By: siying fbshipit-source-id: ec9a2c0a2f8ae4b54d08b13a5c2e9cc97aa80cb5
1 parent de00f28
util_merge_operators_test.cc
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include "util/testharness.h"
#include "util/testutil.h"
#include "utilities/merge_operators.h"
namespace rocksdb {
class UtilMergeOperatorTest : public testing::Test {
public:
UtilMergeOperatorTest() {}
std::string FullMergeV2(std::string existing_value,
std::vector<std::string> operands,
std::string key = "") {
std::string result;
Slice result_operand(nullptr, 0);
Slice existing_value_slice(existing_value);
std::vector<Slice> operands_slice(operands.begin(), operands.end());
const MergeOperator::MergeOperationInput merge_in(
key, &existing_value_slice, operands_slice, nullptr);
MergeOperator::MergeOperationOutput merge_out(result, result_operand);
merge_operator_->FullMergeV2(merge_in, &merge_out);
if (result_operand.data()) {
result.assign(result_operand.data(), result_operand.size());
}
return result;
}
std::string FullMergeV2(std::vector<std::string> operands,
std::string key = "") {
std::string result;
Slice result_operand(nullptr, 0);
std::vector<Slice> operands_slice(operands.begin(), operands.end());
const MergeOperator::MergeOperationInput merge_in(key, nullptr,
operands_slice, nullptr);
MergeOperator::MergeOperationOutput merge_out(result, result_operand);
merge_operator_->FullMergeV2(merge_in, &merge_out);
if (result_operand.data()) {
result.assign(result_operand.data(), result_operand.size());
}
return result;
}
std::string PartialMerge(std::string left, std::string right,
std::string key = "") {
std::string result;
merge_operator_->PartialMerge(key, left, right, &result, nullptr);
return result;
}
std::string PartialMergeMulti(std::deque<std::string> operands,
std::string key = "") {
std::string result;
std::deque<Slice> operands_slice(operands.begin(), operands.end());
merge_operator_->PartialMergeMulti(key, operands_slice, &result, nullptr);
return result;
}
protected:
std::shared_ptr<MergeOperator> merge_operator_;
};
TEST_F(UtilMergeOperatorTest, MaxMergeOperator) {
merge_operator_ = MergeOperators::CreateMaxOperator();
EXPECT_EQ("B", FullMergeV2("B", {"A"}));
EXPECT_EQ("B", FullMergeV2("A", {"B"}));
EXPECT_EQ("", FullMergeV2({"", "", ""}));
EXPECT_EQ("A", FullMergeV2({"A"}));
EXPECT_EQ("ABC", FullMergeV2({"ABC"}));
EXPECT_EQ("Z", FullMergeV2({"ABC", "Z", "C", "AXX"}));
EXPECT_EQ("ZZZ", FullMergeV2({"ABC", "CC", "Z", "ZZZ"}));
EXPECT_EQ("a", FullMergeV2("a", {"ABC", "CC", "Z", "ZZZ"}));
EXPECT_EQ("z", PartialMergeMulti({"a", "z", "efqfqwgwew", "aaz", "hhhhh"}));
EXPECT_EQ("b", PartialMerge("a", "b"));
EXPECT_EQ("z", PartialMerge("z", "azzz"));
EXPECT_EQ("a", PartialMerge("a", ""));
}
} // namespace rocksdb
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...