#create #applications #thread #concurrency #behind #thread-based

ehttpd

基于线程的 HTTP 服务器库,可用于创建自定义 HTTP 服务器应用程序

18 个版本

0.8.2 2024年6月16日
0.8.1 2024年1月28日
0.7.2 2024年1月24日
0.6.2 2023年11月25日
0.4.3 2023年3月20日

#123HTTP 服务器

27 每月下载量
2 crates 中使用

BSD-2-Clause OR MIT

51KB
1K SLoC

License BSD-2-Clause License MIT AppVeyor CI docs.rs crates.io Download numbers dependency status

ehttpd

欢迎来到 ehttpd 🎉

ehttpd 是一个基于线程的 HTTP 服务器库,可用于创建自定义 HTTP 服务器应用程序。

基于线程的设计

采用基于线程的方法的原因是,与 async/await 相比,它更容易实现,需要更少的代码,并且在理论上错误更少。

此外,它还简化了应用程序的开发,因为开发者不会意外地通过单个阻塞调用阻止整个运行时 - 由操作系统调度器管理,线程提供了更强的并发隔离保证(在大多数环境中,如果需要,甚至可以进行 nice 或调整)。

性能

虽然基于线程的方法不是最有效的,但也不是最差的。一些 wrk 基准测试

MacBook Pro (M1 Pro, helloworld, v0.7.1)

$ wrk -t 64 -c 64 https://127.0.0.1:9999/testolope
Running 10s test @ https://127.0.0.1:9999/testolope
  64 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     1.00ms  520.00us  27.29ms   95.96%
    Req/Sec     1.02k   262.37     6.00k    94.81%
  654074 requests in 10.10s, 32.44MB read
Requests/sec:  64756.19
Transfer/sec:      3.21MB

旧 Linux 机器 (Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz, helloworld-nokeepalive, v0.7.0)

$ wrk -t 64 -c 64 https://127.0.0.1:9999/testolope
Running 10s test @ https://127.0.0.1:9999/testolope
  64 threads and 64 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     2.22ms    1.00ms  60.93ms   95.30%
    Req/Sec   435.19     56.94     1.00k    85.05%
  278046 requests in 10.10s, 18.83MB read
Requests/sec:  27528.42
Transfer/sec:      1.86MB

依赖项

~225KB