Skip to content

Commit eb00e40

Browse files
committed
Support higher performance bvar with babylon counter
1 parent 2b757e9 commit eb00e40

16 files changed

Lines changed: 548 additions & 319 deletions

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### What problem does this PR solve?
22

3-
Issue Number:
3+
Issue Number: resolve
44

55
Problem Summary:
66

.github/workflows/ci-linux.yml

Lines changed: 5 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -15,192 +15,14 @@ env:
1515

1616
# https://github.com/actions/runner-images
1717
jobs:
18-
compile-with-make:
18+
gcc-compile-with-bazel-workspace:
1919
runs-on: ubuntu-22.04
2020
steps:
2121
- uses: actions/checkout@v2
22-
- uses: ./.github/actions/install-all-dependencies
22+
- run: bazel test --verbose_failures --define with_babylon_counter=true --define brpc_build_for_unittest=true --test_output=streamed //test:bvar_test
2323

24-
- name: gcc with default options
25-
uses: ./.github/actions/compile-with-make
26-
with:
27-
options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror
28-
29-
- name: gcc with all options
30-
uses: ./.github/actions/compile-with-make
31-
with:
32-
options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan
33-
34-
- name: clang with default options
35-
uses: ./.github/actions/compile-with-make
36-
with:
37-
options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror
38-
39-
- name: clang with all options
40-
uses: ./.github/actions/compile-with-make
41-
with:
42-
options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan
43-
44-
compile-with-cmake:
45-
runs-on: ubuntu-22.04
46-
steps:
47-
- uses: actions/checkout@v2
48-
- uses: ./.github/actions/install-all-dependencies
49-
50-
- name: gcc with default options
51-
run: |
52-
export CC=gcc && export CXX=g++
53-
mkdir gcc_build && cd gcc_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
54-
make -j ${{env.proc_num}} && make clean
55-
56-
- name: gcc with all options
57-
run: |
58-
export CC=gcc && export CXX=g++
59-
mkdir gcc_build_all && cd gcc_build_all
60-
cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
61-
make -j ${{env.proc_num}} && make clean
62-
63-
- name: clang with default options
64-
run: |
65-
export CC=clang && export CXX=clang++
66-
mkdir clang_build && cd clang_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
67-
make -j ${{env.proc_num}} && make clean
68-
69-
- name: clang with all options
70-
run: |
71-
export CC=clang && export CXX=clang++
72-
mkdir clang_build_all && cd clang_build_all
73-
cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
74-
make -j ${{env.proc_num}} && make clean
75-
76-
gcc-compile-with-make-protobuf:
77-
runs-on: ubuntu-22.04
78-
steps:
79-
- uses: actions/checkout@v2
80-
- uses: ./.github/actions/install-essential-dependencies
81-
82-
- name: protobuf 3.5.1
83-
uses: ./.github/actions/compile-with-make-protobuf
84-
with:
85-
protobuf-version: 3.5.1
86-
protobuf-cpp-version: 3.5.1
87-
protobuf-install-dir: /protobuf-3.5.1
88-
config-brpc-options: --cc=gcc --cxx=g++ --werror
89-
90-
- name: protobuf 3.12.4
91-
uses: ./.github/actions/compile-with-make-protobuf
92-
with:
93-
protobuf-version: 3.12.4
94-
protobuf-cpp-version: 3.12.4
95-
protobuf-install-dir: /protobuf-3.12.4
96-
config-brpc-options: --cc=gcc --cxx=g++ --werror
97-
98-
- name: protobuf 21.12
99-
uses: ./.github/actions/compile-with-make-protobuf
100-
with:
101-
protobuf-version: 21.12
102-
protobuf-cpp-version: 3.21.12
103-
protobuf-install-dir: /protobuf-3.21.12
104-
config-brpc-options: --cc=gcc --cxx=g++ --werror
105-
106-
gcc-compile-with-bazel:
107-
runs-on: ubuntu-22.04
108-
steps:
109-
- uses: actions/checkout@v2
110-
- run: bazel build --verbose_failures -- //... -//example/...
111-
112-
gcc-compile-with-boringssl:
24+
clang-compile-with-bazel-workspace:
11325
runs-on: ubuntu-22.04
11426
steps:
115-
- uses: actions/checkout@v2
116-
- run: bazel build --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/...
117-
118-
gcc-compile-with-bazel-all-options:
119-
runs-on: ubuntu-22.04
120-
steps:
121-
- uses: actions/checkout@v2
122-
- run: bazel build --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/...
123-
124-
clang-compile-with-make-protobuf:
125-
runs-on: ubuntu-22.04
126-
steps:
127-
- uses: actions/checkout@v2
128-
- uses: ./.github/actions/install-essential-dependencies
129-
130-
- name: protobuf 3.5.1
131-
uses: ./.github/actions/compile-with-make-protobuf
132-
with:
133-
protobuf-version: 3.5.1
134-
protobuf-cpp-version: 3.5.1
135-
protobuf-install-dir: /protobuf-3.5.1
136-
config-brpc-options: --cc=clang --cxx=clang++ --werror
137-
138-
- name: protobuf 3.12.4
139-
uses: ./.github/actions/compile-with-make-protobuf
140-
with:
141-
protobuf-version: 3.12.4
142-
protobuf-cpp-version: 3.12.4
143-
protobuf-install-dir: /protobuf-3.12.4
144-
config-brpc-options: --cc=clang --cxx=clang++ --werror
145-
146-
- name: protobuf 21.12
147-
uses: ./.github/actions/compile-with-make-protobuf
148-
with:
149-
protobuf-version: 21.12
150-
protobuf-cpp-version: 3.21.12
151-
protobuf-install-dir: /protobuf-3.21.12
152-
config-brpc-options: --cc=clang --cxx=clang++ --werror
153-
154-
clang-compile-with-bazel:
155-
runs-on: ubuntu-22.04
156-
steps:
157-
- uses: actions/checkout@v2
158-
- run: bazel build --verbose_failures --action_env=CC=clang -- //... -//example/...
159-
160-
clang-compile-with-boringssl:
161-
runs-on: ubuntu-22.04
162-
steps:
163-
- uses: actions/checkout@v2
164-
- run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/...
165-
166-
clang-compile-with-bazel-all-options:
167-
runs-on: ubuntu-22.04
168-
steps:
169-
- uses: actions/checkout@v2
170-
- run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define with_debug_bthread_sche_safety=true --define with_debug_lock=true --define with_asan=true -- //... -//example/...
171-
172-
clang-unittest:
173-
runs-on: ubuntu-22.04
174-
steps:
175-
- uses: actions/checkout@v2
176-
- uses: ./.github/actions/install-essential-dependencies
177-
- uses: ./.github/actions/init-ut-make-config
178-
with:
179-
options: --with-bthread-tracer
180-
- name: compile tests
181-
run: |
182-
cat config.mk
183-
cd test
184-
make -j ${{env.proc_num}}
185-
- name: run tests
186-
run: |
187-
cd test
188-
sh ./run_tests.sh
189-
190-
clang-unittest-asan:
191-
runs-on: ubuntu-22.04
192-
steps:
193-
- uses: actions/checkout@v2
194-
- uses: ./.github/actions/install-essential-dependencies
195-
- uses: ./.github/actions/init-ut-make-config
196-
with:
197-
options: --with-bthread-tracer --with-asan
198-
- name: compile tests
199-
run: |
200-
cat config.mk
201-
cd test
202-
make NEED_GPERFTOOLS=0 -j ${{env.proc_num}}
203-
- name: run tests
204-
run: |
205-
cd test
206-
sh ./run_tests.sh
27+
- uses: actions/checkout@v2
28+
- run: bazel test --verbose_failures --action_env=CC=clang --define with_babylon_counter=true --define brpc_build_for_unittest=true --test_output=streamed //test:bvar_test

.github/workflows/ci-macos.yml

Lines changed: 0 additions & 67 deletions
This file was deleted.

BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ cc_library(
377377
"src/bvar/utils/*.h",
378378
"src/bvar/detail/*.h",
379379
]),
380+
defines = [] + select({
381+
"//bazel/config:with_babylon_counter": ["WITH_BABYLON_COUNTER=1"],
382+
"//conditions:default": [],
383+
}),
380384
copts = COPTS + select({
381385
"//bazel/config:brpc_build_for_unittest": [
382386
"-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
@@ -391,7 +395,10 @@ cc_library(
391395
visibility = ["//visibility:public"],
392396
deps = [
393397
":butil",
394-
],
398+
] + select({
399+
"//bazel/config:with_babylon_counter": ["@babylon//:concurrent_counter"],
400+
"//conditions:default": [],
401+
}),
395402
)
396403

397404
cc_library(

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bazel_dep(name = 'rules_cc', version = '0.0.1')
1717
bazel_dep(name = 'rules_proto', version = '4.0.0')
1818
bazel_dep(name = 'zlib', version = '1.3.1.bcr.5', repo_name = 'com_github_madler_zlib')
1919
bazel_dep(name = 'libunwind', version = '1.8.1', repo_name = 'com_github_libunwind_libunwind')
20+
bazel_dep(name = 'babylon', version = '1.4.4')
2021

2122
# --registry=https://baidu.github.io/babylon/registry
2223
bazel_dep(name = 'leveldb', version = '1.23', repo_name = 'com_github_google_leveldb')

bazel/config/BUILD.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,10 @@ config_setting(
142142
name = "brpc_with_no_pthread_mutex_hook",
143143
define_values = {"BRPC_WITH_NO_PTHREAD_MUTEX_HOOK": "true"},
144144
visibility = ["//visibility:public"],
145+
)
146+
147+
config_setting(
148+
name = "with_babylon_counter",
149+
define_values = {"with_babylon_counter": "true"},
150+
visibility = ["//visibility:public"],
145151
)

src/butil/macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444

4545
// Declarations for a class to be unassignable.
4646
#define DISALLOW_ASSIGN(TypeName) \
47-
BUTIL_DELETE_FUNCTION(void operator=(const TypeName&))
47+
BUTIL_DELETE_FUNCTION(TypeName& operator=(const TypeName&))
4848

4949
// Declarations for a class to be move-unassignable.
5050
#define DISALLOW_MOVE_ASSIGN(TypeName) \
51-
BUTIL_DELETE_FUNCTION(void operator=(TypeName&&))
51+
BUTIL_DELETE_FUNCTION(TypeName& operator=(TypeName&&))
5252

5353
// A macro to disallow the copy constructor and operator= functions.
5454
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \

src/bvar/detail/percentile.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace bvar {
2424
namespace detail {
25-
25+
#if !WITH_BABYLON_COUNTER
2626
inline uint32_t ones32(uint32_t x) {
2727
/* 32-bit recursive reduction using SWAR...
2828
* but first step is mapping 2-bit values
@@ -127,6 +127,41 @@ Percentile &Percentile::operator<<(int64_t latency) {
127127
agent->merge_global(AddLatency(latency), _combiner);
128128
return *this;
129129
}
130+
#else
131+
Percentile::value_type Percentile::reset() {
132+
constexpr static size_t SAMPLE_SIZE = value_type::SAMPLE_SIZE;
133+
value_type result;
134+
_concurrent_sampler.for_each([&](
135+
size_t index, const babylon::ConcurrentSampler::SampleBucket& bucket) {
136+
result.merge(bucket, index);
137+
auto capacity = _concurrent_sampler.bucket_capacity(index);
138+
auto num_added = bucket.record_num.load(::std::memory_order_relaxed);
139+
if (capacity < SAMPLE_SIZE && num_added > capacity) {
140+
capacity = std::min<size_t>(SAMPLE_SIZE, num_added * 1.5);
141+
_concurrent_sampler.set_bucket_capacity(index, capacity);
142+
}
143+
});
144+
_concurrent_sampler.reset();
145+
return result;
146+
}
130147

148+
Percentile& Percentile::operator<<(int64_t value) {
149+
if (BAIDU_UNLIKELY(value < 0)) {
150+
// we don't check overflow(of uint32) in percentile because the
151+
// overflowed value which is included in last range does not affect
152+
// overall distribution of other values too much.
153+
if (!_debug_name.empty()) {
154+
LOG_EVERY_SECOND(WARNING) << "Input=" << value << " to `" << _debug_name
155+
<< "' is negative, drop";
156+
} else {
157+
LOG_EVERY_SECOND(WARNING) << "Input=" << value << " to Percentile("
158+
<< (void*)this << ") is negative, drop";
159+
}
160+
} else {
161+
_concurrent_sampler << value;
162+
}
163+
return *this;
164+
}
165+
#endif // WITH_BABYLON_COUNTER
131166
} // namespace detail
132167
} // namespace bvar

0 commit comments

Comments
 (0)