设为首页 加入收藏

TOP

6.5.3 muduo 与Nginx 的吞吐量对比(1)
2013-10-07 16:04:01 来源: 作者: 【 】 浏览:73
Tags:6.5.3 muduo Nginx 吞吐量 对比

6.5.3 muduo 与Nginx 的吞吐量对比(1)

本节简单对比了Nginx 1.0.12 和muduo 0.3.1 内置的简陋HTTP 服务器的长连接性能。其中muduo 的HTTP 实现和测试代码位于muduo/net/http/。

测试环境

服务端,运行HTTP server,8 核DELL 490 工作站,Xeon E5320 CPU。

客户端,运行ab 22 和weighttp 23,4 核i5-2500 CPU。

网络:普通家用千兆网。

测试方法为了公平起见,Nginx 和muduo 都没有访问文件,而是直接返回内存中的数据。毕竟我们想比较的是程序的网络性能,而不是机器的磁盘性能。另外,这里客户机的性能优于服务机,因为我们要给服务端HTTP server 施压,试图使其饱和,而不是测试HTTP client 的性能。

muduo HTTP 测试服务器的主要代码:

  1. muduo/net/http/tests/HttpServer_test.cc  
  2. void onRequest(const HttpRequest& req, HttpResponse* resp)  
  3. {  
  4. if (req.path() == "/") {  
  5. // ...  
  6. } else if (req.path() == "/hello") {  
  7. resp->setStatusCode(HttpResponse::k200Ok);  
  8. resp->setStatusMessage("OK");  
  9. resp->setContentType("text/plain");  
  10. resp->addHeader("Server", "Muduo");  
  11. resp->setBody("hello, world!\n");  
  12. } else {  
  13. resp->setStatusCode(HttpResponse::k404NotFound);  
  14. resp->setStatusMessage("Not Found");  
  15. resp->setCloseConnection(true);  
  16. }  
  17. }  
  18. int main(int argc, char* argv[])  
  19. {  
  20. int numThreads = 0;  
  21. if (argc > 1)  
  22. {  
  23. benchmark = true;  
  24. Logger::setLogLevel(Logger::WARN);  
  25. numThreads = atoi(argv[1]);  
  26. }  
  27. EventLoop loop;  
  28. HttpServer server(&loop, InetAddress(8000), "dummy");  
  29. server.setHttpCallback(onRequest);  
  30. server.setThreadNum(numThreads);  
  31. server.start();  
  32. loop.loop();  
  33. }  
  34. muduo/net/http/tests/HttpServer_test.cc 

Nginx 使用了章亦春的HTTP echo 模块24 来实现直接返回数据。配置文件如下:
  1. #user nobody;  
  2. worker_processes 4;  
  3. events {  
  4. worker_connections 10240;  
  5. }  
  6. http {  
  7. include mime.types;  
  8. default_type application/octet-stream;  
  9. access_log off;  
  10. sendfile on;  
  11. tcp_nopush on;  
  12. keepalive_timeout 65;  
  13. server {  
  14. listen 8080;  
  15. server_name localhost;  
  16. location / {  
  17. root html;  
  18. index index.html index.htm;  
  19. }  
  20. location /hello {  
  21. default_type text/plain;  
  22. echo "hello, world!";  
  23. }  
  24. }  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇6.5.2 击鼓传花:对比muduo 与lib.. 下一篇6.5.3 muduo 与Nginx 的吞吐量对..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 C 语言或者限制使 (2025-12-25 08:50:05)
·C++构造shared_ptr为 (2025-12-25 08:50:01)
·既然引用计数在做 GC (2025-12-25 08:49:59)
·Java 编程和 c 语言 (2025-12-25 08:19:48)
·. net内存管理宝典这 (2025-12-25 08:19:46)