README.md 4.75 KB
Newer Older
1 2 3 4 5

# Protocol Buffers Benchmarks

This directory contains benchmarking schemas and data sets that you
can use to test a variety of performance scenarios against your
6 7 8
protobuf language runtime. If you are looking for performance 
numbers of officially support languages, see [here](
https://github.com/google/protobuf/blob/master/docs/Performance.md)
9

Yilun Chong's avatar
Yilun Chong committed
10
## Prerequisite
11

12
First, you need to follow the instruction in the root directory's README to
Yilun Chong's avatar
Yilun Chong committed
13
build your language's protobuf, then:
14

Yilun Chong's avatar
Yilun Chong committed
15
### CPP
Yilun Chong's avatar
Yilun Chong committed
16
You need to install [cmake](https://cmake.org/) before building the benchmark.
17

18 19
We are using [google/benchmark](https://github.com/google/benchmark) as the
benchmark tool for testing cpp. This will be automaticly made during build the
Yilun Chong's avatar
Yilun Chong committed
20
cpp benchmark.
21

22 23 24 25 26
The cpp protobuf performance can be improved by linking with [tcmalloc library](
https://gperftools.github.io/gperftools/tcmalloc.html). For using tcmalloc, you
need to build [gpertools](https://github.com/gperftools/gperftools) to generate
libtcmallc.so library.

Yilun Chong's avatar
Yilun Chong committed
27
### Java
28 29 30
We're using maven to build the java benchmarks, which is the same as to build
the Java protobuf. There're no other tools need to install. We're using
[google/caliper](https://github.com/google/caliper) as benchmark tool, which
Yilun Chong's avatar
Yilun Chong committed
31
can be automaticly included by maven.
Yilun Chong's avatar
Yilun Chong committed
32

Yilun Chong's avatar
Yilun Chong committed
33
### Python
34
We're using python C++ API for testing the generated
Yilun Chong's avatar
Yilun Chong committed
35
CPP proto version of python protobuf, which is also a prerequisite for Python
36 37 38
protobuf cpp implementation. You need to install the correct version of Python
C++ extension package before run generated CPP proto version of Python
protobuf's benchmark. e.g. under Ubuntu, you need to
Yilun Chong's avatar
Yilun Chong committed
39 40

```
41
$ sudo apt-get install python-dev
Yilun Chong's avatar
Yilun Chong committed
42 43
$ sudo apt-get install python3-dev
```
44
And you also need to make sure `pkg-config` is installed.
Yilun Chong's avatar
Yilun Chong committed
45

BSBandme's avatar
BSBandme committed
46
### Go
BSBandme's avatar
BSBandme committed
47 48 49 50 51
Go protobufs are maintained at [github.com/golang/protobuf](
http://github.com/golang/protobuf). If not done already, you need to install the 
toolchain and the Go protoc-gen-go plugin for protoc. 

To install protoc-gen-go, run:
BSBandme's avatar
BSBandme committed
52 53 54

```
$ go get -u github.com/golang/protobuf/protoc-gen-go
BSBandme's avatar
BSBandme committed
55
$ export PATH=$PATH:$(go env GOPATH)/bin
BSBandme's avatar
BSBandme committed
56 57
```

BSBandme's avatar
BSBandme committed
58 59 60
The first command installs `protoc-gen-go` into the `bin` directory in your local `GOPATH`.
The second command adds the `bin` directory to your `PATH` so that `protoc` can locate the plugin later.

Yilun Chong's avatar
Yilun Chong committed
61 62
### Big data

63 64
There's some optional big testing data which is not included in the directory
initially, you need to run the following command to download the testing data:
Yilun Chong's avatar
Yilun Chong committed
65 66

```
67
$ ./download_data.sh
Yilun Chong's avatar
Yilun Chong committed
68 69
```

70 71
After doing this the big data file will automaticly generated in the
benchmark directory.
Yilun Chong's avatar
Yilun Chong committed
72 73 74

## Run instructions

75 76
To run all the benchmark dataset:

Yilun Chong's avatar
Yilun Chong committed
77
### Java:
78 79 80 81 82

```
$ make java
```

Yilun Chong's avatar
Yilun Chong committed
83
### CPP:
84 85

```
86
$ make cpp
87 88
```

89 90 91 92 93 94
For linking with tcmalloc:

```
$ env LD_PRELOAD={directory to libtcmalloc.so} make cpp
```

Yilun Chong's avatar
Yilun Chong committed
95 96
### Python:

97 98
We have three versions of python protobuf implementation: pure python, cpp
reflection and cpp generated code. To run these version benchmark, you need to:
Yilun Chong's avatar
Yilun Chong committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

#### Pure Python:

```
$ make python-pure-python
```

#### CPP reflection:

```
$ make python-cpp-reflection
```

#### CPP generated code:

```
$ make python-cpp-generated-code
116 117
```

BSBandme's avatar
BSBandme committed
118 119 120 121 122
### Go
```
$ make go
```

123
To run a specific dataset or run with specific options:
124

Yilun Chong's avatar
Yilun Chong committed
125
### Java:
126 127

```
128
$ make java-benchmark
129
$ ./java-benchmark $(specific generated dataset file name) [$(caliper options)]
130 131
```

Yilun Chong's avatar
Yilun Chong committed
132
### CPP:
133 134

```
135
$ make cpp-benchmark
136
$ ./cpp-benchmark $(specific generated dataset file name) [$(benchmark options)]
137 138
```

Yilun Chong's avatar
Yilun Chong committed
139 140
### Python:

141 142
For Python benchmark we have `--json` for outputing the json result

Yilun Chong's avatar
Yilun Chong committed
143 144 145 146
#### Pure Python:

```
$ make python-pure-python-benchmark
147
$ ./python-pure-python-benchmark [--json] $(specific generated dataset file name)
Yilun Chong's avatar
Yilun Chong committed
148 149 150 151 152 153
```

#### CPP reflection:

```
$ make python-cpp-reflection-benchmark
154
$ ./python-cpp-reflection-benchmark [--json] $(specific generated dataset file name)
Yilun Chong's avatar
Yilun Chong committed
155 156 157 158 159 160
```

#### CPP generated code:

```
$ make python-cpp-generated-code-benchmark
161
$ ./python-cpp-generated-code-benchmark [--json] $(specific generated dataset file name)
Yilun Chong's avatar
Yilun Chong committed
162 163
```

BSBandme's avatar
BSBandme committed
164 165 166
### Go:
```
$ make go-benchmark
167
$ ./go-benchmark $(specific generated dataset file name) [go testing options]
BSBandme's avatar
BSBandme committed
168 169 170
```


Yilun Chong's avatar
Yilun Chong committed
171 172
## Benchmark datasets

173
Each data set is in the format of benchmarks.proto:
Yilun Chong's avatar
Yilun Chong committed
174

175 176 177 178
1. name is the benchmark dataset's name.
2. message_name is the benchmark's message type full name (including package and message name)
3. payload is the list of raw data.

Yilun Chong's avatar
Yilun Chong committed
179 180
The schema for the datasets is described in `benchmarks.proto`.

181
Benchmark likely want to run several benchmarks against each data set (parse,
182 183 184 185 186 187
serialize, possibly JSON, possibly using different APIs, etc).

We would like to add more data sets.  In general we will favor data sets
that make the overall suite diverse without being too large or having
too many similar tests.  Ideally everyone can run through the entire
suite without the test run getting too long.