Actix-web是一个Rust中的高性能的Web服务器,采用Actor模型,性能极高,功能完善,适合生成环境,代码如下。
首先添加依赖:1
2[dependencies]
actix-web = "4.12.1"
创建文件src/main.rs:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15use actix_web::{get, App, HttpResponse, HttpServer, Responder};
async fn hello() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(hello))
.bind(("127.0.0.1", 3000))?
.workers(1)
.run()
.await
}
测试一下,结果如下:1
2冷启动速度:3.6ms
内存占用:4MB
- 本文作者: killf
- 本文链接: https://www.killf.info/编程语言/Rust/Rust中的Web服务器-高性能的Actix-web/
- 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!