Add a simple point read/write workload to ServerBench
This commit is contained in:
@@ -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"
|
||||||
|
|
||||||
|
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) {
|
void workload(weaselab::ConflictSet *cs) {
|
||||||
int64_t version = 0;
|
int64_t version = kWindowSize;
|
||||||
constexpr int kWindowSize = 45e6;
|
for (;; transactions.fetch_add(1, std::memory_order_relaxed)) {
|
||||||
for (;;) {
|
// Read
|
||||||
uint8_t buf[sizeof(version)];
|
{
|
||||||
int64_t be = __builtin_bswap64(version);
|
auto rv = version - kWindowSize + rand() % kWindowSize;
|
||||||
memcpy(buf, &be, sizeof(be));
|
auto k = numToKey(rv);
|
||||||
weaselab::ConflictSet::WriteRange w;
|
weaselab::ConflictSet::ReadRange r;
|
||||||
w.begin.p = buf;
|
r.begin.p = k.data();
|
||||||
w.begin.len = sizeof(buf);
|
r.begin.len = k.size();
|
||||||
w.end.len = 0;
|
r.end.len = 0;
|
||||||
cs->addWrites(&w, 1, version);
|
r.readVersion = rv;
|
||||||
++version;
|
weaselab::ConflictSet::Result result;
|
||||||
if (version - kWindowSize >= 0) {
|
cs->check(&r, &result, 1);
|
||||||
cs->setOldestVersion(version - kWindowSize);
|
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 ";
|
||||||
|
Reference in New Issue
Block a user