Go to the source code of this file.
Definition at line 20 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_EQ, FOR_EACH_KV, proxygen::RendezvousHash::get(), and i.
22 std::vector<std::pair<std::string, uint64_t> > nodes;
23 for (
int i = 0;
i < 10; ++
i) {
24 nodes.emplace_back(folly::to<std::string>(
"key",
i), 1);
28 for (
size_t rank = 0; rank < nodes.size() + 2; rank++) {
29 std::map<uint64_t, size_t> mapping;
30 for (
int i = 0;
i < 10000; ++
i) {
31 mapping[
i] = hashes.
get(
i, rank);
#define FOR_EACH_KV(k, v, c)
#define EXPECT_EQ(val1, val2)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
Definition at line 40 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_TRUE, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
43 std::vector<std::pair<std::string, uint64_t> > nodes;
44 for (
int i = 0;
i < numNodes; ++
i) {
45 nodes.emplace_back(folly::to<std::string>(
"key",
i), 1);
48 std::map<uint64_t, size_t> mapping;
50 mapping[
i] = hashes.
get(
i);
54 nodes.emplace_back(folly::to<std::string>(
"key", numNodes), 1);
58 size_t id = hashes.
get(key);
#define FOR_EACH_KV(k, v, c)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
#define EXPECT_TRUE(condition)
Definition at line 63 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_EQ, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
66 std::vector<std::pair<std::string, uint64_t> > nodes;
67 for (
int i = 0;
i < numNodes; ++
i) {
68 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
72 std::map<uint64_t, size_t> mapping;
74 mapping[
i] = hashes.
get(
i);
80 for (
int i = 0;
i < numNodes; ++
i) {
81 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i*2);
#define FOR_EACH_KV(k, v, c)
#define EXPECT_EQ(val1, val2)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
Definition at line 91 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_TRUE, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
94 std::vector<std::pair<std::string, uint64_t> > nodes;
95 for (
int i = 0;
i < numNodes; ++
i) {
96 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
100 std::map<uint64_t, size_t> mapping;
102 mapping[
i] = hashes.
get(
i);
109 nodes.emplace_back(folly::to<std::string>(
"key", 0), 10);
111 for (
int i = 1;
i < numNodes; ++
i) {
112 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
117 size_t id = hashes.
get(key);
#define FOR_EACH_KV(k, v, c)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
#define EXPECT_TRUE(condition)
Definition at line 122 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_TRUE, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
125 std::vector<std::pair<std::string, uint64_t> > nodes;
126 for (
int i = 0;
i < numNodes; ++
i) {
127 nodes.emplace_back(folly::to<std::string>(
"key",
i), 100);
130 std::map<uint64_t, size_t> mapping;
132 mapping[
i] = hashes.
get(
i);
139 for (
int i = 0;
i < 5; ++
i) {
140 nodes.emplace_back(folly::to<std::string>(
"key",
i), 50);
144 for (
int i = 5;
i < numNodes; ++
i) {
145 nodes.emplace_back(folly::to<std::string>(
"key",
i), 100);
151 size_t id = hashes.
get(key);
#define FOR_EACH_KV(k, v, c)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
#define EXPECT_TRUE(condition)
Definition at line 156 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_TRUE, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
159 std::vector<std::pair<std::string, uint64_t> > nodes;
160 for (
int i = 0;
i < numNodes; ++
i) {
161 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
164 std::map<uint64_t, size_t> mapping;
166 mapping[
i] = hashes.
get(
i);
173 for (
int i = 0;
i < numNodes - 1; ++
i) {
174 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
178 nodes.emplace_back(folly::to<std::string>(
"key", numNodes-1), 0);
182 size_t id = hashes.
get(key);
183 if (expected == (
uint64_t)numNodes-1) {
#define FOR_EACH_KV(k, v, c)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
#define EXPECT_TRUE(condition)
Definition at line 191 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_EQ, FOR_EACH_KV, proxygen::RendezvousHash::get(), i, and uint64_t.
194 std::vector<std::pair<std::string, uint64_t> > nodes;
195 for (
int i = 0;
i < numNodes; ++
i) {
196 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i*2);
199 std::map<uint64_t, size_t> mapping;
201 mapping[
i] = hashes.
get(
i);
208 for (
int i = 0;
i < numNodes; ++
i) {
209 nodes.emplace_back(folly::to<std::string>(
"key",
i),
i);
#define FOR_EACH_KV(k, v, c)
#define EXPECT_EQ(val1, val2)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
TEST |
( |
ConsistentHashRing |
, |
|
|
DistributionAccuracy |
|
|
) |
| |
Definition at line 219 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_LE, FOR_EACH_RANGE, proxygen::RendezvousHash::get(), i, max, and uint64_t.
220 std::vector<std::string> keys =
221 {
"ash_proxy",
"prn_proxy",
"snc_proxy",
"frc_proxy"};
223 std::vector<std::vector<uint64_t>> weights = {
229 {922337203685, 12395828300, 50192385101, 59293845010}
232 for (
auto& weight: weights) {
234 std::vector<std::pair<std::string, uint64_t> > nodes;
236 nodes.emplace_back(keys[
i], weight[i]);
240 std::vector<uint64_t> distribution(keys.size());
243 distribution[hashes.
get(
i)]++;
248 for (
auto& w: weight) {
252 double maxError = 0.0;
253 for (
size_t i = 0;
i < keys.size(); ++
i) {
254 double expected = 100.0 * weight[
i] / totalWeight;
255 double actual = 100.0 * distribution[
i] / 21000;
257 maxError =
std::max(maxError, fabs(expected - actual));
#define EXPECT_LE(val1, val2)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
size_t get(const uint64_t key, const size_t rank=0) const override
#define FOR_EACH_RANGE(i, begin, end)
Definition at line 264 of file RendezvousHashTest.cpp.
References proxygen::RendezvousHash::build(), EXPECT_EQ, EXPECT_GT, EXPECT_LT, i, seed, proxygen::RendezvousHash::selectNUnweighted(), and folly::size().
266 std::vector<std::pair<std::string, uint64_t>> nodes;
268 for (
int i = 0;
i <
size; ++
i) {
269 nodes.emplace_back(folly::to<std::string>(
"key",
i), 1);
272 auto seed = 91484253;
277 for (
int i = 0;
i <
size;
i++) {
285 std::set<size_t> uniqueIndex;
286 for (
auto index : select) {
288 uniqueIndex.insert(index);
293 for (
int i = 1;
i < 100;
i++) {
296 for (
auto index : select) {
297 if (uniqueIndex.count(index) == 0) {
#define EXPECT_EQ(val1, val2)
void build(std::vector< std::pair< std::string, uint64_t >> &) override
constexpr auto size(C const &c) -> decltype(c.size())
std::vector< size_t > selectNUnweighted(const uint64_t key, const size_t rank) const
#define EXPECT_LT(val1, val2)
#define EXPECT_GT(val1, val2)