BRPC is the most commonly used industrial-level RPC framework in Baidu, with 1,000,000+ instances (excluding clients) and thousands of services. It is called “Bidu-RPC” in Baidu, and is a very valuable battle-level RPC framework.

The advantage of the BRPC

The introduction of too many advantages is not the focus of this article, and the following links are provided for reference:

  • The official introduction

  • The performance comparison

The installation of the BRPC

Because BRPC is written in C++, there is no official installation method for BRPC, so it can run only after the source code provided by clone is compiled and installed.

First give the official document – MACOS, for your reference.

Although the official documentation is well written and very simple for a C++ veteran, for me, an Android native with a mediocre C++ level, it took nearly 3 hours just to compile and install the BRPC. Here I will explain step by step how to install the BRPC on Mac and the various bugs encountered.

Preparation before installation

Before the installation, Baidu also warned that the current Mac version performance is 2.5 times worse than the Linux version, it is recommended not to use MacOS as a production environment, but this should not affect my development, haha ~ ~

  1. Install common development tools

Run the following commands to install Openssl, git, GNU -getopt, and coreutils

brew install openssl git gnu-getopt coreutils
Copy the code
  1. Install BRPC dependent tools

Run the following command to install gflags, Protobuf, LevelDB

brew install gflags protobuf leveldb
Copy the code
  • Gflags: Google’s command-line argument parsing tool
  • Protobuf: A set of open-source coding rules distributed by Google, a serialized transport tool based on binary streams.
  • Leveldb: A very efficient KV database implemented by Google.
  1. (Optional) Install performance monitoring tool GperfTools
brew install gperftools
Copy the code
  1. Install the unit test tool, GoogleTest (optional)
git clone https://github.com/google/googletest && cd googletest/googletest && mkdir bld && cd bld && cmake -DCMAKE_CXX_FLAGS="-std=c++11" .. && make && sudo mv libgtest* /usr/lib/ && cd -
Copy the code

Start compiling and installing

Here I use the config_brpc.sh script to compile and install.

  1. clone brpc
git clone https://github.com/apache/incubator-brpc.git
Copy the code
  1. CD Go to the source directory and run the following command
$ sh config_brpc.sh --headers=/usr/local/include --libs=/usr/local/lib --cc=clang --cxx=clang++
$ make
Copy the code

A pit encountered when compiling on a MAC

After execution, you will find various compilation errors. Ok, let me start by explaining the various bugs encountered during compilation:

  • Check the version of protobuf you have installed, if >3.6.1, please degrade it first.

As for how to use Homebrew to install the specified version of the program, I offer the following two methods:

(1) General method

(2) The ultimate method

  • If the openSSL version is 1.0.2r, please modify the config.mk file and manually add the openSSL directory:
HDRS = / usr/local/Cellar/openssl / 1.0.2 r/include/usr/local/include / / usr/local/include/node / LIBS = / usr/local/Cellar/openssl / 1.0.2 r/lib/usr/local/libCopy the code

After solving the above two pits, the basic is also able to compile successfully.

Test program run

$ cd example/echo_c++
$ make
$ ./echo_server &
$ ./echo_client
Copy the code

After the command is executed, open a browser and enterlocalhost:8000You can see the state of the server as shown below:

Develop reading

  • How to use ProtoBuf to make network requests on Android via gRPC service

Wechat official account

More information, welcome to wechat search public number: [My Android open source journey]