diff --git a/ServerBench.cpp b/ServerBench.cpp index a75932f..1f57675 100644 --- a/ServerBench.cpp +++ b/ServerBench.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -19,31 +20,69 @@ #include #include "ConflictSet.h" +#include "Internal.h" #include "third_party/nadeau.h" std::atomic transactions; -constexpr int kWindowSize = 10000000; +int64_t safeUnaryMinus(int64_t x) { + return x == std::numeric_limits::min() ? x : -x; +} -constexpr int kNumPrefixes = 250000; +void tupleAppend(std::string &output, int64_t value) { + if (value == 0) { + output.push_back(0x14); + return; + } + uint32_t size = 8 - __builtin_clrsbll(value) / 8; + int typeCode = 0x14 + (value < 0 ? -1 : 1) * size; + output.push_back(typeCode); + if (value < 0) { + value = ~safeUnaryMinus(value); + } + uint64_t swap = __builtin_bswap64(value); + output.insert(output.end(), (uint8_t *)&swap + 8 - size, + (uint8_t *)&swap + 8); +} -std::string makeKey(int64_t num, int suffixLen) { +void tupleAppend(std::string &output, std::string_view value) { + output.push_back('\x02'); + for (auto c : value) { + if (c == '\x00') { + output.push_back('\x00'); + output.push_back('\xff'); + } else { + output.push_back(c); + } + } + output.push_back('\x00'); +} + +template std::string tupleKey(const Ts &...ts) { std::string result; - result.resize(sizeof(int64_t) + suffixLen); - int64_t be = __builtin_bswap64(num); - memcpy(result.data(), &be, sizeof(int64_t)); - memset(result.data() + sizeof(int64_t), 0, suffixLen); + (tupleAppend(result, ts), ...); return result; } +constexpr int kWindowSize = 300000; + void workload(weaselab::ConflictSet *cs) { int64_t version = kWindowSize; constexpr int kNumWrites = 16; for (;; transactions.fetch_add(1, std::memory_order_relaxed)) { + std::vector keyIndices; + for (int i = 0; i < kNumWrites; ++i) { + keyIndices.push_back(rand() % 100'000'000); + } + std::sort(keyIndices.begin(), keyIndices.end()); std::vector keys; std::vector writes; + constexpr std::string_view suffix = "this is a suffix"; for (int i = 0; i < kNumWrites; ++i) { - keys.push_back(makeKey(rand() % kNumPrefixes, rand() % 50)); + keys.push_back(tupleKey(0x100, i, keyIndices[i], + suffix.substr(0, rand() % suffix.size()), + rand())); + // printf("%s\n", printable(keys.back()).c_str()); } for (int i = 0; i < kNumWrites; ++i) { writes.push_back({{(const uint8_t *)keys[i].data(), int(keys[i].size())},