Skip to content

Commit 1d3bded

Browse files
authored
Support higher performance bvar with babylon counter (#3116)
* Support higher performance bvar with babylon counter * Update documents
1 parent 5f1d893 commit 1d3bded

22 files changed

Lines changed: 580 additions & 72 deletions

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ common --registry=https://bcr.bazel.build
2020
common --registry=https://baidu.github.io/babylon/registry
2121

2222
build --cxxopt="-std=c++17"
23+
build --copt="-fno-omit-frame-pointer"
2324
# Use gnu17 for asm keyword.
2425
build --conlyopt="-std=gnu17"
2526

@@ -33,8 +34,8 @@ build --features=per_object_debug_info
3334
build --define absl=1
3435

3536
# For brpc.
36-
build --define=BRPC_WITH_GLOG=true
3737
test --define=BRPC_BUILD_FOR_UNITTEST=true
38+
test --test_output=streamed
3839

3940
# Pass PATH, CC, CXX and LLVM_CONFIG variables from the environment.
4041
build --action_env=CC

.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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,12 @@ jobs:
225225
run: |
226226
cd test
227227
sh ./run_tests.sh
228+
229+
bazel-bvar-unittest:
230+
runs-on: ubuntu-22.04
231+
steps:
232+
- uses: actions/checkout@v2
233+
- run: bazel test --verbose_failures //test:bvar_test
234+
- run: bazel test --verbose_failures --define with_babylon_counter=true //test:bvar_test
235+
- run: bazel test --verbose_failures --action_env=CC=clang //test:bvar_test
236+
- run: bazel test --verbose_failures --action_env=CC=clang --define with_babylon_counter=true //test:bvar_test

.github/workflows/ci-macos.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jobs:
6161
6262
compile-with-bazel:
6363
runs-on: macos-latest # https://github.com/actions/runner-images
64-
6564
steps:
6665
- uses: actions/checkout@v2
6766
- run: bazel build --verbose_failures -- //:brpc -//example/...

BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ licenses(["notice"]) # Apache v2
2121
exports_files(["LICENSE"])
2222

2323
COPTS = [
24+
"-fno-omit-frame-pointer",
2425
"-DBTHREAD_USE_FAST_PTHREAD_MUTEX",
2526
"-D__const__=__unused__",
2627
"-D_GNU_SOURCE",
@@ -377,6 +378,10 @@ cc_library(
377378
"src/bvar/utils/*.h",
378379
"src/bvar/detail/*.h",
379380
]),
381+
defines = [] + select({
382+
"//bazel/config:with_babylon_counter": ["WITH_BABYLON_COUNTER=1"],
383+
"//conditions:default": [],
384+
}),
380385
copts = COPTS + select({
381386
"//bazel/config:brpc_build_for_unittest": [
382387
"-DBVAR_NOT_LINK_DEFAULT_VARIABLES",
@@ -391,7 +396,10 @@ cc_library(
391396
visibility = ["//visibility:public"],
392397
deps = [
393398
":butil",
394-
],
399+
] + select({
400+
"//bazel/config:with_babylon_counter": ["@babylon//:concurrent_counter"],
401+
"//conditions:default": [],
402+
}),
395403
)
396404

397405
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
)

docs/cn/bvar_c++.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,9 @@ static bvar::GFlag s_gflag_my_flag_that_matters("my_flag_that_matters");
650650
// Expose the gflag as a bvar named "foo_bar_my_flag_that_matters".
651651
static bvar::GFlag s_gflag_my_flag_that_matters_with_prefix("foo_bar", "my_flag_that_matters");
652652
```
653+
# babylon counter bvar
654+
655+
原理和性能见[babylon介绍](https://github.com/baidu/babylon/tree/main/example/use-counter-with-bvar)
656+
657+
目前只支持bazel编译方式:`--define with_babylon_counter=true`,babylon版本要求:>= 1.4.4。打开开关后,即可使用基于babylon counter实现的更高性能的bvar,无需修改代码。
658+

docs/en/bvar_c++.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,9 @@ static bvar::GFlag s_gflag_my_flag_that_matters("my_flag_that_matters");
490490
// Expose the gflag as a bvar named "foo_bar_my_flag_that_matters".
491491
static bvar::GFlag s_gflag_my_flag_that_matters_with_prefix("foo_bar", "my_flag_that_matters");
492492
```
493+
494+
# babylon counter bvar
495+
496+
For details on the principles and performance, see [Use concurrent counter optimize bvar](https://github.com/baidu/babylon/tree/main/example/use-counter-with-bvar).
497+
498+
Currently, this feature is only supported by the Bazel compilation method: `--define with_babylon_counter=true`. The required Babylon version is 1.4.4 or higher. Once enabled, you can use the higher-performance bvar implementation based on the babylon counter without modifying your code.

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) \

0 commit comments

Comments
 (0)