pw_rpc Benchmarking#
Pigweed AI summary: The pw_rpc tool provides stress testing and benchmarking for Pigweed RPC deployment and its transport. It includes the pw.rpc.Benchmark service and a Python module for running tests. The Benchmark service is a low-level RPC service for sending data between the client and server, and it can be used directly to test basic RPC functionality. The service is well suited for use in automated integration tests or in an interactive console. The stress test is implemented as an unguided fuzzer that uses multiple worker threads to perform
pw_rpc provides tools for stress testing and benchmarking a Pigweed RPC deployment and the transport it is running over. Two components are included:
The pw.rpc.Benchmark service and its implementation.
A Python module that runs tests using the Benchmark service.
pw.rpc.Benchmark service#
Pigweed AI summary: The pw.rpc.Benchmark service is a low-level RPC service for sending data between client and server, defined in pw_rpc/benchmark.proto. A raw RPC implementation is provided and can be accessed by adding a dependency in GN or CMake and registering it with the RPC server. The service is designed for use in automated integration tests or in an interactive console. It includes a UnaryEcho and BidirectionalEcho function and is also used as part of a stress test for the pw_rpc module.
The Benchmark service provides a low-level RPC service for sending data between
the client and server. The service is defined in pw_rpc/benchmark.proto
.
A raw RPC implementation of the benchmark service is provided. This
implementation is suitable for use in any system with pw_rpc. To access this
service, add a dependency on "$dir_pw_rpc:benchmark"
in GN or
pw_rpc.benchmark
in CMake. Then, include the service
(#include "pw_rpc/benchmark.h"
), instantiate it, and register it with your
RPC server, like any other RPC service.
The Benchmark service was designed with the Python-based benchmarking tools in mind, but it may be used directly to test basic RPC functionality. The service is well suited for use in automated integration tests or in an interactive console.
Benchmark service#
Pigweed AI summary: The Benchmark service is a protocol buffer service that includes two RPC methods: UnaryEcho and BidirectionalEcho. The service responds to client requests with the payload sent by the client. The Payload message includes a byte payload field.
syntax = "proto3";
package pw.rpc;
service Benchmark {
// The server responds with the payload the client sent.
rpc UnaryEcho(Payload) returns (Payload);
// The server responds to each request payload the client sends. The client
// stops the RPC by cancelling it.
rpc BidirectionalEcho(stream Payload) returns (stream Payload);
}
message Payload {
bytes payload = 1;
}
Example#
Pigweed AI summary: This is a code snippet written in C++ that includes two libraries, pw_rpc/benchmark.h and pw_rpc/server.h. It defines a constant array of rpc channels and a server object that uses those channels. It also creates a benchmark service and registers it with the server.
#include "pw_rpc/benchmark.h"
#include "pw_rpc/server.h"
constexpr pw::rpc::Channel kChannels[] = { /* ... */ };
static pw::rpc::Server server(kChannels);
static pw::rpc::BenchmarkService benchmark_service;
void RegisterServices() {
server.RegisterService(benchmark_service);
}
Stress Test#
Pigweed AI summary: This section describes a stress test for the pw_rpc module using an unguided fuzzer that generates sequences of actions using RPC Call objects. The test is included as an integration test and can be run locally using GN. The section is experimental and subject to change.
Attention
This section is experimental and liable to change.
The Benchmark service is also used as part of a stress test of the pw_rpc
module. This stress test is implemented as an unguided fuzzer that uses
multiple worker threads to perform generated sequences of actions using RPC
Call
objects. The test is included as an integration test, and can found and
be run locally using GN:
$ gn desc out //:integration_tests deps | grep fuzz
//pw_rpc/fuzz:cpp_client_server_fuzz_test(//targets/host/pigweed_internal:pw_strict_host_clang_debug)
$ gn outputs out '//pw_rpc/fuzz:cpp_client_server_fuzz_test(//targets/host/pigweed_internal:pw_strict_host_clang_debug)'
pw_strict_host_clang_debug/gen/pw_rpc/fuzz/cpp_client_server_fuzz_test.pw_pystamp
$ ninja -C out pw_strict_host_clang_debug/gen/pw_rpc/fuzz/cpp_client_server_fuzz_test.pw_pystamp