|
| 1 | +**[[简体中文]](README.zh-cn.md)** |
| 2 | + |
| 3 | +# Use Arena for brpc |
| 4 | + |
| 5 | +Before invoking a user's service, [brpc](https://github.com/apache/brpc) needs to construct instances of `Request` and `Response` internally, as well as perform corresponding serialization and deserialization operations. By default, it uses dynamic heap memory allocation. For complex structures, the allocation and deallocation of memory, along with the construction and destruction of `Message` structures, can lead to noticeable overhead. |
| 6 | + |
| 7 | +Since version 3.x, [Protobuf](https://github.com/protocolbuffers/protobuf) has introduced [Arena](https://protobuf.dev/reference/cpp/arenas) allocation, which enables aggregated allocation and deallocation for complex structures. More recent versions of [brpc](https://github.com/apache/brpc) also support the [Protobuf arena](https://github.com/apache/brpc/blob/master/docs/cn/server.md#protobuf-arena) component. Based on this, further acceleration for `string` members can be achieved by applying [arenastring](../../docs/arenastring.zh-cn.md). |
| 8 | + |
| 9 | +In addition to using native [Arena](https://protobuf.dev/reference/cpp/arenas), you can also employ [babylon::SwissMemoryResource](../../docs/reusable/memory_resource.zh-cn.md#swissmemoryresource) for memory pool acceleration. [babylon::SwissMemoryResource](../../docs/reusable/memory_resource.zh-cn.md#swissmemoryresource) enables further flexibility through a customizable fixed-size paging reuse mechanism. |
| 10 | + |
| 11 | +## Performance Demonstration |
| 12 | + |
| 13 | +CPU: AMD EPYC 7W83 64-Core Processor, taskset 0-3 core |
| 14 | + |
| 15 | +QPS: 800 |
| 16 | + |
| 17 | +- Default (mode: 0) |
| 18 | + - latency_percentiles: "[2213,2523,3232,3670]" |
| 19 | + - process_cpu_usage : 1.172 |
| 20 | + - process_memory_resident : 44978722 |
| 21 | +- Arena (mode: 1) |
| 22 | + - latency_percentiles: "[1318,1490,1794,1984]" |
| 23 | + - process_cpu_usage : 0.702 |
| 24 | + - process_memory_resident : 41421824 |
| 25 | +- Arena & ArenaString (mode: 1, arenastring patch) |
| 26 | + - latency_percentiles: "[1055,1196,1416,1583]" |
| 27 | + - process_cpu_usage : 0.572 |
| 28 | + - process_memory_resident : 39732770 |
| 29 | +- SwissMemoryResource & ArenaString (mode: 2, arenastring patch) |
| 30 | + - latency_percentiles: "[1006,1139,1341,1478]" |
| 31 | + - process_cpu_usage : 0.551 |
| 32 | + - process_memory_resident : 44763136 |
0 commit comments