C10K 要不要求响应时间和 RQS

2014-07-23 14:49:34 +08:00
 mengzhuo
我的应用是bottle 做app, gevent做wsgiserver
简单的echo程序
https://gist.github.com/mengzhuo/89ae5dee035a1985a738

用ab测试自己的app,发现
Requests per second: 2017.96 [#/sec] (mean)
测试时Python进程已经100%了

可这应该根本不算能承受C10K吧....,有什么地方我错了?

···
ab -c 10000 -n 10000 -r http://localhost:8998/echo
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname: localhost
Server Port: 8998

Document Path: /echo
Document Length: 16 bytes

Concurrency Level: 10000
Time taken for tests: 4.956 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1430000 bytes
HTML transferred: 160000 bytes
Requests per second: 2017.96 [#/sec] (mean)
Time per request: 4955.505 [ms] (mean)
Time per request: 0.496 [ms] (mean, across all concurrent requests)
Transfer rate: 281.80 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 832 1042.9 253 3009
Processing: 6 192 284.3 67 1688
Waiting: 2 192 284.3 67 1688
Total: 47 1024 1118.6 789 4682

···
3902 次点击
所在节点    Python
18 条回复
ipconfiger
2014-07-23 14:56:17 +08:00
ab -c 10000 -n 10000 -r http://localhost:8998/echo 你在开玩笑的吧
est
2014-07-23 15:01:46 +08:00
槽点太多。不知道从哪里吐。
mengzhuo
2014-07-23 15:01:51 +08:00
@ipconfiger

C10K = concurrently 10*1000 = 10000 我这数学应该没错吧……
mengzhuo
2014-07-23 15:02:21 +08:00
@est

欢迎来吐……我真是菜鸟……
fanta
2014-07-23 15:35:57 +08:00
c10k指的应该是接入socket的数量, 不包含其它的处理,每个socket都会占用内存的,所以机器的内存太小也不行.
ipconfiger
2014-07-23 16:03:49 +08:00
keep住1W个链接,并不代表每秒能处理1w的请求啊,1W的连接数和1W的QPS是两码事哦
mengzhuo
2014-07-23 16:29:12 +08:00
@ipconfiger
@fanta

原来是这样……
那怎么测试C10K?
只需要
```
[socket.socket().connect(('localhost', 8998)) for x in xrange(10000)]
```
ipconfiger
2014-07-23 16:32:38 +08:00
多找点机器来当客户端,每个客户端1K个连接嘛,然后频繁的发ping pong
mengzhuo
2014-07-23 16:37:03 +08:00
@ipconfiger

我单机链接的……

tcp 0 0 127.0.0.1:8998 127.0.0.1:42207 ESTABLISHED
tcp 0 0 127.0.0.1:34349 127.0.0.1:8998 ESTABLISHED

......

$ netstat -nt | grep 8998 | wc -l
20004

这样算不算C10K了……只要不发数据包,gevent太淡定了,直接hold住了
julyclyde
2014-07-23 16:40:40 +08:00
@mengzhuo C10K在当代本来就不是难事啊,以至于单独去测试“保持10K个连接”已经是没有意义的事了。还是讨论处理请求的能力吧
ipconfiger
2014-07-23 16:43:09 +08:00
@mengzhuo 现在的机器性能来说这都是很easy的,别人都在show单机100W连接了,连接起完了20多G内存就不见了
mengzhuo
2014-07-23 16:51:52 +08:00
@julyclyde
@ipconfiger

原来是遗留的问题
我还是折腾RQS吧

我是双核PC
同样输出一样的HTML模板,单核下,bottle 和 nginx 都只能1300左右RQS,
协程果然牛B

不过nginx升到4 个workers就能1W4 RQS....乖乖起4个线程跑应用好了
mengskysama
2014-07-23 16:55:05 +08:00
CK10 保持住1W链接,ping pong。不能用http来测试。

其实没必要这么测。在另外多启动几台机器启动1000线程不断进行HTTP REQ,这样测试出来更有意义。
mengzhuo
2014-07-23 17:09:38 +08:00
@mengskysama

按你说的方法测试了一下,

其他机子竟然可以有这种响应速度了……

Requests per second: 2487.28 [#/sec] (mean)
Time per request: 40.205 [ms] (mean)
Time per request: 0.402 [ms] (mean, across all concurrent requests)
Transfer rate: 347.34 [Kbytes/sec] received
mengzhuo
2014-07-23 17:15:40 +08:00
最差的机子上也是

Requests per second: 1012.04 [#/sec] (mean)
Time per request: 98.810 [ms] (mean)
Time per request: 0.988 [ms] (mean, across all concurrent requests)
Transfer rate: 5709.52 [Kbytes/sec] received

照这个处理速度和能力……只是访问主页的话能顶住8千万日PV?
wecoders
2014-07-23 17:22:03 +08:00
@mengzhuo 正常情况下,web不会有10k的并发量,200-500差不多了吧?
mengskysama
2014-07-23 17:43:27 +08:00
@mengzhuo 妥妥的,试试flask我印象中结果更快。。。。虽然没啥意义就是了。好像还支持多线程来着
mengskysama
2014-07-23 17:46:18 +08:00
有一个测试。。虽然也是没意义的。
http://www.cnbeta.com/articles/178726.htm

谁好用我用谁,谁文档全用谁,谁更新用谁(最后能打的就那2,3个

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/124090

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX