Eurasia3, 我把恶魔带临人间了吗?
本次发布仍然使用 Python 标准库 asyncore.py 的算法, 优化阶段还未开始, 性能尚待提高。
这里提供部分简单功能的预览, 及简单的基准测试 (Apache ab)。欢迎讨论。
代码一, "hello world!"
-------------------------------------------------------
代码:
#!/usr/bin/env python2.5
#import psyco; psyco.full()
from web import Response, config, poll
def controller(req):
resp = Response(req)
resp['Content-Type'] = 'text/plain'
print >> resp, 'hello world!'
resp.close()
config(controller=controller, port=8080)
while True:
poll()
-------------------------------------------------------
基准测试 1:
$ ab -c 1021 -n 10000 'http://localhost:8080/'
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 13 bytes
Concurrency Level: 1021
Time taken for tests: 2.84486 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1770885 bytes
HTML transferred: 130065 bytes
Requests per second: 4797.35 [#/sec] (mean)
Time per request: 212.826 [ms] (mean)
Time per request: 0.208 [ms] (mean, across all concurrent
requests)
Transfer rate: 829.46 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 3.5 1 24
Processing: 9 26 3.4 26 230
Waiting: 7 25 3.4 25 228
Total: 25 27 4.7 27 231
Percentage of the requests served within a certain time (ms)
50% 27
66% 27
75% 27
80% 27
90% 28
95% 28
98% 45
99% 50
100% 231 (longest request)
-------------------------------------------------------
基准测试 2, 使用 psyco.full() 优化:
$ ab -c 1021 -n 10000 'http://localhost:8080/'
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 13 bytes
Concurrency Level: 1021
Time taken for tests: 1.519026 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 1770708 bytes
HTML transferred: 130052 bytes
Requests per second: 6583.17 [#/sec] (mean)
Time per request: 155.093 [ms] (mean)
Time per request: 0.152 [ms] (mean, across all concurrent
requests)
Transfer rate: 1138.23 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 4.0 1 25
Processing: 10 18 3.6 19 239
Waiting: 9 17 3.5 17 237
Total: 18 20 5.6 20 241
Percentage of the requests served within a certain time (ms)
50% 20
66% 20
75% 20
80% 20
90% 21
95% 21
98% 46
99% 47
100% 241 (longest request)
代码 2: Eurasia3 自带 Demo
-------------------------------------------------------
启动 demo:
$ ./demo start
功能:
使用了逻辑调度器, 每 0.1 秒对协程进行一次调度。
使用了 session, 在测试中为每个请求建立一份 session (共计 10000 份)。
-------------------------------------------------------
基准测试:
$ ab -c 1021 -n 10000 'http://localhost:8080/'
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 8 bytes
Concurrency Level: 1021
Time taken for tests: 8.923888 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2521500 bytes
HTML transferred: 80688 bytes
Requests per second: 1120.59 [#/sec] (mean)
Time per request: 911.129 [ms] (mean)
Time per request: 0.892 [ms] (mean, across all concurrent
requests)
Transfer rate: 275.89 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 252 823.2 5 3011
Processing: 130 186 89.0 170 921
Waiting: 129 182 89.1 165 915
Total: 143 438 877.6 176 3929
$ cat /proc/version
Linux version 2.6.20-16-generic (root@terranova) (gcc version 4.1.2
(Ubuntu 4.1.2-0ubuntu4)) #2 SMP Sun Sep 23 19:50:39 UTC 2007
$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 75
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 3600+
stepping : 2
cpu MHz : 2009.283
cache size : 256 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext
fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8legacy
ts fid vid ttp tm stc
bogomips : 4021.64
clflush size : 64
processor : 1
vendor_id : AuthenticAMD
cpu family : 15
model : 75
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 3600+
stepping : 2
cpu MHz : 2009.283
cache size : 256 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext
fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm cr8legacy
ts fid vid ttp tm stc
bogomips : 4018.57
clflush size : 64