2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* WriteBandwidth.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-08-11 06:18:24 +08:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "fdbrpc/ContinuousSample.h"
|
2019-02-18 07:41:16 +08:00
|
|
|
#include "fdbclient/NativeAPI.actor.h"
|
2019-02-18 11:25:16 +08:00
|
|
|
#include "fdbserver/TesterInterface.actor.h"
|
2019-02-18 11:13:26 +08:00
|
|
|
#include "fdbserver/WorkerInterface.actor.h"
|
2019-02-18 11:18:30 +08:00
|
|
|
#include "fdbserver/workloads/workloads.actor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/workloads/BulkSetup.actor.h"
|
2021-03-11 02:06:03 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
struct WriteBandwidthWorkload : KVWorkload {
|
|
|
|
int keysPerTransaction;
|
|
|
|
double testDuration, warmingDelay, loadTime, maxInsertRate;
|
|
|
|
std::string valueString;
|
|
|
|
|
2019-05-17 04:54:06 +08:00
|
|
|
std::vector<Future<Void>> clients;
|
2017-05-26 04:48:44 +08:00
|
|
|
PerfIntCounter transactions, retries;
|
|
|
|
ContinuousSample<double> commitLatencies, GRVLatencies;
|
|
|
|
|
|
|
|
WriteBandwidthWorkload(WorkloadContext const& wcx)
|
2021-07-23 13:48:27 +08:00
|
|
|
: KVWorkload(wcx), loadTime(0.0), transactions("Transactions"), retries("Retries"), commitLatencies(2000),
|
|
|
|
GRVLatencies(2000) {
|
2021-03-11 02:06:03 +08:00
|
|
|
testDuration = getOption(options, LiteralStringRef("testDuration"), 10.0);
|
|
|
|
keysPerTransaction = getOption(options, LiteralStringRef("keysPerTransaction"), 100);
|
|
|
|
valueString = std::string(maxValueBytes, '.');
|
|
|
|
|
|
|
|
warmingDelay = getOption(options, LiteralStringRef("warmingDelay"), 0.0);
|
|
|
|
maxInsertRate = getOption(options, LiteralStringRef("maxInsertRate"), 1e12);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
std::string description() const override { return "WriteBandwidth"; }
|
|
|
|
Future<Void> setup(Database const& cx) override { return _setup(cx, this); }
|
|
|
|
Future<Void> start(Database const& cx) override { return _start(cx, this); }
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-10-05 13:29:07 +08:00
|
|
|
Future<bool> check(Database const& cx) override { return true; }
|
|
|
|
|
|
|
|
void getMetrics(std::vector<PerfMetric>& m) override {
|
2017-05-26 04:48:44 +08:00
|
|
|
double duration = testDuration;
|
|
|
|
int writes = transactions.getValue() * keysPerTransaction;
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Measured Duration", duration, Averaged::True);
|
|
|
|
m.emplace_back("Transactions/sec", transactions.getValue() / duration, Averaged::False);
|
|
|
|
m.emplace_back("Operations/sec", writes / duration, Averaged::False);
|
2019-05-17 04:54:06 +08:00
|
|
|
m.push_back(transactions.getMetric());
|
|
|
|
m.push_back(retries.getMetric());
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Mean load time (seconds)", loadTime, Averaged::True);
|
|
|
|
m.emplace_back("Write rows", writes, Averaged::False);
|
2019-05-17 04:54:06 +08:00
|
|
|
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Mean GRV Latency (ms)", 1000 * GRVLatencies.mean(), Averaged::True);
|
|
|
|
m.emplace_back("Median GRV Latency (ms, averaged)", 1000 * GRVLatencies.median(), Averaged::True);
|
|
|
|
m.emplace_back("90% GRV Latency (ms, averaged)", 1000 * GRVLatencies.percentile(0.90), Averaged::True);
|
|
|
|
m.emplace_back("98% GRV Latency (ms, averaged)", 1000 * GRVLatencies.percentile(0.98), Averaged::True);
|
2019-05-17 04:54:06 +08:00
|
|
|
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Mean Commit Latency (ms)", 1000 * commitLatencies.mean(), Averaged::True);
|
|
|
|
m.emplace_back("Median Commit Latency (ms, averaged)", 1000 * commitLatencies.median(), Averaged::True);
|
|
|
|
m.emplace_back("90% Commit Latency (ms, averaged)", 1000 * commitLatencies.percentile(0.90), Averaged::True);
|
|
|
|
m.emplace_back("98% Commit Latency (ms, averaged)", 1000 * commitLatencies.percentile(0.98), Averaged::True);
|
2019-05-17 04:54:06 +08:00
|
|
|
|
2021-08-30 06:38:21 +08:00
|
|
|
m.emplace_back("Write rows/sec", writes / duration, Averaged::False);
|
|
|
|
m.emplace_back("Bytes written/sec",
|
|
|
|
(writes * (keyBytes + (minValueBytes + maxValueBytes) * 0.5)) / duration,
|
|
|
|
Averaged::False);
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Value randomValue() {
|
|
|
|
return StringRef((uint8_t*)valueString.c_str(),
|
|
|
|
deterministicRandom()->randomInt(minValueBytes, maxValueBytes + 1));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
Standalone<KeyValueRef> operator()(uint64_t n) { return KeyValueRef(keyForIndex(n, false), randomValue()); }
|
|
|
|
|
|
|
|
ACTOR Future<Void> _setup(Database cx, WriteBandwidthWorkload* self) {
|
2017-05-26 04:48:44 +08:00
|
|
|
state Promise<double> loadTime;
|
2021-03-11 02:06:03 +08:00
|
|
|
state Promise<std::vector<std::pair<uint64_t, double>>> ratesAtKeyCounts;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(bulkSetup(cx, self, self->nodeCount, loadTime, true, self->warmingDelay, self->maxInsertRate));
|
2017-05-26 04:48:44 +08:00
|
|
|
self->loadTime = loadTime.getFuture().get();
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> _start(Database cx, WriteBandwidthWorkload* self) {
|
|
|
|
for (int i = 0; i < self->actorCount; i++) {
|
|
|
|
self->clients.push_back(self->writeClient(cx, self));
|
2017-05-26 04:48:44 +08:00
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(timeout(waitForAll(self->clients), self->testDuration, Void()));
|
2017-05-26 04:48:44 +08:00
|
|
|
self->clients.clear();
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
ACTOR Future<Void> writeClient(Database cx, WriteBandwidthWorkload* self) {
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
2021-03-11 02:06:03 +08:00
|
|
|
state Transaction tr(cx);
|
2019-05-11 05:01:52 +08:00
|
|
|
state uint64_t startIdx = deterministicRandom()->random01() * (self->nodeCount - self->keysPerTransaction);
|
2017-05-26 04:48:44 +08:00
|
|
|
loop {
|
|
|
|
try {
|
|
|
|
state double start = now();
|
2019-04-18 07:04:10 +08:00
|
|
|
wait(success(tr.getReadVersion()));
|
2021-03-11 02:06:03 +08:00
|
|
|
self->GRVLatencies.addSample(now() - start);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
// Predefine a single large write conflict range over the whole key space
|
2021-03-11 02:06:03 +08:00
|
|
|
tr.addWriteConflictRange(
|
|
|
|
KeyRangeRef(self->keyForIndex(startIdx, false),
|
|
|
|
keyAfter(self->keyForIndex(startIdx + self->keysPerTransaction - 1, false))));
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2021-03-11 02:06:03 +08:00
|
|
|
for (int i = 0; i < self->keysPerTransaction; i++)
|
2021-07-17 15:11:40 +08:00
|
|
|
tr.set(self->keyForIndex(startIdx + i, false), self->randomValue(), AddConflictRange::False);
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
start = now();
|
2021-03-11 02:06:03 +08:00
|
|
|
wait(tr.commit());
|
|
|
|
self->commitLatencies.addSample(now() - start);
|
2017-05-26 04:48:44 +08:00
|
|
|
break;
|
2021-03-11 02:06:03 +08:00
|
|
|
} catch (Error& e) {
|
|
|
|
wait(tr.onError(e));
|
2017-05-26 04:48:44 +08:00
|
|
|
++self->retries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++self->transactions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkloadFactory<WriteBandwidthWorkload> WriteBandwidthWorkloadFactory("WriteBandwidth");
|