Hyperlane: A High-Performance Rust HTTP Server Library
Hyperlane: A High-Performance Rust HTTP Server Library In the realm of web development, the choice of a robust and efficient HTTP server library can significantly impact the performance and scalability of your application. Hyperlane, a lightweight and high-performance Rust HTTP server library, stands out as an exceptional choice for developers seeking to build modern web services. Designed with simplicity and power in mind, Hyperlane simplifies network service development while delivering outstanding performance. Key Features Hyperlane offers a comprehensive feature set that makes it an ideal choice for building web services. It supports HTTP request parsing, response building, and TCP communication, providing developers with the essential tools needed for web development. Beyond the basics, Hyperlane also supports request and response middleware, enabling developers to add custom logic to the request-response cycle. For real-time communication needs, Hyperlane provides support for WebSocket and Server-Sent Events (SSE), allowing for flexible and efficient data exchange between clients and servers. Performance Excellence Performance is a critical factor in the success of any web service. Hyperlane has been meticulously designed and optimized to deliver exceptional performance. Test results highlight its capabilities: When tested with 1000 concurrent requests and a total of 1,000,000 requests, Hyperlane achieved a QPS (Queries Per Second) of 307,568.90, closely matching the performance of Tokio (308,596.26 QPS) and outperforming other frameworks like Rocket (267,931.52 QPS), Rust standard library (260,514.56 QPS), Go standard library (226,550.34 QPS), Gin framework (224,296.16 QPS), and Node standard library (85,357.18 QPS). In another test with 360 concurrent requests sustained over 60 seconds, Hyperlane again demonstrated remarkable performance with a QPS of 324,323.71, slightly behind Tokio (340,130.92 QPS) but ahead of Rocket (298,945.31 QPS), Rust standard library (291,218.96 QPS), Gin framework (242,570.16 QPS), Go standard library (234,178.93 QPS), and Node standard library (139,412.13 QPS). These results underscore Hyperlane's capability to handle high traffic loads efficiently, making it suitable for applications where performance is paramount. Getting Started with Hyperlane Getting started with Hyperlane is straightforward. You can easily add it to your project using the following command: cargo add hyperlane To help you hit the ground running, Hyperlane provides a quick-start project. You can clone it using: git clone https://github.com/ltpp-universe/hyperlane-quick-start.git Once cloned, navigate into the project directory and run: cargo run For background execution, you can use: cargo run -d Stopping and restarting the server can be done with: cargo run stop cargo run restart And for restarting in the background: cargo run restart -d Example Usage Here's a practical example demonstrating how to use Hyperlane to create a simple server with request and response middleware, as well as route handlers: use hyperlane::*; async fn request_middleware(ctx: Context) { let socket_addr: String = ctx.get_socket_addr_or_default_string().await; ctx.set_response_header(SERVER, HYPERLANE) .await .set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE) .await .set_response_header(CONTENT_TYPE, content_type_charset(TEXT_PLAIN, UTF8)) .await .set_response_header(DATE, gmt()) .await .set_response_header("SocketAddr", socket_addr) .await; } async fn response_middleware(ctx: Context) { let _ = ctx.send().await; let request: String = ctx.get_request_string().await; let response: String = ctx.get_response_string().await; ctx.log_info(&request, log_handler) .await .log_info(&response, log_handler) .await; } async fn root_route(ctx: Context) { ctx.set_response_status_code(200) .await .set_response_body("Hello hyperlane => /") .await; } async fn websocket_route(ctx: Context) { let request_body: Vec = ctx.get_request_body().await; let _ = ctx.send_response_body(request_body).await; } #[tokio::main] async fn main() { let server: Server = Server::new(); server.host("0.0.0.0").await; server.port(60000).await; server.enable_nodelay().await; server.log_dir("./logs").await; server.enable_inner_log().await; server.enable_inner_print().await; server.log_size(100_024_000).await; server.http_line_buffer_size(4096).await; server.websocket_buffer_size(4096).await; server.request_middleware(request_middleware).await; server.response_middleware(response_middleware).await; server.route("/", root_route).await; server.route("/websocket", websocket_route).await; let test_string: String = "Hello hyperlane".to_

Hyperlane: A High-Performance Rust HTTP Server Library
In the realm of web development, the choice of a robust and efficient HTTP server library can significantly impact the performance and scalability of your application. Hyperlane, a lightweight and high-performance Rust HTTP server library, stands out as an exceptional choice for developers seeking to build modern web services. Designed with simplicity and power in mind, Hyperlane simplifies network service development while delivering outstanding performance.
Key Features
Hyperlane offers a comprehensive feature set that makes it an ideal choice for building web services. It supports HTTP request parsing, response building, and TCP communication, providing developers with the essential tools needed for web development. Beyond the basics, Hyperlane also supports request and response middleware, enabling developers to add custom logic to the request-response cycle. For real-time communication needs, Hyperlane provides support for WebSocket and Server-Sent Events (SSE), allowing for flexible and efficient data exchange between clients and servers.
Performance Excellence
Performance is a critical factor in the success of any web service. Hyperlane has been meticulously designed and optimized to deliver exceptional performance. Test results highlight its capabilities:
- When tested with 1000 concurrent requests and a total of 1,000,000 requests, Hyperlane achieved a QPS (Queries Per Second) of 307,568.90, closely matching the performance of Tokio (308,596.26 QPS) and outperforming other frameworks like Rocket (267,931.52 QPS), Rust standard library (260,514.56 QPS), Go standard library (226,550.34 QPS), Gin framework (224,296.16 QPS), and Node standard library (85,357.18 QPS).
- In another test with 360 concurrent requests sustained over 60 seconds, Hyperlane again demonstrated remarkable performance with a QPS of 324,323.71, slightly behind Tokio (340,130.92 QPS) but ahead of Rocket (298,945.31 QPS), Rust standard library (291,218.96 QPS), Gin framework (242,570.16 QPS), Go standard library (234,178.93 QPS), and Node standard library (139,412.13 QPS).
These results underscore Hyperlane's capability to handle high traffic loads efficiently, making it suitable for applications where performance is paramount.
Getting Started with Hyperlane
Getting started with Hyperlane is straightforward. You can easily add it to your project using the following command:
cargo add hyperlane
To help you hit the ground running, Hyperlane provides a quick-start project. You can clone it using:
git clone https://github.com/ltpp-universe/hyperlane-quick-start.git
Once cloned, navigate into the project directory and run:
cargo run
For background execution, you can use:
cargo run -d
Stopping and restarting the server can be done with:
cargo run stop
cargo run restart
And for restarting in the background:
cargo run restart -d
Example Usage
Here's a practical example demonstrating how to use Hyperlane to create a simple server with request and response middleware, as well as route handlers:
use hyperlane::*;
async fn request_middleware(ctx: Context) {
let socket_addr: String = ctx.get_socket_addr_or_default_string().await;
ctx.set_response_header(SERVER, HYPERLANE)
.await
.set_response_header(CONNECTION, CONNECTION_KEEP_ALIVE)
.await
.set_response_header(CONTENT_TYPE, content_type_charset(TEXT_PLAIN, UTF8))
.await
.set_response_header(DATE, gmt())
.await
.set_response_header("SocketAddr", socket_addr)
.await;
}
async fn response_middleware(ctx: Context) {
let _ = ctx.send().await;
let request: String = ctx.get_request_string().await;
let response: String = ctx.get_response_string().await;
ctx.log_info(&request, log_handler)
.await
.log_info(&response, log_handler)
.await;
}
async fn root_route(ctx: Context) {
ctx.set_response_status_code(200)
.await
.set_response_body("Hello hyperlane => /")
.await;
}
async fn websocket_route(ctx: Context) {
let request_body: Vec<u8> = ctx.get_request_body().await;
let _ = ctx.send_response_body(request_body).await;
}
#[tokio::main]
async fn main() {
let server: Server = Server::new();
server.host("0.0.0.0").await;
server.port(60000).await;
server.enable_nodelay().await;
server.log_dir("./logs").await;
server.enable_inner_log().await;
server.enable_inner_print().await;
server.log_size(100_024_000).await;
server.http_line_buffer_size(4096).await;
server.websocket_buffer_size(4096).await;
server.request_middleware(request_middleware).await;
server.response_middleware(response_middleware).await;
server.route("/", root_route).await;
server.route("/websocket", websocket_route).await;
let test_string: String = "Hello hyperlane".to_owned();
server
.route(
"/test/:text",
future_fn!(test_string, |ctx| {
let param: RouteParams = ctx.get_route_params().await;
println_success!(format!("{:?}", param));
println_success!(test_string);
panic!("Test panic");
}),
)
.await;
server.run().await.unwrap();
}
This example illustrates setting up a server with middleware for handling requests and responses, defining routes for different endpoints, and utilizing WebSocket functionality.
License and Contribution
Hyperlane is released under the MIT License, which provides a permissive framework for its use and distribution. The license details can be found in the LICENSE file. Contributions to Hyperlane are welcome and encouraged. Developers can participate by opening issues or submitting pull requests to help improve and expand the library's capabilities.
Contact Information
For any questions or inquiries regarding Hyperlane, you can reach out to the author at root@ltpp.vip.
Hyperlane represents a powerful and efficient solution for building modern web services in Rust. Its combination of lightweight design, high performance, and rich feature set makes it a compelling choice for developers looking to create scalable and responsive web applications. By leveraging Hyperlane, developers can focus on delivering value through their application logic while relying on a robust foundation for handling web traffic efficiently.