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 <netdb.h>
#include <stdio.h>
@@ -14,22 +15,57 @@
#include "ConflictSet.h"
#include "third_party/nadeau.h"
std::atomic<int64_t> transactions;
constexpr int kBaseSearchDepth = 32;
constexpr int kWindowSize = 10000000;
std::basic_string<uint8_t> numToKey(int64_t num) {
std::basic_string<uint8_t> result;
result.resize(kBaseSearchDepth + sizeof(int64_t));
memset(result.data(), 0, kBaseSearchDepth);
int64_t be = __builtin_bswap64(num);
memcpy(result.data() + kBaseSearchDepth, &be, sizeof(int64_t));
return result;
}
void workload(weaselab::ConflictSet *cs) {
int64_t version = 0;
constexpr int kWindowSize = 45e6;
for (;;) {
uint8_t buf[sizeof(version)];
int64_t be = __builtin_bswap64(version);
memcpy(buf, &be, sizeof(be));
weaselab::ConflictSet::WriteRange w;
w.begin.p = buf;
w.begin.len = sizeof(buf);
w.end.len = 0;
cs->addWrites(&w, 1, version);
++version;
if (version - kWindowSize >= 0) {
cs->setOldestVersion(version - kWindowSize);
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 ";
body += std::to_string(getCurrentRSS());
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) {
body += "# HELP ";