Build High-Performance Web Services with Hyperlane

In today's digital era, building high-performance and reliable web services is the goal of every developer. Today, we sincerely recommend Hyperlane, a lightweight and high-performance Rust HTTP server framework designed to simplify your network service development.

Project Overview

Hyperlane is built entirely in pure Rust using the standard library, offering true cross-platform compatibility across Windows, Linux, and macOS---with a consistent API experience on all platforms. It leverages Tokio's asynchronous runtime for seamless network communication without requiring platform-specific dependencies.

Key Features:

  • Supports HTTP request parsing, response building, and TCP communication.
  • Includes middleware support for both requests and responses, as well as WebSocket and Server-Sent Events (SSE) for flexible and efficient real-time communication.
  • A simple and user-friendly API design enables developers to quickly get started and build modern web services.

Quick Start

To begin using Hyperlane, simply add it to your project with the following command:

shell 复制代码
cargo add hyperlane

We also provide a quick-start project, hyperlane-quick-start, to help you quickly set up and run your first Hyperlane application.

Clone the project:

shell 复制代码
git clone https://github.com/eastspire/hyperlane-quick-start.git

Navigate to the project directory:

shell 复制代码
cd hyperlane-quick-start

Run the project:

shell 复制代码
cargo run

You can also run, stop, or restart the service in the background:

shell 复制代码
# Run in the background
cargo run -d

# Stop the service
cargo run stop

# Restart the service
cargo run restart

# Restart in the background
cargo run restart -d

Usage Example

The following example demonstrates how to set up middleware, routing, and WebSocket support in a simple Hyperlane application:

rust 复制代码
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: Context| {
                let param: RouteParams = ctx.get_route_params().await;
                println_success!(format!("{:?}", param));
                println_success!(test_string);
                panic!("Test panic");
            }),
        )
        .await;
    server.run().await.unwrap();
}

Performance Benchmark

We conducted performance benchmarks on Hyperlane to demonstrate its excellent performance. The results below were obtained using wrk and ab tools.

wrk Benchmark

Command:

sh 复制代码
wrk -c360 -d60s http://127.0.0.1:60000/

Results:

Rank Framework QPS
1 Tokio 340130.92
2 Hyperlane 324323.71
3 Rocket 298945.31
4 Rust Stdlib 291218.96
5 Gin (Go) 242570.16
6 Go Stdlib 234178.93
7 Node.js Stdlib 139412.13

ab Benchmark

Command:

sh 复制代码
ab -n 1000000 -c 1000 -r -k http://127.0.0.1:60000/

Results:

Rank Framework QPS
1 Tokio 308596.26
2 Hyperlane 307568.90
3 Rocket 267931.52
4 Rust Stdlib 260514.56
5 Go Stdlib 226550.34
6 Gin (Go) 224296.16
7 Node.js Stdlib 85357.18

License and Contributions

Hyperlane is licensed under the MIT license. For details, please refer to the <license> file. Community contributions are welcome! You can participate by submitting issues or creating pull requests.

If you have any questions or need further assistance, feel free to contact the author: [email protected].

Choose Hyperlane---choose the future of high performance and simplified development. Start your journey today and experience the speed and convenience of Hyperlane!

推荐几款学习编程的免费平台

免费在线开发平台(https://docs.ltpp.vip/LTPP/

探索编程世界的新天地,为学生和开发者精心打造的编程平台,现已盛大开启!这个平台汇集了近4000道精心设计的编程题目,覆盖了C、C++、JavaScript、TypeScript、Go、Rust、PHP、Java、Ruby、Python3以及C#等众多编程语言,为您的编程学习之旅提供了一个全面而丰富的实践环境。

在这里,您不仅可以查看自己的代码记录,还能轻松地在云端保存和运行代码,让编程变得更加便捷。平台还提供了私聊和群聊功能,让您可以与同行们无障碍交流,分享文件,共同进步。不仅如此,您还可以通过阅读文章、参与问答板块和在线商店,进一步拓展您的知识边界。

为了提升您的编程技能,平台还设有每日一题、精选题单以及激动人心的编程竞赛,这些都是备考编程考试的绝佳资源。更令人兴奋的是,您还可以自定义系统UI,选择视频或图片作为背景,打造一个完全个性化的编码环境,让您的编程之旅既有趣又充满挑战。

免费公益服务器(https://docs.ltpp.vip/LTPP-SHARE/linux.html

作为开发者或学生,您是否经常因为搭建和维护编程环境而感到头疼?现在,您不必再为此烦恼,因为一款全新的免费公共服务器已经为您解决了所有问题。这款服务器内置了多种编程语言的编程环境,并且配备了功能强大的在线版VS Code,让您可以随时随地在线编写代码,无需进行任何复杂的配置。
随时随地,云端编码

无论您身在何处,只要有网络连接,就可以通过浏览器访问这款公共服务器,开始您的编程之旅。这种云端编码的便利性,让您的学习或开发工作不再受限于特定的设备或环境。
丰富的编程语言支持

服务器支持包括C、C++、JavaScript、TypeScript、Go、Rust、PHP、Java、Ruby、Python3以及C#等在内的多种主流编程语言,满足不同开发者和学生的需求。无论您是初学者还是资深开发者,都能找到适合自己的编程环境。
在线版VS Code,高效开发

内置的在线版VS Code提供了与本地VS Code相似的编辑体验,包括代码高亮、智能提示、代码调试等功能,让您即使在云端也能享受到高效的开发体验。
数据隐私和安全提醒

虽然服务器是免费的,但为了保护您的数据隐私和安全,我们建议您不要上传任何敏感或重要的数据。这款服务器更适合用于学习和实验,而非存储重要信息。

免费公益MYSQL(https://docs.ltpp.vip/LTPP-SHARE/mysql.html

作为一名开发者或学生,数据库环境的搭建和维护往往是一个复杂且耗时的过程。但不用担心,现在有一款免费的MySQL服务器,专为解决您的烦恼而设计,让数据库的使用变得简单而高效。
性能卓越,满足需求

虽然它是免费的,但性能绝不打折。服务器提供了稳定且高效的数据库服务,能够满足大多数开发和学习场景的需求。
在线phpMyAdmin,管理更便捷

内置的在线phpMyAdmin管理面板,提供了一个直观且功能强大的用户界面,让您可以轻松地查看、编辑和管理数据库。
数据隐私提醒,安全第一

正如您所知,这是一项公共资源,因此我们强烈建议不要上传任何敏感或重要的数据。请将此服务器仅用于学习和实验目的,以确保您的数据安全。

免费在线WEB代码编辑器(https://docs.ltpp.vip/LTPP-WEB-IDE/

无论你是开发者还是学生,编程环境的搭建和管理可能会占用你宝贵的时间和精力。现在,有一款强大的免费在线代码编辑器,支持多种编程语言,让您可以随时随地编写和运行代码,提升编程效率,专注于创意和开发。
多语言支持,无缝切换

这款在线代码编辑器支持包括C、C++、JavaScript、TypeScript、Go、Rust、PHP、Java、Ruby、Python3以及C#在内的多种编程语言,无论您的项目需要哪种语言,都能在这里找到支持。
在线运行,快速定位问题

您可以在编写代码的同时,即时运行并查看结果,快速定位并解决问题,提高开发效率。
代码高亮与智能提示

编辑器提供代码高亮和智能提示功能,帮助您更快地编写代码,减少错误,提升编码质量。

免费二维码生成器(https://docs.ltpp.vip/LTPP-QRCODE/

二维码(QR Code)是一种二维条码,能够存储更多信息,并且可以通过智能手机等设备快速扫描识别。它广泛应用于各种场景,如:
企业宣传

企业可以通过二维码分享公司网站、产品信息、服务介绍等。
活动推广

活动组织者可以创建二维码,参与者扫描后可以直接访问活动详情、报名链接或获取电子门票。
个人信息分享

个人可以生成包含联系方式、社交媒体链接、个人简历等信息的二维码。
电子商务

商家使用二维码进行商品追踪、促销活动、在线支付等。
教育

教师可以创建二维码,学生扫描后可以直接访问学习资料或在线课程。
交通出行

二维码用于公共交通的票务系统,乘客扫描二维码即可进出站或支付车费。 功能强大的二维码生成器通常具备用户界面友好,操作简单,即使是初学者也能快速上手和生成的二维码可以在各种设备和操作系统上扫描识别的特点。

相关推荐
(・Д・)ノ5 分钟前
python打卡day33
开发语言·python
小革36018 分钟前
JAVA批量发送邮件(含excel内容)
开发语言·python·excel
magic 24519 分钟前
AJAX get请求如何提交数据呢?
前端·javascript·ajax
阿梦Anmory19 分钟前
[解决conda创建新的虚拟环境没用python的问题]
开发语言·python·conda
byxdaz24 分钟前
C++ HTTP框架推荐
http
心扬27 分钟前
python容器
开发语言·python
ARM2NCWU1 小时前
安卓原生兼容服务器
android·运维·服务器
程序员葵安1 小时前
【Java Web】1.Maven
前端
我漫长的孤独流浪1 小时前
STL中的Vector(顺序表)
开发语言·c++·算法
i1yo_kiki2 小时前
Ajax快速入门教程
前端·javascript·ajax