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
petelin
V2EX  ›  Python

基于 select+asynico 的基础实现, 上次分享过一个类似的, 这次关注点是 Python 内置包 asynico 是内部是怎么实现这个东西的.

  •  
  •   petelin · 2017-11-02 13:33:47 +08:00 · 2142 次点击
    这是一个创建于 2360 天前的主题,其中的信息可能已经有所发展或是发生改变。
    基于 select+socket+asynico 的基础实现.

    将 asyncio.get_event_loop() 换成自己写的 selfayncio.get_event_loop(), 然后其他调用方法完全一样

    每秒能处理 5000 个 index html 请求. ab 并发 2w 没压力, 好像最高只能写-c 20000?


    <script src=".js"></script>
    3 条回复    2017-11-02 21:27:52 +08:00
    petelin
        1
    petelin  
    OP
       2017-11-02 13:40:23 +08:00
    root@env-pay:~# siege -b -c 200 http://127.0.0.1:8080/
    ** SIEGE 3.0.8
    ** Preparing 200 concurrent users for battle.
    The server is now under siege...^C
    Lifting the server siege... done.

    Transactions: 422665 hits
    Availability: 100.00 %
    Elapsed time: 73.83 secs
    Data transferred: 12.50 MB
    Response time: 0.03 secs
    Transaction rate: 5724.84 trans/sec
    Throughput: 0.17 MB/sec
    Concurrency: 199.12
    Successful transactions: 422665
    Failed transactions: 0
    Longest transaction: 3.22
    Shortest transaction: 0.00
    godymho
        2
    godymho  
       2017-11-02 21:19:13 +08:00
    asynico 跟 多个客户端建立连接之后,服务端如何主动跟客户端发送 tcp 包呢?
    petelin
        3
    petelin  
    OP
       2017-11-02 21:27:52 +08:00
    直接创建一个 task, 然后在里面写逻辑就行了,

    create_task(muti_handler(client_socket))

    更多是通过 epoll 来调度你的服务器处理函数, 想清楚怎么调度就好了...

    我写的这个, 就是不管客户端发什么过来, 我都直接 return html, 其实处理逻辑都可以和以前一样的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5359 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:56 · PVG 16:56 · LAX 01:56 · JFK 04:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.