1.. _module-pw_rpc-benchmark: 2 3=================== 4pw_rpc Benchmarking 5=================== 6pw_rpc provides tools for stress testing and benchmarking a Pigweed RPC 7deployment and the transport it is running over. Two components are included: 8 9* The pw.rpc.Benchmark service and its implementation. 10* A Python module that runs tests using the Benchmark service. 11 12------------------------ 13pw.rpc.Benchmark service 14------------------------ 15The Benchmark service provides a low-level RPC service for sending data between 16the client and server. The service is defined in ``pw_rpc/benchmark.proto``. 17 18A raw RPC implementation of the benchmark service is provided. This 19implementation is suitable for use in any system with pw_rpc. To access this 20service, add a dependency on ``"$dir_pw_rpc:benchmark"`` in GN or 21``pw_rpc.benchmark`` in CMake. Then, include the service 22(``#include "pw_rpc/benchmark.h"``), instantiate it, and register it with your 23RPC server, like any other RPC service. 24 25The Benchmark service was designed with the Python-based benchmarking tools in 26mind, but it may be used directly to test basic RPC functionality. The service 27is well suited for use in automated integration tests or in an interactive 28console. 29 30Benchmark service 31================== 32.. literalinclude:: benchmark.proto 33 :language: protobuf 34 :lines: 14- 35 36Example 37======= 38.. code-block:: c++ 39 40 #include "pw_rpc/benchmark.h" 41 #include "pw_rpc/server.h" 42 43 constexpr pw::rpc::Channel kChannels[] = { /* ... */ }; 44 static pw::rpc::Server server(kChannels); 45 46 static pw::rpc::BenchmarkService benchmark_service; 47 48 void RegisterServices() { 49 server.RegisterService(benchmark_service); 50 } 51 52Stress Test 53=========== 54.. attention:: 55 This section is experimental and liable to change. 56 57The Benchmark service is also used as part of a stress test of the ``pw_rpc`` 58module. This stress test is implemented as an unguided fuzzer that uses 59multiple worker threads to perform generated sequences of actions using RPC 60``Call`` objects. The test is included as an integration test, and can found and 61be run locally using GN: 62 63.. code-block:: bash 64 65 $ gn desc out //:integration_tests deps | grep fuzz 66 //pw_rpc/fuzz:cpp_client_server_fuzz_test(//targets/host/pigweed_internal:pw_strict_host_clang_debug) 67 68 $ gn outputs out '//pw_rpc/fuzz:cpp_client_server_fuzz_test(//targets/host/pigweed_internal:pw_strict_host_clang_debug)' 69 pw_strict_host_clang_debug/gen/pw_rpc/fuzz/cpp_client_server_fuzz_test.pw_pystamp 70 71 $ ninja -C out pw_strict_host_clang_debug/gen/pw_rpc/fuzz/cpp_client_server_fuzz_test.pw_pystamp 72