Skip to content

Commit a19fa4f

Browse files
authored
chore: use PerfCounters to replace counters & metrics (#129)
1 parent 925a074 commit a19fa4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+431
-2757
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ find_package(spdlog CONFIG REQUIRED)
7676
find_package(GTest CONFIG REQUIRED)
7777
find_package(benchmark CONFIG REQUIRED)
7878
find_package(Crc32c CONFIG REQUIRED)
79-
find_package(prometheus-cpp CONFIG REQUIRED)
8079
find_package(httplib CONFIG REQUIRED)
8180
find_package(PkgConfig)
8281
pkg_check_modules(libunwind REQUIRED IMPORTED_TARGET GLOBAL libunwind)

CMakePresets.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
1111
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
1212
"BUILD_SHARED_LIBS": "ON",
13-
"ENABLE_PROFILING": "ON"
13+
"ENABLE_PROFILING": "ON",
14+
"ENABLE_PERF_COUNTERS": "ON"
1415
}
1516
},
1617
{
@@ -26,8 +27,7 @@
2627
"inherits": "base",
2728
"hidden": true,
2829
"cacheVariables": {
29-
"CMAKE_BUILD_TYPE": "Release",
30-
"COUNTERS_LEVEL": "none"
30+
"CMAKE_BUILD_TYPE": "Release"
3131
}
3232
},
3333
{
@@ -68,4 +68,4 @@
6868
}
6969
}
7070
]
71-
}
71+
}

benchmarks/ycsb/YcsbLeanStore.hpp

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "Ycsb.hpp"
2+
#include "leanstore-c/PerfCounters.h"
23
#include "leanstore-c/StoreOption.h"
4+
#include "leanstore-c/leanstore-c.h"
35
#include "leanstore/KVInterface.hpp"
46
#include "leanstore/LeanStore.hpp"
57
#include "leanstore/btree/BasicKV.hpp"
@@ -17,14 +19,20 @@
1719

1820
#include <atomic>
1921
#include <chrono>
22+
#include <cstdint>
2023
#include <cstdlib>
2124
#include <cstring>
2225
#include <format>
26+
#include <fstream>
2327
#include <iostream>
2428
#include <memory>
2529
#include <string>
30+
#include <thread>
2631
#include <vector>
2732

33+
#include <sys/types.h>
34+
#include <unistd.h>
35+
2836
namespace leanstore::ycsb {
2937

3038
constexpr std::string kTableName = "ycsb_leanstore";
@@ -44,8 +52,6 @@ class YcsbLeanStore : public YcsbExecutor {
4452
option->mEnableEagerGc = true;
4553
option->mWorkerThreads = FLAGS_ycsb_threads;
4654
option->mBufferPoolSize = FLAGS_ycsb_mem_kb * 1024;
47-
option->mEnableMetrics = true;
48-
option->mMetricsPort = 8080;
4955

5056
auto res = LeanStore::Open(option);
5157
if (!res) {
@@ -55,6 +61,9 @@ class YcsbLeanStore : public YcsbExecutor {
5561
}
5662

5763
mStore = std::move(res.value());
64+
65+
// start metrics http exposer for cpu/mem profiling
66+
StartMetricsHttpExposer(8080);
5867
}
5968

6069
~YcsbLeanStore() override {
@@ -164,6 +173,12 @@ class YcsbLeanStore : public YcsbExecutor {
164173
a = 0;
165174
}
166175

176+
std::vector<PerfCounters*> workerPerfCounters;
177+
for (auto i = 0u; i < mStore->mStoreOption->mWorkerThreads; i++) {
178+
mStore->ExecSync(
179+
i, [&]() { workerPerfCounters.push_back(cr::WorkerContext::My().GetPerfCounters()); });
180+
}
181+
167182
for (uint64_t workerId = 0; workerId < mStore->mStoreOption->mWorkerThreads; workerId++) {
168183
mStore->ExecAsync(workerId, [&]() {
169184
uint8_t key[FLAGS_ycsb_key_size];
@@ -239,11 +254,45 @@ class YcsbLeanStore : public YcsbExecutor {
239254
a = 0;
240255
}
241256

257+
std::thread perfContextReporter([&]() {
258+
auto reportPeriod = 1;
259+
const char* counterFilePath = "/tmp/leanstore/worker-counters.txt";
260+
std::ofstream ost;
261+
262+
while (keepRunning) {
263+
sleep(reportPeriod);
264+
uint64_t txWithRemoteDependencies = 0;
265+
uint64_t lcbExecuted = 0;
266+
uint64_t lcbTotalLatNs [[maybe_unused]] = 0;
267+
uint64_t gcExecuted = 0;
268+
uint64_t gcTotalLatNs [[maybe_unused]] = 0;
269+
uint64_t txCommitWait = 0;
270+
271+
// collect counters
272+
for (auto* perfCounters : workerPerfCounters) {
273+
txWithRemoteDependencies += atomic_exchange(&perfCounters->mTxWithRemoteDependencies, 0);
274+
txCommitWait += atomic_exchange(&perfCounters->mTxCommitWait, 0);
275+
276+
lcbExecuted += atomic_exchange(&perfCounters->mLcbExecuted, 0);
277+
lcbTotalLatNs += atomic_exchange(&perfCounters->mLcbTotalLatNs, 0);
278+
279+
gcExecuted += atomic_exchange(&perfCounters->mGcExecuted, 0);
280+
gcTotalLatNs += atomic_exchange(&perfCounters->mGcTotalLatNs, 0);
281+
}
282+
ost.open(counterFilePath, std::ios_base::app);
283+
ost << std::format("TxWithDep: {}, txCommitWait: {}, LcbExec: {}, GcExec: {}",
284+
txWithRemoteDependencies, txCommitWait, lcbExecuted, gcExecuted)
285+
<< std::endl;
286+
ost.close();
287+
}
288+
});
289+
242290
printTpsSummary(1, FLAGS_ycsb_run_for_seconds, mStore->mStoreOption->mWorkerThreads,
243291
threadCommitted, threadAborted);
244292

245293
// Shutdown threads
246294
keepRunning = false;
295+
perfContextReporter.join();
247296
mStore->WaitAll();
248297
}
249298
};

benchmarks/ycsb/YcsbWiredTiger.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "Ycsb.hpp"
4+
#include "leanstore-c/leanstore-c.h"
45
#include "leanstore/utils/Defer.hpp"
56
#include "leanstore/utils/Log.hpp"
67
#include "leanstore/utils/Parallelize.hpp"
@@ -26,6 +27,7 @@ class YcsbWiredTiger : public YcsbExecutor {
2627

2728
public:
2829
YcsbWiredTiger() : mConn(nullptr) {
30+
StartMetricsHttpExposer(8080);
2931
}
3032

3133
~YcsbWiredTiger() override {
@@ -195,7 +197,8 @@ class YcsbWiredTiger : public YcsbExecutor {
195197
}
196198

197199
std::string configString(
198-
"create, direct_io=[data, log, checkpoint], log=(enabled=false), statistics_log=(wait=1), "
200+
"create, direct_io=[data, log, checkpoint], "
201+
"log=(enabled=true,archive=true), statistics_log=(wait=1), "
199202
"statistics=(all, clear), session_max=2000, eviction=(threads_max=4), cache_size=" +
200203
std::to_string(FLAGS_ycsb_mem_kb / 1024) + "M");
201204
int ret = wiredtiger_open(dataDir.c_str(), nullptr, configString.c_str(), &mConn);

docker/monitor-compose/docker-compose.yml

-26
This file was deleted.

docker/monitor-compose/grafana/dashboards/dashboards.yaml

-11
This file was deleted.

docker/monitor-compose/grafana/dashboards/my_dashboard.json

-84
This file was deleted.

docker/monitor-compose/grafana/datasources/datasources.yaml

-7
This file was deleted.

docker/monitor-compose/prometheus.yml

-11
This file was deleted.

include/leanstore-c/PerfCounters.h

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#ifndef LEANSTORE_PERF_COUNTERS_H
2+
#define LEANSTORE_PERF_COUNTERS_H
3+
4+
#include <stdatomic.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
//! The counter type.
11+
typedef atomic_ullong CounterType;
12+
13+
//! The performance counters for each worker.
14+
typedef struct PerfCounters {
15+
16+
// ---------------------------------------------------------------------------
17+
// Transaction related counters
18+
// ---------------------------------------------------------------------------
19+
20+
//! The number of transactions committed.
21+
CounterType mTxCommitted;
22+
23+
//! The number of transactions commit wait.
24+
CounterType mTxCommitWait;
25+
26+
//! The number of transactions aborted.
27+
CounterType mTxAborted;
28+
29+
///! The number of transactions with remote dependencies.
30+
CounterType mTxWithRemoteDependencies;
31+
32+
//! The number of transactions without remote dependencies.
33+
CounterType mTxWithoutRemoteDependencies;
34+
35+
//! The number of short running transactions.
36+
CounterType mTxShortRunning;
37+
38+
//! The number of long running transactions.
39+
CounterType mTxLongRunning;
40+
41+
// ---------------------------------------------------------------------------
42+
// MVCC concurrency control related counters
43+
// ---------------------------------------------------------------------------
44+
45+
//! The number of LCB query executed.
46+
CounterType mLcbExecuted;
47+
48+
//! The total latency of LCB query in nanoseconds.
49+
CounterType mLcbTotalLatNs;
50+
51+
// ---------------------------------------------------------------------------
52+
// MVCC garbage collection related counters
53+
// ---------------------------------------------------------------------------
54+
55+
//! The number of MVCC garbage collection executed.
56+
CounterType mGcExecuted;
57+
58+
//! The total latency of MVCC garbage collection in nanoseconds.
59+
CounterType mGcTotalLatNs;
60+
61+
// ---------------------------------------------------------------------------
62+
// Contention split related counters
63+
// ---------------------------------------------------------------------------
64+
65+
//! The number of contention split succeed.
66+
CounterType mContentionSplitSucceed;
67+
68+
//! The number of contention split failed.
69+
CounterType mContentionSplitFailed;
70+
71+
//! The number of normal split succeed.
72+
CounterType mSplitSucceed;
73+
74+
//! The number of normal split failed.
75+
CounterType mSplitFailed;
76+
77+
} PerfCounters;
78+
79+
#ifdef __cplusplus
80+
}
81+
#endif
82+
83+
#endif

0 commit comments

Comments
 (0)