brpc prefers static linking if possible, so that deps don't have to be installed on every machine running the code.
brpc depends on following packages:
- gflags: Extensively used to specify global options.
- protobuf: needless to say, pb is a must-have dep.
- leveldb: required by /rpcz to record RPCs for tracing.
install common deps: git g++ make libssl-dev
install gflags, protobuf, leveldb, including: libgflags-dev libprotobuf-dev libprotoc-dev protobuf-compiler libleveldb-dev
. If you need to statically link leveldb, install libsnappy-dev
as well.
git clone brpc, cd into the repo and run
$ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib
$ make
to change compiler to clang, add --cxx=clang++ --cc=clang
.
$ cd example/echo_c++
$ make
$ ./echo_server &
$ ./echo_client
Examples link brpc statically, if you need to link the shared version, make clean
and LINK_SO=1 make
To run examples with cpu/heap profilers, install libgoogle-perftools-dev
and re-run config_brpc.sh
before compiling
Install gmock and gtest, use the gtest embedded in gmock and don't install libgtest-dev
$ sudo apt-get install google-mock
$ cd /usr/src
$ sudo cmake .
$ sudo make
$ sudo mv lib*.a gtest/lib*.a /usr/lib
$ sudo mv gtest/include/gtest /usr/include/
Rerun config_brpc.sh and run make in test/
install common deps: git g++ make openssl-devel
install gflags, protobuf, leveldb, including: gflags-devel protobuf-devel protobuf-compiler leveldb-devel
.
git clone brpc, cd into the repo and run
$ sh config_brpc.sh --headers=/usr/include --libs=/usr/lib64
$ make
to change compiler to clang, add --cxx=clang++ --cc=clang
.
$ cd example/echo_c++
$ make
$ ./echo_server &
$ ./echo_client
Examples link brpc statically, if you need to link the shared version, make clean
and LINK_SO=1 make
To run examples with cpu/heap profilers, install gperftools-devel
and re-run config_brpc.sh
before compiling
brpc builds itself to both static and shared libs by default, so it needs static and shared libs of deps to be built as well.
Take gflags as example, which does not build shared lib by default, you need to pass options to cmake
to change the behavior, like this: cmake . -DBUILD_SHARED_LIBS=1 -DBUILD_STATIC_LIBS=1
then make
.
Keep on with the gflags example, let ../gflags_dev
be where you clone gflags.
git clone brpc. cd into the repo and run
$ sh config_brpc.sh --headers="../gflags_dev /usr/include" --libs="../gflags_dev /usr/lib64"
$ make
to change compiler to clang, add --cxx=clang++ --cc=clang
.
Here we pass multiple paths to --headers
and --libs
to make the script search for multiple places. You can also group all deps and brpc into one directory, then pass the directory to --headers/--libs which actually search all subdirectories recursively and will find necessary files.
$ ls my_dev
gflags_dev protobuf_dev leveldb_dev brpc_dev
$ cd brpc_dev
$ sh config_brpc.sh --headers=.. --libs=..
$ make
Note: don't put ~ (tilde) in paths to --headers/--libs, it's not converted.
c++11 is turned on by default to remove dependency on boost (atomic).
The over-aligned issues in GCC7 is suppressed temporarily now.
Using other versions of gcc may generate warnings, contact us to fix.
Adding -D__const__=
to cxxflags in your makefiles is a must avoid errno issue in gcc4+。
unittests can't be compiled with clang yet.
no known issues.
Be compatible with pb 3.0 and pb 2.x with the same file:
Don't use new types in proto3 and start the proto file with syntax="proto2";
tools/add_syntax_equal_proto2_to_all.shcan add syntax="proto2"
to all proto files without it.
protobuf 3.3-3.4 is not tested yet.
no known issues.
required by https.
brpc does not link tcmalloc by default. Users link tcmalloc on-demand.
Comparing to ptmalloc embedded in glibc, tcmalloc often improves performance. However different versions of tcmalloc may behave really differently. For example, tcmalloc 2.1 may make multi-threaded examples in brpc perform significantly worse(due to a spinlock in tcmalloc) than the one using tcmalloc 1.7 and 2.5. Even different minor versions may differ. When you program behave unexpectedly, remove tcmalloc or try another version.
Code compiled with gcc 4.8.2 when linking to a tcmalloc compiled with earlier GCC may crash or deadlock before main(), E.g:
When you meet the issue, compile tcmalloc with the same GCC as the RPC code.
Another common issue with tcmalloc is that it does not return memory to system as early as ptmalloc. So when there's an invalid memory access, the program may not crash directly, instead it crashes at a unrelated place, or even not crash. When you program has weird memory issues, try removing tcmalloc.
If you want to use cpu profiler or heap profiler, do link libtcmalloc_and_profiler.a
. These two profilers are based on tcmalloc.contention profiler does not require tcmalloc.
When you remove tcmalloc, not only remove the linking with tcmalloc but also the macros: -DBRPC_ENABLE_CPU_PROFILER
.
brpc implementes a default logging utility which conflicts with glog. To replace this with glog, add --with-glog to config_brpc.sh
brpc detects valgrind automatically (and registers stacks of bthread). Older valgrind (say 3.2) is not supported.
We provide a program to help you to track and monitor all brpc instances. Just run trackme_server somewhere and launch need-to-be-tracked instances with -trackme_server=SERVER. The trackme_server will receive pings from instances periodically and print logs when it does. You can aggregate instance addresses from the log and call builtin services of the instances for further information.