| 6868 | */ |
| 6869 | template <typename server_t, typename client_t> |
| 6870 | static void rpc(bm::State &state, networking_route_t route, std::size_t batch_size, std::size_t packet_size) { |
| 6871 | |
| 6872 | std::string address_to_listen = route == networking_route_t::loopback_k ? "127.0.0.1" : "0.0.0.0"; |
| 6873 | std::string address_to_talk = route == networking_route_t::loopback_k ? "127.0.0.1" : fetch_public_ip(); |
| 6874 | |
| 6875 | rpc_batch_result stats; |
| 6876 | try { |
| 6877 | // Create server and client |
| 6878 | server_t server(address_to_listen, rpc_port_k, batch_size); |
| 6879 | client_t client(address_to_talk, rpc_port_k, batch_size); |
| 6880 | |
| 6881 | std::thread server_thread(std::ref(server)); |
| 6882 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 6883 | |
| 6884 | // Benchmark round-trip time |
| 6885 | for (auto _ : state) { |
| 6886 | rpc_batch_result batch_stats = client(); |
| 6887 | stats += batch_stats; |
| 6888 | double seconds = |
| 6889 | std::chrono::duration_cast<std::chrono::duration<double>>(batch_stats.batch_latency).count(); |
| 6890 | state.SetIterationTime(seconds); |
| 6891 | } |
| 6892 | |
| 6893 | server.stop(); // Inform the server to stop polling for new packets |
| 6894 | server_thread.join(); // Wait for the server to finish |
| 6895 | server.close(); // Close the server socket and free resources |
| 6896 | } |
| 6897 | catch (std::exception const &e) { |
| 6898 | state.SkipWithError(e.what()); |
| 6899 | } |
| 6900 | |
| 6901 | // Process and report stats |
| 6902 | auto const mean_batch_latency_us = |
| 6903 | stats.received_packets ? to_microseconds(stats.batch_latency).count() * 1.0 / state.iterations() : 0.0; |
| 6904 | auto const mean_packet_latency_us = to_microseconds(stats.batch_latency).count() * 1.0 / stats.received_packets; |
| 6905 | |
| 6906 | state.SetItemsProcessed(stats.sent_packets); |
| 6907 | state.SetBytesProcessed(stats.sent_packets * packet_size); |
| 6908 | state.counters["drop,%"] = 100.0 * (stats.sent_packets - stats.received_packets) / stats.sent_packets; |
| 6909 | state.counters["mean_batch_latency,us"] = mean_batch_latency_us; |
| 6910 | state.counters["mean_packet_latency,us"] = mean_packet_latency_us; |
| 6911 | state.counters["max_packet_latency,us"] = to_microseconds(stats.max_packet_latency).count(); |
| 6912 | } |
| 6913 | |
| 6914 | static void rpc_libc(bm::State &state, networking_route_t route, std::size_t batch_size, std::size_t packet_size) { |
| 6915 | return rpc<rpc_libc_server, rpc_libc_client>(state, route, batch_size, packet_size); |
nothing calls this directly
no test coverage detected