高性能Web服务器-Lwan
Lwan 是一个高性能和可伸缩的 Web 服务器软件,支持 glibc/Linux 平台。经历了将近3年的开发时间,目前还是个人究的成果。主要是为了构建一个坚固、轻量级高性能的 Web 服务器。采用C语言开发并在GPLv2协议下授权。
Lwan is a high-performance & scalable web server for glibc/Linux platforms.
特点
占用内存低 (1万个空闲连接只占用 ~500KiB)
最小化的内存分配和拷贝
最小化的系统调用
精确的 HTTP 请求解析
使用最高效的方法来处理文件服务
大于 16k 的文件不需要进行核心和用户层的拷贝
更小的文件使用内存映射缓冲向量 I/O 发送
处理压缩小文件时考虑Header 开销
大多数无等待、多线程设计
核心代码只有 7200 行左右
Low memory footprint (~500KiB for 10k idle connections)
Minimal memory allocations & copies
Minimal system calls
Hand-crafted HTTP request parser
Static file serving uses the most efficient way according to file size
No copies between kernel and userland for files larger than 16KiB
Smaller files are sent using vectored I/O
Header overhead is considered before considering deflate compression
Mostly wait-free multi-threaded design
One thread accepts connections, one I/O thread per logical CPU handles them
Hand-crafted coroutines makes asynchronous I/O a breeze in C
Linux only, as it relies on epoll()
Purpose-built I/O loop
Efficient loading cache used for
Directory listing
File information (size, last modified date, MIME type, etc)
Compressed files
Diminute codebase with roughly 7200 lines of C code
性能
在一台使用 i7 处理器的笔记本上可以达到每秒 32 万无磁盘访问的 HTTP 请求。当访问磁盘,测试文件在 16Kb 时可达到每秒 29 万个请求;而更大的文件可到每秒 18.5 万请求。以上测试使用 keep-alive 连接,如果不使用 keep-alive 这个数字可能降低 6 倍左右。
下图是不同并发连接数测试的每秒请求数:

其中绿线是使用如下示例代码的 Hello world 扩展应用,棕色线是 100 字节的文件。
最新版本:
官方主页:http://lwan.ws/