foundationdb/fdbserver/workloads/RYWPerformance.actor.cpp

316 lines
9.4 KiB
C++
Raw Normal View History

2017-05-26 04:48:44 +08:00
/*
* RYWPerformance.actor.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
2017-05-26 04:48:44 +08:00
* 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
*
2017-05-26 04:48:44 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
*
2017-05-26 04:48:44 +08:00
* 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 "fdbrpc/ContinuousSample.h"
#include "fdbclient/NativeAPI.actor.h"
#include "fdbserver/TesterInterface.actor.h"
2017-05-26 04:48:44 +08:00
#include "fdbclient/ReadYourWrites.h"
#include "fdbserver/workloads/workloads.actor.h"
#include "flow/actorcompiler.h" // This must be the last #include.
2017-05-26 04:48:44 +08:00
struct RYWPerformanceWorkload : TestWorkload {
int keyBytes, nodes, ranges;
RYWPerformanceWorkload(WorkloadContext const& wcx) : TestWorkload(wcx) {
nodes = getOption(options, LiteralStringRef("nodes"), 10000);
ranges = getOption(options, LiteralStringRef("ranges"), 10);
keyBytes = std::max(getOption(options, LiteralStringRef("keyBytes"), 16), 16);
2017-05-26 04:48:44 +08:00
}
2020-10-05 13:29:07 +08:00
std::string description() const override { return "RYWPerformance"; }
2017-05-26 04:48:44 +08:00
2020-10-05 13:29:07 +08:00
Future<Void> setup(Database const& cx) override {
if (clientId == 0)
return _setup(cx, this);
2017-05-26 04:48:44 +08:00
return Void();
}
ACTOR Future<Void> _setup(Database cx, RYWPerformanceWorkload* self) {
2017-05-26 04:48:44 +08:00
state Transaction tr(cx);
loop {
try {
for (int i = 0; i < self->nodes; i++)
tr.set(self->keyForIndex(i), LiteralStringRef("bar"));
2017-05-26 04:48:44 +08:00
wait(tr.commit());
2017-05-26 04:48:44 +08:00
break;
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
2017-05-26 04:48:44 +08:00
return Void();
}
2020-10-05 13:29:07 +08:00
Future<Void> start(Database const& cx) override {
if (clientId == 0)
return _start(cx, this);
2017-05-26 04:48:44 +08:00
return Void();
}
ACTOR static Future<Void> fillCache(ReadYourWritesTransaction* tr, RYWPerformanceWorkload* self, int type) {
2017-05-26 04:48:44 +08:00
state int i;
if (type == 0) {
for (i = 0; i < self->nodes; i++) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 1) {
2017-05-26 04:48:44 +08:00
std::vector<Future<Optional<Value>>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->get(self->keyForIndex(i)));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
} else if (type == 2) {
2017-05-26 04:48:44 +08:00
std::vector<Future<Optional<Value>>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->get(self->keyForIndex(i)));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 0; i < self->nodes; i++) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 3) {
2017-05-26 04:48:44 +08:00
std::vector<Future<Optional<Value>>> gets;
for (i = 0; i < self->nodes; i += 2) {
gets.push_back(tr->get(self->keyForIndex(i)));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 1; i < self->nodes; i += 2) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 4) {
wait(success(tr->getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
} else if (type == 5) {
wait(success(tr->getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
for (i = 0; i < self->nodes; i++) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 6) {
wait(success(tr->getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
for (i = 0; i < self->nodes; i += 2) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 7) {
wait(success(tr->getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
for (i = 0; i < self->nodes; i++) {
tr->clear(self->keyForIndex(i));
2017-05-26 04:48:44 +08:00
}
} else if (type == 8) {
wait(success(tr->getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
for (i = 0; i < self->nodes; i += 2) {
tr->clear(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 1)));
2017-05-26 04:48:44 +08:00
}
} else if (type == 9) {
2021-05-04 04:14:16 +08:00
std::vector<Future<RangeResult>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->getRange(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 2)), self->nodes));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
} else if (type == 10) {
2021-05-04 04:14:16 +08:00
std::vector<Future<RangeResult>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->getRange(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 2)), self->nodes));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 0; i < self->nodes; i++) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 11) {
2021-05-04 04:14:16 +08:00
std::vector<Future<RangeResult>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->getRange(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 2)), self->nodes));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 0; i < self->nodes; i += 2) {
tr->set(self->keyForIndex(i), LiteralStringRef("foo"));
2017-05-26 04:48:44 +08:00
}
} else if (type == 12) {
2021-05-04 04:14:16 +08:00
std::vector<Future<RangeResult>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->getRange(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 2)), self->nodes));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 0; i < self->nodes; i++) {
tr->clear(self->keyForIndex(i));
2017-05-26 04:48:44 +08:00
}
} else if (type == 13) {
2021-05-04 04:14:16 +08:00
std::vector<Future<RangeResult>> gets;
for (i = 0; i < self->nodes; i++) {
gets.push_back(tr->getRange(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 2)), self->nodes));
2017-05-26 04:48:44 +08:00
}
wait(waitForAll(gets));
for (i = 0; i < self->nodes; i += 2) {
tr->clear(KeyRangeRef(self->keyForIndex(i), self->keyForIndex(i + 1)));
2017-05-26 04:48:44 +08:00
}
}
return Void();
}
ACTOR static Future<Void> test_get_single(Database cx, RYWPerformanceWorkload* self, int cacheType) {
2017-05-26 04:48:44 +08:00
state int i;
state ReadYourWritesTransaction tr(cx);
2017-05-26 04:48:44 +08:00
loop {
try {
wait(self->fillCache(&tr, self, cacheType));
2017-05-26 04:48:44 +08:00
state double startTime = timer();
for (i = 0; i < self->nodes; i++) {
wait(success(tr.get(self->keyForIndex(self->nodes / 2))));
2017-05-26 04:48:44 +08:00
}
2017-05-26 04:48:44 +08:00
fprintf(stderr, "%f", self->nodes / (timer() - startTime));
return Void();
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
}
ACTOR static Future<Void> test_get_many_sequential(Database cx, RYWPerformanceWorkload* self, int cacheType) {
2017-05-26 04:48:44 +08:00
state int i;
state ReadYourWritesTransaction tr(cx);
2017-05-26 04:48:44 +08:00
loop {
try {
wait(self->fillCache(&tr, self, cacheType));
2017-05-26 04:48:44 +08:00
state double startTime = timer();
for (i = 0; i < self->nodes; i++) {
wait(success(tr.get(self->keyForIndex(i))));
2017-05-26 04:48:44 +08:00
}
2017-05-26 04:48:44 +08:00
fprintf(stderr, "%f", self->nodes / (timer() - startTime));
return Void();
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
}
ACTOR static Future<Void> test_get_range_basic(Database cx, RYWPerformanceWorkload* self, int cacheType) {
2017-05-26 04:48:44 +08:00
state int i;
state ReadYourWritesTransaction tr(cx);
2017-05-26 04:48:44 +08:00
loop {
try {
wait(self->fillCache(&tr, self, cacheType));
2017-05-26 04:48:44 +08:00
state double startTime = timer();
for (i = 0; i < self->ranges; i++) {
wait(success(
tr.getRange(KeyRangeRef(self->keyForIndex(0), self->keyForIndex(self->nodes)), self->nodes)));
2017-05-26 04:48:44 +08:00
}
2017-05-26 04:48:44 +08:00
fprintf(stderr, "%f", self->ranges / (timer() - startTime));
return Void();
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
}
ACTOR static Future<Void> test_interleaved_sets_gets(Database cx, RYWPerformanceWorkload* self, int cacheType) {
2017-05-26 04:48:44 +08:00
state int i;
state ReadYourWritesTransaction tr(cx);
2017-05-26 04:48:44 +08:00
loop {
try {
wait(self->fillCache(&tr, self, cacheType));
2017-05-26 04:48:44 +08:00
tr.set(self->keyForIndex(self->nodes / 2), self->keyForIndex(self->nodes));
2017-05-26 04:48:44 +08:00
state double startTime = timer();
for (i = 0; i < self->nodes; i++) {
wait(success(tr.get(self->keyForIndex(self->nodes / 2))));
tr.set(self->keyForIndex(self->nodes / 2), self->keyForIndex(i));
2017-05-26 04:48:44 +08:00
}
2017-05-26 04:48:44 +08:00
fprintf(stderr, "%f", self->nodes / (timer() - startTime));
return Void();
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
}
ACTOR static Future<Void> _start(Database cx, RYWPerformanceWorkload* self) {
2017-05-26 04:48:44 +08:00
state int i;
fprintf(stderr, "test_get_single, ");
for (i = 0; i < 14; i++) {
wait(self->test_get_single(cx, self, i));
if (i == 13)
fprintf(stderr, "\n");
else
fprintf(stderr, ", ");
2017-05-26 04:48:44 +08:00
}
fprintf(stderr, "test_get_many_sequential, ");
for (i = 0; i < 14; i++) {
wait(self->test_get_many_sequential(cx, self, i));
if (i == 13)
fprintf(stderr, "\n");
else
fprintf(stderr, ", ");
2017-05-26 04:48:44 +08:00
}
fprintf(stderr, "test_get_range_basic, ");
for (i = 4; i < 14; i++) {
wait(self->test_get_range_basic(cx, self, i));
if (i == 13)
fprintf(stderr, "\n");
else
fprintf(stderr, ", ");
2017-05-26 04:48:44 +08:00
}
fprintf(stderr, "test_interleaved_sets_gets, ");
for (i = 0; i < 14; i++) {
wait(self->test_interleaved_sets_gets(cx, self, i));
if (i == 13)
fprintf(stderr, "\n");
else
fprintf(stderr, ", ");
2017-05-26 04:48:44 +08:00
}
return Void();
}
2020-10-05 13:29:07 +08:00
Future<bool> check(Database const& cx) override { return true; }
2017-05-26 04:48:44 +08:00
2020-10-05 13:29:07 +08:00
void getMetrics(vector<PerfMetric>& m) override {}
2017-05-26 04:48:44 +08:00
Key keyForIndex(uint64_t index) {
Key result = makeString(keyBytes);
uint8_t* data = mutateString(result);
2017-05-26 04:48:44 +08:00
memset(data, '.', keyBytes);
double d = double(index) / nodes;
emplaceIndex(data, 0, *(int64_t*)&d);
2017-05-26 04:48:44 +08:00
return result;
}
};
WorkloadFactory<RYWPerformanceWorkload> RYWPerformanceWorkloadFactory("RYWPerformance");