Compare commits
29 Commits
5e06a30357
...
erase-betw
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a132799a4 | |||
| 72469ebb6e | |||
| 6c79847a42 | |||
| 405a2ca161 | |||
| f93466316a | |||
| 5626cd09d9 | |||
| 41840220c3 | |||
| 7ff00e7846 | |||
| 6242f40d48 | |||
| 403d70a1d3 | |||
| 9763452713 | |||
| 73d0593fca | |||
| 23c2a3e1c6 | |||
| a64e792964 | |||
| 5e362d5330 | |||
| cc526cb6ba | |||
| 7e49888bec | |||
| e64ebabced | |||
| 1e34951a77 | |||
| baf64520d6 | |||
| 3499626127 | |||
| b7f9084694 | |||
| 4b82502946 | |||
| 68bbacb69a | |||
| 3078845673 | |||
| 43f6126cc4 | |||
| b911d87d55 | |||
| 0c65a82b78 | |||
| e024cb8291 |
16
Bench.cpp
16
Bench.cpp
@@ -361,7 +361,21 @@ void benchWorstCaseForRadixRangeRead() {
|
|||||||
void benchCreateAndDestroy() {
|
void benchCreateAndDestroy() {
|
||||||
ankerl::nanobench::Bench bench;
|
ankerl::nanobench::Bench bench;
|
||||||
|
|
||||||
bench.run("create and destroy", [&]() { ConflictSet cs{0}; });
|
bench.run("create and destroy", [&]() {
|
||||||
|
ConflictSet cs{0};
|
||||||
|
ConflictSet::WriteRange w;
|
||||||
|
uint8_t b[9];
|
||||||
|
b[8] = 0;
|
||||||
|
for (int64_t i = 0; i < 1000; i += 7) {
|
||||||
|
auto x = __builtin_bswap64(i);
|
||||||
|
memcpy(b, &x, 8);
|
||||||
|
w.begin.p = b;
|
||||||
|
w.begin.len = 8;
|
||||||
|
w.end.len = 0;
|
||||||
|
w.end.p = b;
|
||||||
|
cs.addWrites(&w, 1, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.18)
|
cmake_minimum_required(VERSION 3.18)
|
||||||
project(
|
project(
|
||||||
conflict-set
|
conflict-set
|
||||||
VERSION 0.0.14
|
VERSION 0.0.12
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
"A data structure for optimistic concurrency control on ranges of bitwise-lexicographically-ordered keys."
|
"A data structure for optimistic concurrency control on ranges of bitwise-lexicographically-ordered keys."
|
||||||
HOMEPAGE_URL "https://git.weaselab.dev/weaselab/conflict-set"
|
HOMEPAGE_URL "https://git.weaselab.dev/weaselab/conflict-set"
|
||||||
@@ -276,15 +276,9 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND BUILD_TESTING)
|
|||||||
|
|
||||||
find_program(VALGRIND_EXE valgrind)
|
find_program(VALGRIND_EXE valgrind)
|
||||||
if(VALGRIND_EXE AND NOT CMAKE_CROSSCOMPILING)
|
if(VALGRIND_EXE AND NOT CMAKE_CROSSCOMPILING)
|
||||||
list(LENGTH CORPUS_TESTS len)
|
add_test(NAME conflict_set_blackbox_valgrind
|
||||||
math(EXPR last "${len} - 1")
|
COMMAND ${VALGRIND_EXE} --error-exitcode=99 --
|
||||||
set(partition_size 100)
|
$<TARGET_FILE:driver> ${CORPUS_TESTS})
|
||||||
foreach(i RANGE 0 ${last} ${partition_size})
|
|
||||||
list(SUBLIST CORPUS_TESTS ${i} ${partition_size} partition)
|
|
||||||
add_test(NAME conflict_set_blackbox_valgrind_${i}
|
|
||||||
COMMAND ${VALGRIND_EXE} --error-exitcode=99 --
|
|
||||||
$<TARGET_FILE:driver> ${partition})
|
|
||||||
endforeach()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# api smoke tests
|
# api smoke tests
|
||||||
|
|||||||
1359
ConflictSet.cpp
1359
ConflictSet.cpp
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ using namespace weaselab;
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <callgrind.h>
|
#include <callgrind.h>
|
||||||
|
|
||||||
@@ -747,10 +748,7 @@ struct TestDriver {
|
|||||||
fprintf(stderr, "%p Set oldest version: %" PRId64 "\n", this,
|
fprintf(stderr, "%p Set oldest version: %" PRId64 "\n", this,
|
||||||
oldestVersion);
|
oldestVersion);
|
||||||
#endif
|
#endif
|
||||||
CALLGRIND_START_INSTRUMENTATION;
|
|
||||||
cs.setOldestVersion(oldestVersion);
|
cs.setOldestVersion(oldestVersion);
|
||||||
CALLGRIND_STOP_INSTRUMENTATION;
|
|
||||||
|
|
||||||
if constexpr (kEnableAssertions) {
|
if constexpr (kEnableAssertions) {
|
||||||
refImpl.setOldestVersion(oldestVersion);
|
refImpl.setOldestVersion(oldestVersion);
|
||||||
}
|
}
|
||||||
|
|||||||
11
Jenkinsfile
vendored
11
Jenkinsfile
vendored
@@ -48,17 +48,6 @@ pipeline {
|
|||||||
recordIssues(tools: [clang()])
|
recordIssues(tools: [clang()])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('64 bit versions') {
|
|
||||||
agent {
|
|
||||||
dockerfile {
|
|
||||||
args '-v /home/jenkins/ccache:/ccache'
|
|
||||||
reuseNode true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
CleanBuildAndTest("-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Debug') {
|
stage('Debug') {
|
||||||
agent {
|
agent {
|
||||||
dockerfile {
|
dockerfile {
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -24,15 +24,16 @@ Hardware for all benchmarks is an AMD Ryzen 9 7900 with (2x32GB) 5600MT/s CL28-3
|
|||||||
|
|
||||||
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|
| ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark
|
||||||
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|
||||||
| 11.18 | 89,455,125.34 | 0.6% | 185.37 | 57.08 | 3.248 | 41.51 | 0.4% | 0.01 | `point reads`
|
| 10.80 | 92,600,541.52 | 0.6% | 180.38 | 54.49 | 3.310 | 41.51 | 0.4% | 0.01 | `point reads`
|
||||||
| 14.53 | 68,800,688.89 | 0.4% | 282.41 | 74.80 | 3.776 | 55.06 | 0.3% | 0.01 | `prefix reads`
|
| 15.00 | 66,687,691.68 | 0.4% | 278.44 | 76.44 | 3.642 | 55.56 | 0.3% | 0.01 | `prefix reads`
|
||||||
| 36.54 | 27,367,576.87 | 0.2% | 798.06 | 188.90 | 4.225 | 141.69 | 0.2% | 0.01 | `range reads`
|
| 36.81 | 27,163,394.61 | 0.4% | 795.06 | 187.91 | 4.231 | 142.67 | 0.2% | 0.01 | `range reads`
|
||||||
| 16.69 | 59,912,106.02 | 0.6% | 314.57 | 86.29 | 3.645 | 39.84 | 0.4% | 0.01 | `point writes`
|
| 18.14 | 55,137,674.01 | 1.2% | 338.19 | 92.86 | 3.642 | 42.81 | 0.4% | 0.01 | `point writes`
|
||||||
| 30.09 | 33,235,744.07 | 0.5% | 591.33 | 155.92 | 3.793 | 82.69 | 0.2% | 0.01 | `prefix writes`
|
| 33.19 | 30,127,119.71 | 0.1% | 681.03 | 170.05 | 4.005 | 98.68 | 0.2% | 0.01 | `prefix writes`
|
||||||
| 35.77 | 27,956,388.03 | 1.4% | 682.25 | 187.63 | 3.636 | 96.12 | 0.1% | 0.01 | `range writes`
|
| 37.37 | 26,759,432.70 | 1.9% | 779.70 | 195.45 | 3.989 | 114.21 | 0.0% | 0.01 | `range writes`
|
||||||
| 74.04 | 13,505,408.41 | 2.7% | 1,448.95 | 392.10 | 3.695 | 260.53 | 0.1% | 0.01 | `monotonic increasing point writes`
|
| 74.36 | 13,448,582.47 | 1.9% | 1,425.68 | 389.08 | 3.664 | 258.88 | 0.1% | 0.01 | `monotonic increasing point writes`
|
||||||
| 330,984.50 | 3,021.29 | 1.9% | 3,994,153.50 | 1,667,309.00 | 2.396 | 806,019.50 | 0.0% | 0.01 | `worst case for radix tree`
|
| 316,928.00 | 3,155.29 | 1.5% | 3,992,986.00 | 1,699,813.00 | 2.349 | 806,226.50 | 0.0% | 0.01 | `worst case for radix tree`
|
||||||
| 92.46 | 10,814,961.65 | 0.5% | 1,800.00 | 463.41 | 3.884 | 297.00 | 0.0% | 0.01 | `create and destroy`
|
| 75.26 | 13,286,517.16 | 0.5% | 1,590.01 | 386.67 | 4.112 | 258.00 | 0.0% | 0.01 | `create and destroy`
|
||||||
|
|
||||||
|
|
||||||
# "Real data" test
|
# "Real data" test
|
||||||
|
|
||||||
@@ -47,7 +48,7 @@ Check: 4.47891 seconds, 364.05 MB/s, Add: 4.55599 seconds, 123.058 MB/s, Gc rati
|
|||||||
## radix tree
|
## radix tree
|
||||||
|
|
||||||
```
|
```
|
||||||
Check: 0.953012 seconds, 1710.94 MB/s, Add: 1.30025 seconds, 431.188 MB/s, Gc ratio: 43.9816%, Peak idle memory: 2.28375e+06
|
Check: 0.910234 seconds, 1791.35 MB/s, Add: 1.25908 seconds, 445.287 MB/s, Gc ratio: 44.0415%
|
||||||
```
|
```
|
||||||
|
|
||||||
## hash table
|
## hash table
|
||||||
|
|||||||
125
ServerBench.cpp
125
ServerBench.cpp
@@ -6,15 +6,11 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <utility>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "ConflictSet.h"
|
#include "ConflictSet.h"
|
||||||
#include "third_party/nadeau.h"
|
#include "third_party/nadeau.h"
|
||||||
@@ -24,8 +20,8 @@ std::atomic<int64_t> transactions;
|
|||||||
constexpr int kBaseSearchDepth = 32;
|
constexpr int kBaseSearchDepth = 32;
|
||||||
constexpr int kWindowSize = 10000000;
|
constexpr int kWindowSize = 10000000;
|
||||||
|
|
||||||
std::string numToKey(int64_t num) {
|
std::basic_string<uint8_t> numToKey(int64_t num) {
|
||||||
std::string result;
|
std::basic_string<uint8_t> result;
|
||||||
result.resize(kBaseSearchDepth + sizeof(int64_t));
|
result.resize(kBaseSearchDepth + sizeof(int64_t));
|
||||||
memset(result.data(), 0, kBaseSearchDepth);
|
memset(result.data(), 0, kBaseSearchDepth);
|
||||||
int64_t be = __builtin_bswap64(num);
|
int64_t be = __builtin_bswap64(num);
|
||||||
@@ -45,13 +41,13 @@ void workload(weaselab::ConflictSet *cs) {
|
|||||||
auto pointK = numToKey(pointRv);
|
auto pointK = numToKey(pointRv);
|
||||||
weaselab::ConflictSet::ReadRange reads[] = {
|
weaselab::ConflictSet::ReadRange reads[] = {
|
||||||
{
|
{
|
||||||
{(const uint8_t *)pointK.data(), int(pointK.size())},
|
{pointK.data(), int(pointK.size())},
|
||||||
{nullptr, 0},
|
{nullptr, 0},
|
||||||
pointRv,
|
pointRv,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{(const uint8_t *)beginK.data(), int(beginK.size())},
|
{beginK.data(), int(beginK.size())},
|
||||||
{(const uint8_t *)endK.data(), int(endK.size())},
|
{endK.data(), int(endK.size())},
|
||||||
version - 2,
|
version - 2,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -70,7 +66,7 @@ void workload(weaselab::ConflictSet *cs) {
|
|||||||
{
|
{
|
||||||
weaselab::ConflictSet::WriteRange w;
|
weaselab::ConflictSet::WriteRange w;
|
||||||
auto k = numToKey(version);
|
auto k = numToKey(version);
|
||||||
w.begin.p = (const uint8_t *)k.data();
|
w.begin.p = k.data();
|
||||||
w.end.len = 0;
|
w.end.len = 0;
|
||||||
if (version % (kWindowSize / 2) == 0) {
|
if (version % (kWindowSize / 2) == 0) {
|
||||||
for (int l = 0; l <= k.size(); ++l) {
|
for (int l = 0; l <= k.size(); ++l) {
|
||||||
@@ -83,9 +79,9 @@ void workload(weaselab::ConflictSet *cs) {
|
|||||||
int64_t beginN = version - kWindowSize + rand() % kWindowSize;
|
int64_t beginN = version - kWindowSize + rand() % kWindowSize;
|
||||||
auto b = numToKey(beginN);
|
auto b = numToKey(beginN);
|
||||||
auto e = numToKey(beginN + 1000);
|
auto e = numToKey(beginN + 1000);
|
||||||
w.begin.p = (const uint8_t *)b.data();
|
w.begin.p = b.data();
|
||||||
w.begin.len = b.size();
|
w.begin.len = b.size();
|
||||||
w.end.p = (const uint8_t *)e.data();
|
w.end.p = e.data();
|
||||||
w.end.len = e.size();
|
w.end.len = e.size();
|
||||||
cs->addWrites(&w, 1, version);
|
cs->addWrites(&w, 1, version);
|
||||||
}
|
}
|
||||||
@@ -168,29 +164,36 @@ double toSeconds(timeval t) {
|
|||||||
return double(t.tv_sec) + double(t.tv_usec) * 1e-6;
|
return double(t.tv_sec) + double(t.tv_usec) * 1e-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
#include <linux/perf_event.h>
|
#include <linux/perf_event.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/syscall.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
struct PerfCounter {
|
struct PerfCounter {
|
||||||
PerfCounter(int type, int config, const std::string &labels = {},
|
explicit PerfCounter(int event) {
|
||||||
int groupLeaderFd = -1)
|
|
||||||
: labels(labels) {
|
|
||||||
struct perf_event_attr pe;
|
struct perf_event_attr pe;
|
||||||
|
|
||||||
memset(&pe, 0, sizeof(pe));
|
memset(&pe, 0, sizeof(pe));
|
||||||
pe.type = type;
|
pe.type = PERF_TYPE_HARDWARE;
|
||||||
pe.size = sizeof(pe);
|
pe.size = sizeof(pe);
|
||||||
pe.config = config;
|
pe.config = event;
|
||||||
pe.inherit = 1;
|
pe.inherit = 1;
|
||||||
pe.exclude_kernel = 1;
|
pe.exclude_kernel = 1;
|
||||||
pe.exclude_hv = 1;
|
pe.exclude_hv = 1;
|
||||||
|
|
||||||
fd = perf_event_open(&pe, 0, -1, groupLeaderFd, 0);
|
fd = perf_event_open(&pe, 0, -1, -1, 0);
|
||||||
if (fd < 0 && errno != ENOENT && errno != EINVAL) {
|
if (fd == -1) {
|
||||||
perror(labels.c_str());
|
fprintf(stderr, "Error opening leader %llx\n", pe.config);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t total() const {
|
int64_t total() {
|
||||||
int64_t count;
|
int64_t count;
|
||||||
if (read(fd, &count, sizeof(count)) != sizeof(count)) {
|
if (read(fd, &count, sizeof(count)) != sizeof(count)) {
|
||||||
perror("read instructions from perf");
|
perror("read instructions from perf");
|
||||||
@@ -199,27 +202,10 @@ struct PerfCounter {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfCounter(PerfCounter &&other)
|
~PerfCounter() { close(fd); }
|
||||||
: fd(std::exchange(other.fd, -1)), labels(std::move(other.labels)) {}
|
|
||||||
PerfCounter &operator=(PerfCounter &&other) {
|
|
||||||
fd = std::exchange(other.fd, -1);
|
|
||||||
labels = std::move(other.labels);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~PerfCounter() {
|
|
||||||
if (fd >= 0) {
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok() const { return fd >= 0; }
|
|
||||||
const std::string &getLabels() const { return labels; }
|
|
||||||
int getFd() const { return fd; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int fd;
|
int fd;
|
||||||
std::string labels;
|
|
||||||
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
|
static long perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
|
||||||
int cpu, int group_fd, unsigned long flags) {
|
int cpu, int group_fd, unsigned long flags) {
|
||||||
int ret;
|
int ret;
|
||||||
@@ -228,6 +214,11 @@ private:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#else
|
||||||
|
struct PerfCounter {
|
||||||
|
explicit PerPerfCounter(int) {}
|
||||||
|
int64_t total() { return 0; }
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
@@ -242,50 +233,8 @@ int main(int argc, char **argv) {
|
|||||||
int metricsCount;
|
int metricsCount;
|
||||||
cs.getMetricsV1(&metrics, &metricsCount);
|
cs.getMetricsV1(&metrics, &metricsCount);
|
||||||
|
|
||||||
#ifdef __linux__
|
PerfCounter instructions{PERF_COUNT_HW_INSTRUCTIONS};
|
||||||
PerfCounter instructions{PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS};
|
PerfCounter cycles{PERF_COUNT_HW_CPU_CYCLES};
|
||||||
PerfCounter cycles{PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, "",
|
|
||||||
instructions.getFd()};
|
|
||||||
|
|
||||||
std::vector<PerfCounter> cacheCounters;
|
|
||||||
for (auto [id, idStr] : std::initializer_list<std::pair<int, std::string>>{
|
|
||||||
{PERF_COUNT_HW_CACHE_L1D, "l1d"},
|
|
||||||
{PERF_COUNT_HW_CACHE_L1I, "l1i"},
|
|
||||||
{PERF_COUNT_HW_CACHE_LL, "ll"},
|
|
||||||
{PERF_COUNT_HW_CACHE_DTLB, "dtlb"},
|
|
||||||
{PERF_COUNT_HW_CACHE_ITLB, "itlb"},
|
|
||||||
{PERF_COUNT_HW_CACHE_BPU, "bpu"},
|
|
||||||
{PERF_COUNT_HW_CACHE_NODE, "node"},
|
|
||||||
}) {
|
|
||||||
for (auto [op, opStr] :
|
|
||||||
std::initializer_list<std::pair<int, std::string>>{
|
|
||||||
{PERF_COUNT_HW_CACHE_OP_READ, "read"},
|
|
||||||
{PERF_COUNT_HW_CACHE_OP_WRITE, "write"},
|
|
||||||
{PERF_COUNT_HW_CACHE_OP_PREFETCH, "prefetch"},
|
|
||||||
}) {
|
|
||||||
int groupLeaderFd = -1;
|
|
||||||
for (auto [result, resultStr] :
|
|
||||||
std::initializer_list<std::pair<int, std::string>>{
|
|
||||||
{PERF_COUNT_HW_CACHE_RESULT_MISS, "miss"},
|
|
||||||
{PERF_COUNT_HW_CACHE_RESULT_ACCESS, "access"},
|
|
||||||
}) {
|
|
||||||
auto labels = "{id=\"" + idStr + "\", op=\"" + opStr +
|
|
||||||
"\", result=\"" + resultStr + "\"}";
|
|
||||||
cacheCounters.emplace_back(PERF_TYPE_HW_CACHE,
|
|
||||||
id | (op << 8) | (result << 16), labels,
|
|
||||||
groupLeaderFd);
|
|
||||||
if (!cacheCounters.back().ok()) {
|
|
||||||
cacheCounters.pop_back();
|
|
||||||
} else {
|
|
||||||
if (groupLeaderFd == -1) {
|
|
||||||
groupLeaderFd = cacheCounters.back().getFd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
auto w = std::thread{workload, &cs};
|
auto w = std::thread{workload, &cs};
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -313,7 +262,6 @@ int main(int argc, char **argv) {
|
|||||||
"transactions_total ";
|
"transactions_total ";
|
||||||
body += std::to_string(transactions.load(std::memory_order_relaxed));
|
body += std::to_string(transactions.load(std::memory_order_relaxed));
|
||||||
body += "\n";
|
body += "\n";
|
||||||
#ifdef __linux__
|
|
||||||
body += "# HELP instructions_total Total number of instructions\n"
|
body += "# HELP instructions_total Total number of instructions\n"
|
||||||
"# TYPE instructions_total counter\n"
|
"# TYPE instructions_total counter\n"
|
||||||
"instructions_total ";
|
"instructions_total ";
|
||||||
@@ -324,13 +272,6 @@ int main(int argc, char **argv) {
|
|||||||
"cycles_total ";
|
"cycles_total ";
|
||||||
body += std::to_string(cycles.total());
|
body += std::to_string(cycles.total());
|
||||||
body += "\n";
|
body += "\n";
|
||||||
body += "# HELP cache_event_total Total number of cache events\n"
|
|
||||||
"# TYPE cache_event_total counter\n";
|
|
||||||
for (const auto &counter : cacheCounters) {
|
|
||||||
body += "cache_event_total" + counter.getLabels() + " " +
|
|
||||||
std::to_string(counter.total()) + "\n";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = 0; i < metricsCount; ++i) {
|
for (int i = 0; i < metricsCount; ++i) {
|
||||||
body += "# HELP ";
|
body += "# HELP ";
|
||||||
|
|||||||
81
SkipList.cpp
81
SkipList.cpp
@@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
|
std::span<const uint8_t> keyAfter(Arena &arena, std::span<const uint8_t> key) {
|
||||||
auto result =
|
auto result =
|
||||||
@@ -116,6 +115,15 @@ bool operator==(const KeyInfo &lhs, const KeyInfo &rhs) {
|
|||||||
return !(lhs < rhs || rhs < lhs);
|
return !(lhs < rhs || rhs < lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void swapSort(std::vector<KeyInfo> &points, int a, int b) {
|
||||||
|
if (points[b] < points[a]) {
|
||||||
|
KeyInfo temp;
|
||||||
|
temp = points[a];
|
||||||
|
points[a] = points[b];
|
||||||
|
points[b] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct SortTask {
|
struct SortTask {
|
||||||
int begin;
|
int begin;
|
||||||
int size;
|
int size;
|
||||||
@@ -175,6 +183,13 @@ void sortPoints(std::vector<KeyInfo> &points) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static thread_local uint32_t g_seed = 0;
|
||||||
|
|
||||||
|
static inline int skfastrand() {
|
||||||
|
g_seed = g_seed * 1664525L + 1013904223L;
|
||||||
|
return g_seed;
|
||||||
|
}
|
||||||
|
|
||||||
static int compare(const StringRef &a, const StringRef &b) {
|
static int compare(const StringRef &a, const StringRef &b) {
|
||||||
int c = memcmp(a.data(), b.data(), std::min(a.size(), b.size()));
|
int c = memcmp(a.data(), b.data(), std::min(a.size(), b.size()));
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
@@ -200,24 +215,20 @@ struct ReadConflictRange {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int MaxLevels = 26;
|
|
||||||
|
|
||||||
struct RandomLevel {
|
|
||||||
explicit RandomLevel(uint32_t seed) : seed(seed) {}
|
|
||||||
|
|
||||||
int next() {
|
|
||||||
int result = __builtin_clz(seed | (uint32_t(-1) >> (MaxLevels - 1)));
|
|
||||||
seed = seed * 1664525L + 1013904223L;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t seed;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SkipList {
|
class SkipList {
|
||||||
private:
|
private:
|
||||||
RandomLevel randomLevel{0};
|
static constexpr int MaxLevels = 26;
|
||||||
|
|
||||||
|
int randomLevel() const {
|
||||||
|
uint32_t i = uint32_t(skfastrand()) >> (32 - (MaxLevels - 1));
|
||||||
|
int level = 0;
|
||||||
|
while (i & 1) {
|
||||||
|
i >>= 1;
|
||||||
|
level++;
|
||||||
|
}
|
||||||
|
assert(level < MaxLevels);
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
// Represent a node in the SkipList. The node has multiple (i.e., level)
|
// Represent a node in the SkipList. The node has multiple (i.e., level)
|
||||||
// pointers to other nodes, and keeps a record of the max versions for each
|
// pointers to other nodes, and keeps a record of the max versions for each
|
||||||
@@ -415,23 +426,18 @@ public:
|
|||||||
}
|
}
|
||||||
void swap(SkipList &other) { std::swap(header, other.header); }
|
void swap(SkipList &other) { std::swap(header, other.header); }
|
||||||
|
|
||||||
// Returns the change in the number of entries
|
void addConflictRanges(const Finger *fingers, int rangeCount,
|
||||||
int64_t addConflictRanges(const Finger *fingers, int rangeCount,
|
Version version) {
|
||||||
Version version) {
|
|
||||||
int64_t result = rangeCount;
|
|
||||||
for (int r = rangeCount - 1; r >= 0; r--) {
|
for (int r = rangeCount - 1; r >= 0; r--) {
|
||||||
const Finger &startF = fingers[r * 2];
|
const Finger &startF = fingers[r * 2];
|
||||||
const Finger &endF = fingers[r * 2 + 1];
|
const Finger &endF = fingers[r * 2 + 1];
|
||||||
|
|
||||||
if (endF.found() == nullptr) {
|
if (endF.found() == nullptr)
|
||||||
++result;
|
|
||||||
insert(endF, endF.finger[0]->getMaxVersion(0));
|
insert(endF, endF.finger[0]->getMaxVersion(0));
|
||||||
}
|
|
||||||
|
|
||||||
result -= remove(startF, endF);
|
remove(startF, endF);
|
||||||
insert(startF, version);
|
insert(startF, version);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void detectConflicts(ReadConflictRange *ranges, int count,
|
void detectConflicts(ReadConflictRange *ranges, int count,
|
||||||
@@ -561,10 +567,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Returns the number of entries removed
|
void remove(const Finger &start, const Finger &end) {
|
||||||
int64_t remove(const Finger &start, const Finger &end) {
|
|
||||||
if (start.finger[0] == end.finger[0])
|
if (start.finger[0] == end.finger[0])
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
Node *x = start.finger[0]->getNext(0);
|
Node *x = start.finger[0]->getNext(0);
|
||||||
|
|
||||||
@@ -573,20 +578,17 @@ private:
|
|||||||
if (start.finger[i] != end.finger[i])
|
if (start.finger[i] != end.finger[i])
|
||||||
start.finger[i]->setNext(i, end.finger[i]->getNext(i));
|
start.finger[i]->setNext(i, end.finger[i]->getNext(i));
|
||||||
|
|
||||||
int64_t result = 0;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Node *next = x->getNext(0);
|
Node *next = x->getNext(0);
|
||||||
x->destroy();
|
x->destroy();
|
||||||
++result;
|
|
||||||
if (x == end.finger[0])
|
if (x == end.finger[0])
|
||||||
break;
|
break;
|
||||||
x = next;
|
x = next;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(const Finger &f, Version version) {
|
void insert(const Finger &f, Version version) {
|
||||||
int level = randomLevel.next();
|
int level = randomLevel();
|
||||||
// std::cout << std::string((const char*)value,length) << " level: " <<
|
// std::cout << std::string((const char*)value,length) << " level: " <<
|
||||||
// level << std::endl;
|
// level << std::endl;
|
||||||
Node *x = Node::create(f.value, level);
|
Node *x = Node::create(f.value, level);
|
||||||
@@ -702,6 +704,8 @@ private:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SkipListConflictSet {};
|
||||||
|
|
||||||
struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
||||||
Impl(int64_t oldestVersion)
|
Impl(int64_t oldestVersion)
|
||||||
: oldestVersion(oldestVersion), newestVersion(oldestVersion),
|
: oldestVersion(oldestVersion), newestVersion(oldestVersion),
|
||||||
@@ -771,20 +775,17 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
|||||||
StringRef values[stripeSize];
|
StringRef values[stripeSize];
|
||||||
int64_t writeVersions[stripeSize / 2];
|
int64_t writeVersions[stripeSize / 2];
|
||||||
int ss = stringCount - (stripes - 1) * stripeSize;
|
int ss = stringCount - (stripes - 1) * stripeSize;
|
||||||
int64_t entryDelta = 0;
|
|
||||||
for (int s = stripes - 1; s >= 0; s--) {
|
for (int s = stripes - 1; s >= 0; s--) {
|
||||||
for (int i = 0; i * 2 < ss; ++i) {
|
for (int i = 0; i * 2 < ss; ++i) {
|
||||||
const auto &w = combinedWriteConflictRanges[s * stripeSize / 2 + i];
|
const auto &w = combinedWriteConflictRanges[s * stripeSize / 2 + i];
|
||||||
values[i * 2] = w.first;
|
values[i * 2] = w.first;
|
||||||
values[i * 2 + 1] = w.second;
|
values[i * 2 + 1] = w.second;
|
||||||
|
keyUpdates += 3;
|
||||||
}
|
}
|
||||||
skipList.find(values, fingers, temp, ss);
|
skipList.find(values, fingers, temp, ss);
|
||||||
entryDelta += skipList.addConflictRanges(fingers, ss / 2, writeVersion);
|
skipList.addConflictRanges(fingers, ss / 2, writeVersion);
|
||||||
ss = stripeSize;
|
ss = stripeSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run gc at least 200% the rate we're inserting entries
|
|
||||||
keyUpdates += std::max<int64_t>(entryDelta, 0) * 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setOldestVersion(int64_t oldestVersion) {
|
void setOldestVersion(int64_t oldestVersion) {
|
||||||
@@ -794,7 +795,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
|||||||
int temp;
|
int temp;
|
||||||
std::span<const uint8_t> key = removalKey;
|
std::span<const uint8_t> key = removalKey;
|
||||||
skipList.find(&key, &finger, &temp, 1);
|
skipList.find(&key, &finger, &temp, 1);
|
||||||
skipList.removeBefore(oldestVersion, finger, std::exchange(keyUpdates, 0));
|
skipList.removeBefore(oldestVersion, finger, std::exchange(keyUpdates, 10));
|
||||||
removalArena = Arena();
|
removalArena = Arena();
|
||||||
removalKey = copyToArena(
|
removalKey = copyToArena(
|
||||||
removalArena, {finger.getValue().data(), finger.getValue().size()});
|
removalArena, {finger.getValue().data(), finger.getValue().size()});
|
||||||
@@ -803,7 +804,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl {
|
|||||||
int64_t totalBytes = 0;
|
int64_t totalBytes = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int64_t keyUpdates = 0;
|
int64_t keyUpdates = 10;
|
||||||
Arena removalArena;
|
Arena removalArena;
|
||||||
std::span<const uint8_t> removalKey;
|
std::span<const uint8_t> removalKey;
|
||||||
int64_t oldestVersion;
|
int64_t oldestVersion;
|
||||||
|
|||||||
BIN
corpus/00109d195ce4e826feb08448d822f7ad925fa763
Normal file
BIN
corpus/00109d195ce4e826feb08448d822f7ad925fa763
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/0369048a3408822fdfb7e4250a850e263481544b
Normal file
BIN
corpus/0369048a3408822fdfb7e4250a850e263481544b
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/04d8a5799db6740450a758d973610b39719493dd
Normal file
BIN
corpus/04d8a5799db6740450a758d973610b39719493dd
Normal file
Binary file not shown.
BIN
corpus/0510903db2331a8ac8de00768131b184d5871e64
Normal file
BIN
corpus/0510903db2331a8ac8de00768131b184d5871e64
Normal file
Binary file not shown.
BIN
corpus/0594eed24298634b028ccafaf284afb5a6acf940
Normal file
BIN
corpus/0594eed24298634b028ccafaf284afb5a6acf940
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/084e4406b0be350bb06ea41a4fa08ee4edf2b3c5
Normal file
BIN
corpus/084e4406b0be350bb06ea41a4fa08ee4edf2b3c5
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/0d94e23cb04bdaa083df8c0eb9a37d56c1d72b08
Normal file
BIN
corpus/0d94e23cb04bdaa083df8c0eb9a37d56c1d72b08
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/0e03a31dd94cd404f9559ee3041937418a5d6e73
Normal file
BIN
corpus/0e03a31dd94cd404f9559ee3041937418a5d6e73
Normal file
Binary file not shown.
BIN
corpus/0e4d2f5bc16bb65322c976e1c40d8aa8ee83bef0
Normal file
BIN
corpus/0e4d2f5bc16bb65322c976e1c40d8aa8ee83bef0
Normal file
Binary file not shown.
BIN
corpus/0e5ef615ee3864cffe276899f998ef9de68d792d
Normal file
BIN
corpus/0e5ef615ee3864cffe276899f998ef9de68d792d
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/1276c544ff45483d27ba32242fff1f4db3cfda3f
Normal file
BIN
corpus/1276c544ff45483d27ba32242fff1f4db3cfda3f
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/14675a1f433ad02a993ee402c562f19b39a69896
Normal file
BIN
corpus/14675a1f433ad02a993ee402c562f19b39a69896
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/15ef9579e5fa538b38b74e134c86bbfce4eea462
Normal file
BIN
corpus/15ef9579e5fa538b38b74e134c86bbfce4eea462
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/182793674308ba671193c5cdd9750e03a2889235
Normal file
BIN
corpus/182793674308ba671193c5cdd9750e03a2889235
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/1be0db1f3b34f05c856bb1f87337c1c5ad2c1051
Normal file
BIN
corpus/1be0db1f3b34f05c856bb1f87337c1c5ad2c1051
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/1e0cc87f3aeef1f66b1cf58007854fc5404e5700
Normal file
BIN
corpus/1e0cc87f3aeef1f66b1cf58007854fc5404e5700
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/1eb1dd4a29b56aae35a607593cf5c7a1b56868f3
Normal file
BIN
corpus/1eb1dd4a29b56aae35a607593cf5c7a1b56868f3
Normal file
Binary file not shown.
BIN
corpus/1ec9a7689eceb2a68b703619c6302147f258d088
Normal file
BIN
corpus/1ec9a7689eceb2a68b703619c6302147f258d088
Normal file
Binary file not shown.
BIN
corpus/1f4bd753e184a7e81d0c26b43ca18a3e8cfee86f
Normal file
BIN
corpus/1f4bd753e184a7e81d0c26b43ca18a3e8cfee86f
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/248bb4518929f33a266eae8e1d233958f7330198
Normal file
BIN
corpus/248bb4518929f33a266eae8e1d233958f7330198
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/29f42e23253dbbff5fce83cc09004704c6c18c1c
Normal file
BIN
corpus/29f42e23253dbbff5fce83cc09004704c6c18c1c
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/2db7bb596dfbaff4c7f68584f47ca49c6550b171
Normal file
BIN
corpus/2db7bb596dfbaff4c7f68584f47ca49c6550b171
Normal file
Binary file not shown.
BIN
corpus/2e1c8f40585dd31e6d1b0db564fc7a4c4983d7e3
Normal file
BIN
corpus/2e1c8f40585dd31e6d1b0db564fc7a4c4983d7e3
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/2e5f150272808fe332c6861fb1b3cad26827091a
Normal file
BIN
corpus/2e5f150272808fe332c6861fb1b3cad26827091a
Normal file
Binary file not shown.
BIN
corpus/2f01ecff62d1174bd3d29311a6c7ed830234feb1
Normal file
BIN
corpus/2f01ecff62d1174bd3d29311a6c7ed830234feb1
Normal file
Binary file not shown.
BIN
corpus/2f52518baf38b56e013170e88f40705c4c62fdf8
Normal file
BIN
corpus/2f52518baf38b56e013170e88f40705c4c62fdf8
Normal file
Binary file not shown.
BIN
corpus/2f55cc9c0979af56b253b41b572477170d233450
Normal file
BIN
corpus/2f55cc9c0979af56b253b41b572477170d233450
Normal file
Binary file not shown.
BIN
corpus/3020790285b3a34ef756d982502594517e6cc535
Normal file
BIN
corpus/3020790285b3a34ef756d982502594517e6cc535
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/324b414c0c0fe8aa042b6b3d38a8687a7d98bf3f
Normal file
BIN
corpus/324b414c0c0fe8aa042b6b3d38a8687a7d98bf3f
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/3380368f7a3b74bb98e8077e2e98d8f25a5f687a
Normal file
BIN
corpus/3380368f7a3b74bb98e8077e2e98d8f25a5f687a
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/377e85079bc11aa87600024852e9933b428fdbfa
Normal file
BIN
corpus/377e85079bc11aa87600024852e9933b428fdbfa
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/3aed9ae1320b244d4fccc5da70a788dc5a86c501
Normal file
BIN
corpus/3aed9ae1320b244d4fccc5da70a788dc5a86c501
Normal file
Binary file not shown.
BIN
corpus/3b1b54256c016f3ef2c5b82811937d1c1fa19a04
Normal file
BIN
corpus/3b1b54256c016f3ef2c5b82811937d1c1fa19a04
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/3d945fa5dedbbf67585f16917fbc6a49995ad658
Normal file
BIN
corpus/3d945fa5dedbbf67585f16917fbc6a49995ad658
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/3e32897a108d7df921659463f5ba301634bc278c
Normal file
BIN
corpus/3e32897a108d7df921659463f5ba301634bc278c
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/3f35e2bcd8857d807dd5c8e4a04f2dad19103efa
Normal file
BIN
corpus/3f35e2bcd8857d807dd5c8e4a04f2dad19103efa
Normal file
Binary file not shown.
BIN
corpus/3f6efe293f6347c0d960918e84a7adc5341d5295
Normal file
BIN
corpus/3f6efe293f6347c0d960918e84a7adc5341d5295
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/43b87330229d21961a7df933b2be9da65d71bcb1
Normal file
BIN
corpus/43b87330229d21961a7df933b2be9da65d71bcb1
Normal file
Binary file not shown.
BIN
corpus/44038657af1b2a3398a0c39bcab8f6e4b24d218d
Normal file
BIN
corpus/44038657af1b2a3398a0c39bcab8f6e4b24d218d
Normal file
Binary file not shown.
BIN
corpus/459d9bc23bfdabdf74fba5f5847e607e58dc4db8
Normal file
BIN
corpus/459d9bc23bfdabdf74fba5f5847e607e58dc4db8
Normal file
Binary file not shown.
BIN
corpus/45ec4091345676324b4bf22da4902e2ad688ea5c
Normal file
BIN
corpus/45ec4091345676324b4bf22da4902e2ad688ea5c
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/471d91e159052a7f3b84c92b5b9c8aa23e7eb11b
Normal file
BIN
corpus/471d91e159052a7f3b84c92b5b9c8aa23e7eb11b
Normal file
Binary file not shown.
BIN
corpus/483b083c153baea1a8ab33f45ba4e9e557e393c0
Normal file
BIN
corpus/483b083c153baea1a8ab33f45ba4e9e557e393c0
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
corpus/496e3f23a395a7d97a97cc85579cbc62c81b235a
Normal file
BIN
corpus/496e3f23a395a7d97a97cc85579cbc62c81b235a
Normal file
Binary file not shown.
Binary file not shown.
BIN
corpus/4a5483ae597c5dd4fc5399e443bc3a37d74262d9
Normal file
BIN
corpus/4a5483ae597c5dd4fc5399e443bc3a37d74262d9
Normal file
Binary file not shown.
BIN
corpus/4afa69032fccc9656084fb3270741f2b54151ff7
Normal file
BIN
corpus/4afa69032fccc9656084fb3270741f2b54151ff7
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user