Add a simple point read/write workload to ServerBench

This commit is contained in:
2024-08-05 14:37:00 -07:00
parent c8be68db40
commit 2d3985ca40

View File

@@ -1,3 +1,4 @@
#include <atomic>
#include <errno.h> #include <errno.h>
#include <netdb.h> #include <netdb.h>
#include <stdio.h> #include <stdio.h>
@@ -14,22 +15,57 @@
#include "ConflictSet.h" #include "ConflictSet.h"
#include "third_party/nadeau.h" #include "third_party/nadeau.h"
void workload(weaselab::ConflictSet *cs) { std::atomic<int64_t> transactions;
int64_t version = 0;
constexpr int kWindowSize = 45e6; constexpr int kBaseSearchDepth = 32;
for (;;) { constexpr int kWindowSize = 10000000;
uint8_t buf[sizeof(version)];
int64_t be = __builtin_bswap64(version); std::basic_string<uint8_t> numToKey(int64_t num) {
memcpy(buf, &be, sizeof(be)); std::basic_string<uint8_t> result;
weaselab::ConflictSet::WriteRange w; result.resize(kBaseSearchDepth + sizeof(int64_t));
w.begin.p = buf; memset(result.data(), 0, kBaseSearchDepth);
w.begin.len = sizeof(buf); int64_t be = __builtin_bswap64(num);
w.end.len = 0; memcpy(result.data() + kBaseSearchDepth, &be, sizeof(int64_t));
cs->addWrites(&w, 1, version); return result;
++version;
if (version - kWindowSize >= 0) {
cs->setOldestVersion(version - kWindowSize);
} }
void workload(weaselab::ConflictSet *cs) {
int64_t version = kWindowSize;
for (;; transactions.fetch_add(1, std::memory_order_relaxed)) {
// Read
{
auto rv = version - kWindowSize + rand() % kWindowSize;
auto k = numToKey(rv);
weaselab::ConflictSet::ReadRange r;
r.begin.p = k.data();
r.begin.len = k.size();
r.end.len = 0;
r.readVersion = rv;
weaselab::ConflictSet::Result result;
cs->check(&r, &result, 1);
if (result != weaselab::ConflictSet::Commit) {
abort();
}
}
// Write
{
weaselab::ConflictSet::WriteRange w;
auto k = numToKey(version);
w.begin.p = k.data();
w.end.len = 0;
if (version % (kWindowSize / 2) == 0) {
for (int l = 0; l <= k.size(); ++l) {
w.begin.len = l;
cs->addWrites(&w, 1, version);
}
} else {
w.begin.len = k.size();
cs->addWrites(&w, 1, version);
}
}
// GC
cs->setOldestVersion(version - kWindowSize);
++version;
} }
} }
@@ -139,6 +175,11 @@ int main(int argc, char **argv) {
"process_resident_memory_bytes "; "process_resident_memory_bytes ";
body += std::to_string(getCurrentRSS()); body += std::to_string(getCurrentRSS());
body += "\n"; body += "\n";
body += "# HELP transactions_total Total number of transactions\n"
"# TYPE transactions_total counter\n"
"transactions_total ";
body += std::to_string(transactions.load(std::memory_order_relaxed));
body += "\n";
for (int i = 0; i < metricsCount; ++i) { for (int i = 0; i < metricsCount; ++i) {
body += "# HELP "; body += "# HELP ";