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
- CLR Threads and Windows ThreadsthreadWindows
- Python gevent 是如何 patch 標準庫的 ?Python
- Unity Networking API文件翻譯(一):Networking概述UnityAPI
- 初試Gevent – 高效能的Python併發框架Python框架
- linux networkingLinux
- 基於協程的Python網路庫gevent介紹Python
- Gevent 排程流程解析
- Conventional Path Export Versus Direct Path ExportExport
- 執行緒 threads執行緒thread
- networking常用命令
- 一起讀 Gevent 原始碼原始碼
- gevent 學習筆記 —— 協程筆記
- Common threads: Awk by examplethread
- python多執行緒非同步爬蟲-Python非同步爬蟲試驗[Celery,gevent,requests]Python執行緒非同步爬蟲
- python-多工,簡易的協程gevent的安裝與使用例程Python
- 《碧藍幻想:Versus》的創新戰鬥系統
- Simplifying Graphics With Java and Threads (轉)Javathread
- MySQL 5.5 -- innodb_purge_threadsMySqlthread
- 正則式 REGEX - Python re libraryPython
- <Learning How to Learn>Week One: Focused versus Diffuse ThinkingThinking
- Threads in Node 10.5.0: a practical introthread
- Java 8 併發: Threads 和 ExecutorsJavathread
- android ddms裡邊看threadsAndroidthread
- 使用socket+gevent實現協程併發
- python協程(yield、asyncio標準庫、gevent第三方)、非同步的實現Python非同步
- 《碧藍幻想Versus》評測:粉絲說香,那就夠了
- Networking from the container's point of view 筆記AIView筆記
- Android Guide Dev 之Processes and ThreadsAndroidGUIIDEdevthread
- 奇怪的All threads (200) are currently busythread
- Python3.4 Tutorial10 - Brief Tour of the Standard LibraryPython
- Networking && Internet 計網學習筆記一筆記
- One of the mosting interesting threads on theserversideRESTthreadServerIDE
- 有關threads中message的問題thread
- Library Cache Pin 及 Library Cache Lock分析
- library cache lock和library cache pin理解
- centOS7 Failed to start LSB Bring up/down networkingCentOSAI
- Unity Networking API文件翻譯(二):The High Level APIUnityAPI