NXWEB何许人也?莫非来自星星的你?
好吧,其实NXWEB是C语言写的一个超快超轻量级的web服务器,就这么简单。作者:Yaroslav Stavnichiy,官网
也许有人会有疑问,webserver领域既然已经有老牌劲旅Apache,新科状元Nginx,我们还需要其他web服务器吗?其实互联网的复杂性总会产生各种各样的需求,比如功能单一,简洁,追求高并发,占用系统性能少,超轻量级的web服务还是有一定的市场。
比如:广告曝光展现引擎,它会根据预定义的配置调用多次站点的每一页上产生的小HTML片段,这种应用如何实现呢?
CGI应该不是一个好的选择,因为它处理每个请求都需要进行加载和卸载操作,极大影响了请求的处理速度。当然可以在一些主流web服务器,比如Apache,nginx上面编写模块,以提供更好的性能,但是上述web服务器的API也不是非常完美,甚至不是很友好,这样NXWEB上场啦!
NXWEB拥有怎样的特性敢叫板其他webserver?
- 能提供最好的性能,详见压力测试数据
- 能够处理数上万的并发请求
- 占用极少内存
- event驱动,多线程模块开发
- 异常代码库
- API简单明了
- 良好的HTTP协议处理
- 支持长连接
- 支持SSL(基于GNUTLS)
- 支持非阻塞传输文件(支持可配置的小文件内存缓存)
- 可缓存gzip编码的内容
- 可缓存图像缩略图水印(通过ImageMagick)
- 模块化设计,方便开发人员进行模块开发
- 可以作为守护进程运行
压力测试数据:
NXWEB 3.0 Benchmarks
NXWEB v3 is even faster than v2.
Results are in thousands requests per second. F = failed. NA = not supported. Measured by httpress on 4-core CPU (without AES-NI).
Test | NXWEB | G-WAN | libevent | microhttpd | mongoose | nginx |
---|---|---|---|---|---|---|
1. hello 100 ka | 200 / 121 | 144 | 30 / 69 | 132 | 190 | 141 |
2. hello 100 | 51 / 42 | 41 | 15 / 32 | 13 | 34 | 41 |
3. hello 1000 ka | 160 / 115 | 130 | 21 / 43 | 130 | 180 | 124 |
4. hello 1000 | 46 / 38 | 38 | 14 / 30 | 12 | 35 | 40 |
5. hello 10000 ka | 115 / 84 | 103 | 23 / 40 | 116 | 119 | 108 |
5.1. real concurrency | 9500-10000 | 9500-10000 | 10000 | 600-1000 | 1500-1700 | 4000-7000 |
5.2. memory footprint | 28Mb | 105Mb | – | – | – | 4x15Mb |
6. hello 10000 | 38 / 34 | 33 | 14 / 27 | 9 | 20 | 29 |
7. file 2.3K ka | 133 | NA | NA | NA | 5 | 98 |
7.1. file 2.3K ka cached | 145 | 120 | NA | NA | NA | NA |
8. file 2.3K | 42 | NA | NA | NA | 12 | 39 |
8.1. file 2.3K cached | 43 | 33 | NA | NA | NA | NA |
9. file 100K ka | 36 | 15 | NA | NA | 3.6 | 32 |
10. file 100K | 23 | 12 | NA | NA | 3.5 | 21 |
11. file 2.1M ka | 3.2 | 0.7 | NA | NA | 0.6 | 2.6 |
12. file 2.1M | 2.3 | 0.6 | NA | NA | 0.5 | 2.0 |
Test descriptions:
Minimal handler returning '<p>Hello, world!</p>'; 100 concurrent, keep-alive (httpress -c 100 -n 1000000 -t 4 -k) Minimal handler returning '<p>Hello, world!</p>'; 100 concurrent, no keep-alive (httpress -c 100 -n 500000 -t 4) Minimal handler returning '<p>Hello, world!</p>'; 1000 concurrent, keep-alive (httpress -c 1000 -n 1000000 -t 4 -k) Minimal handler returning '<p>Hello, world!</p>'; 1000 concurrent, no keep-alive (httpress -c 1000 -n 500000 -t 4) Minimal handler returning '<p>Hello, world!</p>'; 10000 concurrent, keep-alive (httpress -c 10000 -n 1000000 -t 4 -k) httpress tool allows to calculate real concurrency, the number of actually active connections participating in test 10K concurrent connections take a lot of RAM. Here you can see how much Minimal handler returning '<p>Hello, world!</p>'; 10000 concurrent, no keep-alive (httpress -c 10000 -n 500000 -t 4) Disk file 2.3 KiB; 400 concurrent connections, keep-alive Disk file 2.3 KiB; 400 concurrent connections, keep-alive, using memory cache Disk file 2.3 KiB; 400 concurrent connections, no keep-alive Disk file 2.3 KiB; 400 concurrent connections, no keep-alive, using memory cache Disk file 100 KiB; 400 concurrent connections, keep-alive Disk file 100 KiB; 400 concurrent connections, no keep-alive Disk file 2.1 MiB; 400 concurrent connections, keep-alive Disk file 2.1 MiB; 400 concurrent connections, no keep-alive
开源其他的压力测试数据:
Server | Version | Req/s | % of httpd static | Notes |
---|---|---|---|---|
nxweb static file | 3.2.0-dev | 512,767 | 347.1 % | “memcache”:false. (626,270 if true) |
nginx static file | 1.0.15 | 430,135 | 291.1 % | stock CentOS 6.3 rpm |
httpd static file | 2.4.4, mpm_event | 147,746 | 100.0 % | |
mod_python handler | 3.5, Python 2.7.5 | 125,139 | 84.7 % | |
uWSGI | 1.9.18.2 | 119,175 | 80.7 % | -p 16 –threads 1 |
mod_python wsgi | 3.5, Python 2.7.5 | 87,304 | 59.1 % | |
mod_wsgi | 3.4 | 76,251 | 51.6 % | embedded mode |
nxweb wsgi | 3.2.0-dev, Python 2.7.5 | 15,141 | 10.2 % | posibly misconfigured? |
看看上述数据,爱折腾的ops们不想尝试一下?
nginx不是web服务器,nginx的web服务器功能是nginx的内置模块,谢谢