Threads Versus Greenlets in Python Networking Library Gevent
In a previous post, I gave an introduction to gevent to show some of the benefits your application might get from using gevent greenlets instead of threads. Some people, however, took issue with my benchmark code, saying that the threaded example was contrived. In this post, I'll try to answer some of the objections.
(It actually turns out that there was a bug in the version of ab I was using to test, as well, so I re-ran the tests from the previous post, too.)
Threads versus Greenlets
Initially, I had proposed a dummy webserver that handled incoming requests by creating a thread and delegating communication to that thread. The code in question is below:
02.s = socket.socket()
03.s.bind(('0.0.0.0', port))
04.s.listen(500)
05.while True:
06.cli, addr = s.accept()
07.t = threading.Thread(target=handle_request, args=(cli, time.sleep))
08.t.daemon = True
09.t.start()
(It actually turns out that there was a bug in the version of ab I was using to test, as well, so I re-ran the tests from the previous post, too.)
Threads versus Greenlets
Initially, I had proposed a dummy webserver that handled incoming requests by creating a thread and delegating communication to that thread. The code in question is below:
CODE:
01.def threads(port):02.s = socket.socket()
03.s.bind(('0.0.0.0', port))
04.s.listen(500)
05.while True:
06.cli, addr = s.accept()
07.t = threading.Thread(target=handle_request, args=(cli, time.sleep))
08.t.daemon = True
09.t.start()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-737271/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python中gevent協程庫Python
- Python gevent 是如何 patch 標準庫的 ?Python
- CLR Threads and Windows ThreadsthreadWindows
- Fossil: Fossil Versus GitGit
- Unity Networking API文件翻譯(一):Networking概述UnityAPI
- 初試Gevent – 高效能的Python併發框架Python框架
- linux networkingLinux
- 基於協程的Python網路庫gevent介紹Python
- Gevent 排程流程解析
- Calico 組網(Networking)
- Conventional Path Export Versus Direct Path ExportExport
- networking常用命令
- 一起讀 Gevent 原始碼原始碼
- gevent 學習筆記 —— 協程筆記
- Tenacity -- Retrying library for PythonPython
- 執行緒 threads執行緒thread
- python多執行緒非同步爬蟲-Python非同步爬蟲試驗[Celery,gevent,requests]Python執行緒非同步爬蟲
- python-多工,簡易的協程gevent的安裝與使用例程Python
- Common threads: Awk by examplethread
- mormot.core.threads--TSynQueueORMthread
- mormot.core.threads--TSynParallelProcessORMthreadParallel
- 《碧藍幻想:Versus》的創新戰鬥系統
- 正則式 REGEX - Python re libraryPython
- Simplifying Graphics With Java and Threads (轉)Javathread
- MySQL 5.5 -- innodb_purge_threadsMySqlthread
- mormot.core.threads--TBlockingProcessORMthreadBloC
- mormot.core.threads--TSynThreadORMthread
- mormot.core.threads--TSynThreadPoolORMthread
- mormot.core.threads.pas unitORMthread
- <Learning How to Learn>Week One: Focused versus Diffuse ThinkingThinking
- 使用socket+gevent實現協程併發
- python協程(yield、asyncio標準庫、gevent第三方)、非同步的實現Python非同步
- 《碧藍幻想Versus》評測:粉絲說香,那就夠了
- Threads in Node 10.5.0: a practical introthread
- Java 8 併發: Threads 和 ExecutorsJavathread
- android ddms裡邊看threadsAndroidthread
- mormot.core.threads--TSynBackgroundThreadMethodORMthread
- Networking from the container's point of view 筆記AIView筆記