继
Mongoose的功能使用,简单验证其性能。
#ifdef _WIN32
/*
* On windows, if read_set and write_set are empty,
* select() returns "Invalid parameter" error
* (at least on my Windows XP Pro). So in this case,
* we sleep here.
*/
sleep(1);
#endif /* _WIN32 */
} else {
for (sp = ctx->listening_sockets;
sp != NULL; sp = sp->next)
if (FD_ISSET(sp->sock, &read_set))
accept_new_connection(sp, ctx);
}
比对对象:Apache、Nginx与Mongoose;
比对方法:访问简单静态页面;
比对结果:用图表说话如下:
比对结论:Mongoose不适合作为高性能服务器。
关于性能不优的原因,在Mongoose的源码也略有一斑:
源码:http://code.google.com/p/mongoose/source/browse/mongoose.c
1、其中包含很多对Windows的兼容;
2、更关键的是master_thread函数,使用的select方法而非epoll:
if ( select(max_fd + 1, &read_set, NULL, NULL, &tv) < 0) {#ifdef _WIN32
/*
* On windows, if read_set and write_set are empty,
* select() returns "Invalid parameter" error
* (at least on my Windows XP Pro). So in this case,
* we sleep here.
*/
sleep(1);
#endif /* _WIN32 */
} else {
for (sp = ctx->listening_sockets;
sp != NULL; sp = sp->next)
if (FD_ISSET(sp->sock, &read_set))
accept_new_connection(sp, ctx);
}