mini http 实现在 may 上
基于 may 实现的小型 http 服务器
此 crate 来自 tokio_minihttp。
但是,由于使用非常方便,您可以在服务中直接调用 MAY 块 API。
首先,将以下内容添加到您的 Cargo.toml:
may_minihttp = "0.1"然后只需简单地实现您的 http 服务
extern crate may_minihttp;
use std::io;
use may_minihttp::{HttpServer, HttpService, Request, Response};
#[derive(Clone)]
struct HelloWorld;
impl HttpService for HelloWorld {
fn call(&mut self, _req: Request, res: &mut Response) -> io::Result {
res.body("Hello, world!");
Ok(())
}
}
// Start the server in `main`.
fn main() {
let server = HttpServer(HelloWorld).start("0.0.0.0:8080").unwrap();
server.join().unwrap();
}在我的笔记本电脑上,只测试了一个工作线程 可以使用以下命令启动服务器:
$ cargo run --example=hello-world --releasetokio_minihttp
$ wrk http://127.0.0.1:8080 -d 10 -t 1 -c 200
Running 10s test @ http://127.0.0.1:8080
1 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.98ms 284.06us 12.53ms 98.92%
Req/Sec 101.64k 1.76k 103.69k 91.00%
1011679 requests in 10.05s, 99.38MB read
Requests/sec: 100650.94
Transfer/sec: 9.89MBmay_minihttp
$ wrk http://127.0.0.1:8080 -d 10 -t 1 -c 200
Running 10s test @ http://127.0.0.1:8080
1 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 1.70ms 812.42us 20.17ms 97.94%
Req/Sec 117.65k 7.52k 123.40k 88.00%
1171118 requests in 10.08s, 115.04MB read
Requests/sec: 116181.73
Transfer/sec: 11.41MB根据 TechEmpower Framework Benchmark 评测,这是最快的 Web 框架之一。
本项目的许可证为以下两种之一
[dependencies]
暂无开放 Issues,或尚未同步最近议题。