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