gevent 的异步 StreamServer

测试环境windows + python + gevent,有条件的朋友可以采用pypy测试。


code:

# -*- coding: UTF-8 -*-
from gevent.monkey import patch_all;patch_all()
from gevent.server import StreamServer


def main(socket,address):
    socket.recv(4096)
    socket.send("HTTP/1.1 200 OK\n\n<h1>Hello World!</h1>")



if __name__ == '__main__':
    Server = StreamServer(("192.168.1.190",80),main)
    Server.serve_forever()
    #Server.close()


测试工具(ab):

    

[root@test ~]# ab -c 200 -n 5000000  http://192.168.1.190/

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.190 (be patient)
Completed 500000 requests
Completed 1000000 requests
Completed 1500000 requests
Completed 2000000 requests
Completed 2500000 requests
Completed 3000000 requests
Completed 3500000 requests
Completed 4000000 requests
Completed 4500000 requests
Completed 5000000 requests
Finished 5000000 requests


Server Software:
Server Hostname:        192.168.1.190
Server Port:            80

Document Path:          /
Document Length:        21 bytes

Concurrency Level:      200
Time taken for tests:   493.025 seconds
Complete requests:      5000000
Failed requests:        0
Write errors:           0
Total transferred:      190000000 bytes
HTML transferred:       105000000 bytes
Requests per second:    10141.48 [#/sec] (mean)
Time per request:       19.721 [ms] (mean)
Time per request:       0.099 [ms] (mean, across all concurrent requests)
Transfer rate:          376.34 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   1.2      0      16
Processing:     3   19   3.8     18     136
Waiting:        1   19   3.8     18     136
Total:          3   20   3.8     19     138

Percentage of the requests served within a certain time (ms)
  50%     19
  66%     20
  75%     21
  80%     21
  90%     23
  95%     26
  98%     29
  99%     33
 100%    138(longest request)
 
[root@test ~]#



你可能感兴趣的:(gevent 的异步 StreamServer)