foundationdb/fdbserver/workloads/IndexScan.actor.cpp

148 lines
4.9 KiB
C++
Raw Normal View History

2017-05-26 04:48:44 +08:00
/*
* IndexScan.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"
#include "fdbserver/workloads/workloads.actor.h"
#include "fdbserver/workloads/BulkSetup.actor.h"
2017-05-26 04:48:44 +08:00
#include "fdbclient/ReadYourWrites.h"
#include "flow/actorcompiler.h" // This must be the last #include.
2017-05-26 04:48:44 +08:00
struct IndexScanWorkload : KVWorkload {
uint64_t rowsRead, chunks;
int bytesPerRead, failedTransactions, scans;
double totalTimeFetching, testDuration, transactionDuration;
bool singleProcess, readYourWrites;
IndexScanWorkload(WorkloadContext const& wcx)
2021-07-23 13:48:27 +08:00
: KVWorkload(wcx), rowsRead(0), chunks(0), failedTransactions(0), scans(0) {
testDuration = getOption(options, LiteralStringRef("testDuration"), 10.0);
bytesPerRead = getOption(options, LiteralStringRef("bytesPerRead"), 80000);
transactionDuration = getOption(options, LiteralStringRef("transactionDuration"), 1.0);
singleProcess = getOption(options, LiteralStringRef("singleProcess"), true);
readYourWrites = getOption(options, LiteralStringRef("readYourWrites"), true);
2017-05-26 04:48:44 +08:00
}
2020-10-05 13:29:07 +08:00
std::string description() const override { return "SimpleRead"; }
2017-05-26 04:48:44 +08:00
2020-10-05 13:29:07 +08:00
Future<Void> setup(Database const& cx) override {
2017-05-26 04:48:44 +08:00
// this will be set up by and external force!
return Void();
}
2020-10-05 13:29:07 +08:00
Future<Void> start(Database const& cx) override {
if (singleProcess && clientId != 0) {
2017-05-26 04:48:44 +08:00
return Void();
}
return _start(cx, this);
2017-05-26 04:48:44 +08:00
}
2020-10-05 13:29:07 +08:00
Future<bool> check(const Database&) 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 {
if (singleProcess && clientId != 0)
2017-05-26 04:48:44 +08:00
return;
m.push_back(PerfMetric("FailedTransactions", failedTransactions, false));
m.push_back(PerfMetric("RowsRead", rowsRead, false));
m.push_back(PerfMetric("Scans", scans, false));
m.push_back(PerfMetric("Chunks", chunks, false));
m.push_back(PerfMetric("TimeFetching", totalTimeFetching, true));
m.push_back(PerfMetric("Rows/sec", totalTimeFetching == 0 ? 0 : rowsRead / totalTimeFetching, true));
m.push_back(PerfMetric("Rows/chunk", chunks == 0 ? 0 : rowsRead / (double)chunks, true));
2017-05-26 04:48:44 +08:00
}
ACTOR Future<Void> _start(Database cx, IndexScanWorkload* self) {
2017-05-26 04:48:44 +08:00
// Boilerplate: "warm" the location cache so that the location of all keys is known before test starts
state double startTime = now();
loop {
state Transaction tr(cx);
try {
wait(tr.warmRange(cx, allKeys));
2017-05-26 04:48:44 +08:00
break;
} catch (Error& e) {
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
// Wait some small amount of time for things to "settle". Maybe this is historical?
wait(delay(std::max(0.1, 1.0 - (now() - startTime))));
2017-05-26 04:48:44 +08:00
wait(timeout(serialScans(cx, self), self->testDuration, Void()));
2017-05-26 04:48:44 +08:00
return Void();
}
ACTOR static Future<Void> serialScans(Database cx, IndexScanWorkload* self) {
2017-05-26 04:48:44 +08:00
state double start = now();
try {
loop { wait(scanDatabase(cx, self)); }
} catch (...) {
2017-05-26 04:48:44 +08:00
self->totalTimeFetching = now() - start;
throw;
}
}
ACTOR static Future<Void> scanDatabase(Database cx, IndexScanWorkload* self) {
state int startNode =
deterministicRandom()->randomInt(0, self->nodeCount / 2); // start in the first half of the database
state KeySelector begin = firstGreaterOrEqual(self->keyForIndex(startNode));
state KeySelector end = firstGreaterThan(self->keyForIndex(self->nodeCount));
state GetRangeLimits limits(GetRangeLimits::ROW_LIMIT_UNLIMITED, self->bytesPerRead);
2017-05-26 04:48:44 +08:00
state int rowsRead;
state int chunks;
state double startTime;
loop {
state ReadYourWritesTransaction tr(cx);
if (!self->readYourWrites)
tr.setOption(FDBTransactionOptions::READ_YOUR_WRITES_DISABLE);
2017-05-26 04:48:44 +08:00
startTime = now();
rowsRead = 0;
chunks = 0;
try {
loop {
2021-05-04 04:14:16 +08:00
RangeResult r = wait(tr.getRange(begin, end, limits));
2017-05-26 04:48:44 +08:00
chunks++;
rowsRead += r.size();
if (!r.size() || !r.more || (now() - startTime) > self->transactionDuration) {
2017-05-26 04:48:44 +08:00
break;
}
begin = firstGreaterThan(r[r.size() - 1].key);
2017-05-26 04:48:44 +08:00
}
break;
} catch (Error& e) {
if (e.code() != error_code_actor_cancelled)
2017-05-26 04:48:44 +08:00
++self->failedTransactions;
wait(tr.onError(e));
2017-05-26 04:48:44 +08:00
}
}
self->rowsRead += rowsRead;
self->chunks += chunks;
self->scans++;
return Void();
}
};
WorkloadFactory<IndexScanWorkload> IndexScanWorkloadFactory("IndexScan");