python的simple http server跟nginx哪个占用资源更少?


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

选哪个更好?

python nginx web服务器

jobgene 10 years, 3 months ago

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

くぎみや(毒) answered 10 years, 3 months ago

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

o準駙馬o answered 10 years, 3 months ago

我在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的性能才能真正发挥。。。

風卷夕雲秋長波 answered 10 years, 3 months ago

Your Answer