Skip to content

Add benchmark suite comparing Corosio and Asio performance#74

Merged
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:feature/benchmark
Jan 23, 2026
Merged

Add benchmark suite comparing Corosio and Asio performance#74
sgerbino merged 1 commit intocppalliance:developfrom
sgerbino:feature/benchmark

Conversation

@sgerbino
Copy link
Collaborator

@sgerbino sgerbino commented Jan 23, 2026

Implement comprehensive benchmarks for scheduler and socket I/O operations, with equivalent Asio implementations for fair comparison.

Benchmarks added:

  • io_context: handler posting throughput, multi-threaded scaling
  • socket throughput: unidirectional and bidirectional transfer rates
  • socket latency: ping-pong round-trip times and concurrent connections

Directory structure:
bench/
├── common/benchmark.hpp - Shared timing utilities and statistics
├── corosio/ - Corosio benchmarks using capy::task<>
└── asio/ - Asio benchmarks using asio::awaitable<>

Both benchmark suites use coroutines for apples-to-apples comparison. TCP_NODELAY is enabled on all sockets to ensure fair latency measurements.

Also adds socket::native_handle() to expose the underlying file descriptor, enabling socket option configuration (e.g., TCP_NODELAY) from user code.

Summary by CodeRabbit

  • New Features

    • Added a public API to access underlying native socket handles, enabling advanced use cases requiring direct interaction with platform-specific socket descriptors.
  • Chores

    • Enhanced build system to support benchmark compilation configuration.

✏️ Tip: You can customize this high-level summary in your review settings.

Implement comprehensive benchmarks for scheduler and socket I/O operations,
with equivalent Asio implementations for fair comparison.

Benchmarks added:
- io_context: handler posting throughput, multi-threaded scaling
- socket throughput: unidirectional and bidirectional transfer rates
- socket latency: ping-pong round-trip times and concurrent connections

Directory structure:
  bench/
  ├── common/benchmark.hpp    - Shared timing utilities and statistics
  ├── corosio/                - Corosio benchmarks using capy::task<>
  └── asio/                   - Asio benchmarks using asio::awaitable<>

Both benchmark suites use coroutines for apples-to-apples comparison.
TCP_NODELAY is enabled on all sockets to ensure fair latency measurements.

Also adds socket::native_handle() to expose the underlying file descriptor,
enabling socket option configuration (e.g., TCP_NODELAY) from user code.
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

📝 Walkthrough

Walkthrough

The pull request adds native socket handle access through a new platform-dependent public API. A native_handle_type type alias and corresponding native_handle() method are introduced across the socket interface hierarchy, with implementations for both epoll (POSIX) and IOCP (Windows) platforms. CMake benchmarking support is also configured.

Changes

Cohort / File(s) Summary
Build Configuration
CMakeLists.txt
Added conditional benchmarking wiring: when BOOST_COROSIO_BUILD_BENCH is enabled, asio is appended to include libraries and a bench subdirectory is registered.
Public Socket Interface
include/boost/corosio/socket.hpp
Introduced platform-dependent native_handle_type alias (uintptr_t on Windows, int on POSIX). Added pure virtual native_handle() const noexcept to socket_impl base class and corresponding public method to socket class.
POSIX Platform Implementation
src/corosio/src/detail/epoll/sockets.hpp
Updated epoll_socket_impl::native_handle() return type from int to native_handle_type while maintaining const, noexcept, and override qualifiers.
Windows Platform Implementation
src/corosio/src/detail/iocp/sockets.hpp
Added public native_handle() const noexcept override method to win_socket_impl that delegates to internal implementation and casts result to native_handle_type.
Socket Implementation
src/corosio/src/socket.cpp
Implemented socket::native_handle() const noexcept that returns an invalid handle if impl is null, otherwise delegates to impl_.get().native_handle().

Sequence Diagram

sequenceDiagram
    participant Client
    participant socket
    participant socket_impl
    participant Platform as epoll/iocp<br/>Implementation

    Client->>socket: native_handle()
    socket->>socket_impl: Check if impl exists
    alt impl is null
        socket_impl-->>socket: Return invalid handle<br/>(~0ull or -1)
    else impl exists
        socket->>Platform: native_handle()
        Platform->>Platform: Return platform-specific<br/>handle (fd_ or SOCKET)
        Platform-->>socket: native_handle_type
    end
    socket-->>Client: native_handle_type
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A burrow deep where sockets dwell,
Now native handles we can tell!
Cross platform magic, Windows, POSIX too,
With native_handle() shining through!
The rabbit's warren grows more strong,
Each implementation right along!

🚥 Pre-merge checks | ✅ 1 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes adding a benchmark suite, but the changeset primarily adds a native_handle() API to the socket class; benchmarking support is only a secondary configuration change in CMakeLists.txt. Update the title to reflect the primary changes: consider 'Add native_handle() API to socket class and benchmark suite' or focus on the main API addition if that's the core intent.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@cppalliance-bot
Copy link

An automated preview of the documentation is available at https://74.corosio.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-01-23 19:48:06 UTC

@sgerbino sgerbino merged commit 6975574 into cppalliance:develop Jan 23, 2026
26 of 27 checks passed
@sgerbino sgerbino deleted the feature/benchmark branch January 23, 2026 20:57
@coderabbitai coderabbitai bot mentioned this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants