V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
mengzhuo
V2EX  ›  Python

C10K 要不要求响应时间和 RQS

  •  
  •   mengzhuo · 2014-07-23 14:49:34 +08:00 · 3800 次点击
    这是一个创建于 3573 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我的应用是bottle 做app, gevent做wsgiserver
    简单的echo程序


    用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

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

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

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

    原来是这样……
    那怎么测试C10K?
    只需要
    ```
    [socket.socket().connect(('localhost', 8998)) for x in xrange(10000)]
    ```
    ipconfiger
        8
    ipconfiger  
       2014-07-23 16:32:38 +08:00
    多找点机器来当客户端,每个客户端1K个连接嘛,然后频繁的发ping pong
    mengzhuo
        9
    mengzhuo  
    OP
       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
        10
    julyclyde  
       2014-07-23 16:40:40 +08:00   ❤️ 1
    @mengzhuo C10K在当代本来就不是难事啊,以至于单独去测试“保持10K个连接”已经是没有意义的事了。还是讨论处理请求的能力吧
    ipconfiger
        11
    ipconfiger  
       2014-07-23 16:43:09 +08:00   ❤️ 1
    @mengzhuo 现在的机器性能来说这都是很easy的,别人都在show单机100W连接了,连接起完了20多G内存就不见了
    mengzhuo
        12
    mengzhuo  
    OP
       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
        13
    mengskysama  
       2014-07-23 16:55:05 +08:00   ❤️ 1
    CK10 保持住1W链接,ping pong。不能用http来测试。

    其实没必要这么测。在另外多启动几台机器启动1000线程不断进行HTTP REQ,这样测试出来更有意义。
    mengzhuo
        14
    mengzhuo  
    OP
       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
        15
    mengzhuo  
    OP
       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
        16
    wecoders  
       2014-07-23 17:22:03 +08:00
    @mengzhuo 正常情况下,web不会有10k的并发量,200-500差不多了吧?
    mengskysama
        17
    mengskysama  
       2014-07-23 17:43:27 +08:00
    @mengzhuo 妥妥的,试试flask我印象中结果更快。。。。虽然没啥意义就是了。好像还支持多线程来着
    mengskysama
        18
    mengskysama  
       2014-07-23 17:46:18 +08:00
    有一个测试。。虽然也是没意义的。
    http://www.cnbeta.com/articles/178726.htm

    谁好用我用谁,谁文档全用谁,谁更新用谁(最后能打的就那2,3个
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1022 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:57 · PVG 07:57 · LAX 16:57 · JFK 19:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.