玩蛇网提供最新Python编程技术信息以及Python资源下载!

请问python simple http server与nginx比较,占用资源更少是哪个

只有设备上的一个浏览器访问, 不会有大量客户端连我的这个http server.

选哪个更好?

我在Win8上测试的,nginx 1.5.8,Python 2.7.6
同一个网站,nginx跑在80上,Python SimpleHTTPServer跑在7777上。
没有任何访问的时候nginx占用2.1MB,Python占用7.6MB,如下图:

我使用ab同时对两个服务进行测试,两者的内存占用方面都没有变化,估计是我的测试页面不够大的缘故,但是CPU占用方面nginx高于SimpleHTTPServer,如下图:

但同时nginx的效果比SimpleHTTPServer高很多,下面是ab的报告:
ngixn:

Server Software:        nginx/1.5.8
Server Hostname:        172.16.0.102
Server Port:            80

Document Path:          /reader.html
Document Length:        4132 bytes

Concurrency Level:      1
Time taken for tests:   30.000 seconds
Complete requests:      8919
Failed requests:        0
Write errors:           0
Total transferred:      38940354 bytes
HTML transferred:       36853308 bytes
Requests per second:    297.30 [#/sec] (mean)
Time per request:       3.364 [ms] (mean)
Time per request:       3.364 [ms] (mean, across all concurrent requests)
Transfer rate:          1267.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    1   0.2      1       6
Processing:     2    3   0.9      2      30
Waiting:        1    2   0.9      2      29
Total:          2    3   1.0      3      30
WARNING: The median and mean for the processing time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      3
  75%      4
  80%      4
  90%      4
  95%      5
  98%      5
  99%      6
 100%     30 (longest request)
Finished 2749 requests

SimpleHTTPServer

Server Software:        SimpleHTTP/0.6
Server Hostname:        172.16.0.102
Server Port:            7777

Document Path:          /reader.html
Document Length:        4132 bytes

Concurrency Level:      1
Time taken for tests:   30.001 seconds
Complete requests:      2749
Failed requests:        0
Write errors:           0
Total transferred:      11870182 bytes
HTML transferred:       11358868 bytes
Requests per second:    91.63 [#/sec] (mean)
Time per request:       10.914 [ms] (mean)
Time per request:       10.914 [ms] (mean, across all concurrent requests)
Transfer rate:          386.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    1   0.2      1       5
Processing:     2   10  35.0      4     846
Waiting:        1    8  34.6      3     844
Total:          3   11  35.0      5     847

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      7
  75%      8
  80%     10
  90%     17
  95%     29
  98%     55
  99%     86
 100%    847 (longest request)

nginx的效率是SimpleHTTPServer的4倍左右,另外需要提的是SimpleHTTP在并发的时候经常出现卡死的情况,它毕竟只是一个测试用的服务,使用需谨慎。这win下的结果,linux下,ng的性能才能真正发挥。。。

人家都说了,它叫simple嘛。。。

Nginx,永远不要将语言自带 Server 放到你的生产环境。

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd18800.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年05月22日 - 11时35分56秒 发布自玩蛇网

您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容
我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules