This project benchmarks two different approaches to implementing an HTTP-to-Kafka API server in Rust. The server receives JSON payloads via HTTP, processes them, and sends the data to a Kafka topic. The two implementations compare the performance of using:
tokio-uring
with raw TCP streams (low-level, high-performance I/O based onio_uring
).hyper
with thetokio
runtime (high-level HTTP framework).
tokio_server
: A server using the Tokio runtime.io_uring_server
: A server using the io_uring interface.benches/benchmark.rs
: Contains the benchmarking code.Cargo.toml
: Project dependencies and configuration.
The project contains the following implementations:
- Uses
tokio-uring
for asynchronous I/O with raw TCP streams. - Manually parses HTTP requests and extracts the JSON payload from the body.
- Sends the extracted JSON payload to Kafka using the
rdkafka
library. - Designed for maximum performance and efficiency by directly interfacing with the
io_uring
system call.
- Uses
hyper
, a high-level HTTP framework built ontokio
. - Automatically parses HTTP requests and provides abstractions for handling JSON payloads.
- Sends the JSON payload to Kafka using the
rdkafka
library. - Easier to use but comes with higher overhead due to HTTP abstractions.
criterion
: For benchmarking.hyper
: HTTP client library.tokio
: Asynchronous runtime.
- The server listens for incoming requests on a specific port (
8080
forhyper
,8081
fortokio-uring
). - Each client sends a POST request with a JSON payload (e.g.,
{"data": "test_payload"}
). - The server processes the payload and forwards it to a Kafka topic (
test_topic_io_uring
fortokio-uring
,test_topic_tokio
forhyper
). - The server responds with
Payload received
after processing the request.
The Kafka setup uses the rdkafka
library to:
- Produce messages to the Kafka topic.
- Retry automatically in case of transient errors.
To run the benchmarks, use the following command:
cargo bench