Difference between revisions of "Eventlet"

From Second Life Wiki
Jump to navigation Jump to search
(→‎Limitations: Processes not working on windows)
 
(21 intermediate revisions by 6 users not shown)
Line 1: Line 1:
= Eventlet =
= [http://eventlet.net Eventlet] =


Eventlet is a networking library written in Python. It achieves high scalability by using [http://en.wikipedia.org/wiki/Non-blocking_IO#Select.28.2Fpoll.29_loop non-blocking io] while at the same time retaining high programmer usability by using [http://en.wikipedia.org/wiki/Coroutine coroutines] to make the non-blocking io operations appear blocking at the source code level.
Eventlet is a networking library written in Python. It achieves high scalability and concurrency by using [http://en.wikipedia.org/wiki/Non-blocking_IO#Select.28.2Fpoll.29_loop non-blocking io] while at the same time retaining high programmer usability by using [http://en.wikipedia.org/wiki/Coroutine coroutines] to make the non-blocking io operations appear blocking at the source code level.


* Example code: [[Eventlet/Examples]]
* [http://blog.eventlet.net/ Blog]
* Subversion repository: http://svn.secondlife.com/svn/eventlet
* [http://eventlet.net/doc/ Documentation]
* Trac page: http://svn.secondlife.com/trac/eventlet
* [https://lists.secondlife.com/pipermail/eventletdev/ Mailing List Archives]
* Mailing list: https://lists.secondlife.com/cgi-bin/mailman/listinfo/eventletdev
* [http://eventlet.net/hudson/ Automated Builds]
* [http://bitbucket.org/which_linden/eventlet/issues/new/ Bug Report Form]
* [irc://chat.freenode.net/#eventlet irc channel]


== Releases ==


{| cellpadding="6"
Linden Lab open-sourced Eventlet [http://blogs.secondlife.com/community/features/blog/2007/08/25/more-open-source-our-web-services-libraries in 2007], and it's been under continuous development since.  Several applications have been built on top of Eventlet, such as [http://pypi.python.org/pypi/Spawning/ Spawning] and [http://pypi.python.org/pypi/proxylet/ Proxylet].
|-
| '''Name''' || '''Date''' || '''Zip''' || '''SVN'''
|-
| beta-1 || Aug 24, 2007 || [http://svn.secondlife.com/trac/eventlet/changeset/8/branches/beta-1?old_path=%2F&format=zip] || [http://svn.secondlife.com/svn/eventlet/branches/beta-1]
|}


== Requirements ==
== Other resources ==
 
[http://soundfarmer.com/content/slides/coroutines-nonblocking-io-eventlet-spawning/coros,%20nonblocking%20i:o,%20eventlet,%20spawning.pdf Article talks about coros, eventlet and spawning]
Eventlet runs on Python version 2.3 or greater, with the following dependenceis:
* [http://cheeseshop.python.org/pypi/greenlet greenlet]
* (if running python versions < 2.4) a deque object in a <code>collections</code> module.  One option is to copy [http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/259179 this deque] into a file called <code>collections.py</code>.
 
== Eventlet at Linden ==
 
eventlet is the networking library used to implement the [[backbone]] architecture.  Backbone is primarily an http server, and as such uses the eventlet.httpd module. eventlet itself is responsible only for handling http protocol-level semantics; "web framework" concepts such as URL traversal and html rendering are implemented in a separate python package, [[mulib]].
 
== Files ==
Files with a corresponding _test.py unit test are called out in '''bold''' in these lists.
 
=== API ===
* '''[[Eventlet/api.py | api.py]]''' :  Exposes all of the most important apis from eventlet, such as apis for managing threads of control (api.spawn) and apis for managing network sockets. Contains 9 apis intended for external use.
* [[Eventlet/backdoor.py | backdoor.py]] : Implements a Python REPL over a raw socket, suitable for use by telnetting in to the port and screwing around with the live state of the application.
* [[Eventlet/channel.py | channel.py]] : Channel is the main scheduling primitive. It is a Queue pattern with send and recieve methods. It is used for synchronizing across coroutines.
* '''[[Eventlet/coros.py | coros.py]]''' : Coroutine communication tools, such as events (like channels, but only for a single use), and a coroutine pool.
* [[Eventlet/httpc.py | httpc.py]] : Nonblocking http client, and a client factory that can make content-swizzling clients.
* '''[[Eventlet/httpd.py | httpd.py]]''' : HTTP server written by Donovan. Should probably be merged with wsgi
* [[Eventlet/httpdate.py | httpdate.py]] : Very small utility module for formatting http dates. This module should grow http date parsing code and code for dealing with conversion to and from utc as well, but currently does not.
* [[Eventlet/jsonhttp.py | jsonhttp.py]] : Http client that transparently converts python data structures to and from [http://json.org/ json].
* '''[[Eventlet/pools.py | pools.py]]''' :  Implements pooled resources.  Coroutines that try to get items from a depleted pool block until another coroutine puts a resource back in the pool.
* '''[[Eventlet/processes.py | processes.py]]''' : Implements popen-like process objects for communicating with external programs.
* [[Eventlet/wsgi.py | wsgi.py]] : An implementation of a wsgi (web services gateway interface) (http) server. Not used by linden; should be merged with httpd.
 
 
=== Core implementation details ===
* [[Eventlet/greenlib.py | greenlib.py]] : Private implementation module which adds the concept of a "tracked" greenlet: A greenlet that is notified as it is being scheduled or unscheduled. Used by backdoor to swizzle stdin and stdout during context switches so that input and output always goes to the right place.
* '''[[Eventlet/runloop.py | runloop.py]]''' : Generic runloop which when combined with the appropriate "hub" for the current architecture forms the main loop of eventlet. Manages lists of observers for the runloop states: ['entry', 'before_timers', 'before_waiting', 'after_waiting', 'exit'] along with managing all timers.
* '''[[Eventlet/timer.py | timer.py]]''' : Timers track code which is scheduled to be run after some timeout. Usually this module is not used directly, but is used indirectly through the api.sleep call
* [[Eventlet/util.py | util.py]] : A bunch of utilities for operating on socket objects. Could probably be factored better.
* [[Eventlet/wrappedfd.py | wrappedfd.py]] : A socket object which cooperates with the main loop to yield control of the current coroutine each time a socket read or write operation occurs.
 
 
=== "EventHub" implementations ===
* [[Eventlet/kqueuehub.py | kqueuehub.py]] : An event hub which uses kqueue. Used on OS X and FreeBSD.
* [[Eventlet/pollhub.py | pollhub.py]] : An event hub which uses the poll() call.
* [[Eventlet/selecthub.py | selecthub.py]] : An event hub which uses the select() call.
 
 
=== Misc ===
 
* [[Eventlet/logutil.py | logutil.py]] : Mish-mash of utilities for simplifying the use of the python standard "logging" module and for logging using syslog.
* [[Eventlet/tests.py | tests.py]] : A place to keep test utilities.  Lightly used, but it will become more useful as test coverage grows.
* [[Eventlet/tls.py | tls.py]] : Thread-local storage implementation for Python 2.3.
 
 
=== Supporting modules ===
 
* [[Eventlet/pylibsupport.py | pylibsupport.py]] : Supports using the "greenlet" present at py.magic.greenlet in the py.lib instead of the python egg packaged greenlet from the cheeseshop.
* [[Eventlet/twistedsupport.py | twistedsupport.py]] : Support for using eventlet with twisted. See http://twistedmatrix.com. Currently broken.
* [[Eventlet/stacklesssupport.py | stacklesssupport.py]] : Support for using eventlet with stackless instead of greenlet. Currently broken.
 
== Limitations ==
 
* Sorely lacking in documentation
** Please help by adding to the wiki documentation, and submitting patches with more and better docstrings for the source.
* Not enough test coverage -- the goal is 100%, but we are not there yet.
* Eventlet does not currently run on stackless using tasklets, though it is a goal to do so in the future.
** If you're familiar with the stackless architecture, take a look at <code>stacklesssupport.py</code> and see if you can wrangle it to get one of the example programs running on top of stackless.
* The SSL client does not properly connect to the SSL server, though both client and server interoperate with other SSL implementations (e.g. curl and apache).
** We could use a) a unit test that reproduces the bug (rather than the hand-testing we have been doing) and b) a fix for said bug.
* Not tested on Windows
** There are probably some simple Unix dependencies we introduced by accident.  If you're running Eventlet on Windows and run into errors, let us know.
** The eventlet.processes module is known to not work on Windows.
 
== Eventlet History ==
 
Eventlet began life as Donovan Preston was talking to Bob Ippolito about coroutine-based non-blocking networking frameworks in Python. Most non-blocking frameworks require you to run the "main loop" in order to perform all network operations, but Donovan wondered if a library written using a trampolining style could get away with transparently running the main loop any time i/o was required, stopping the main loop once no more i/o was scheduled. Bob spent a few days during PyCon 2005 writing a proof-of-concept. He named it eventlet, after the coroutine implementation it used, [http://cheeseshop.python.org/pypi/greenlet greenlet]. Donovan began using eventlet as a light-weight network library for his spare-time project [http://soundfarmer.com/Pavel/trunk/ Pavel], and also began writing some unittests.
 
* http://svn.red-bean.com/bob/eventlet/trunk/
 
When Donovan started at Linden Lab in May of 2006, he added eventlet as an svn external in the indra/lib/python directory, to be a dependency of the yet-to-be-named [[backbone]] project (at the time, it was named restserv). However, including eventlet as an svn external meant that any time the externally hosted project had hosting issues, Linden developers were not able to perform svn updates. Thus, the eventlet source was imported into the linden source tree at the same location, and became a fork.
 
Bob Ippolito has ceased working on eventlet and has stated his desire for Linden to take it's fork forward to the open source world as "the" eventlet.

Latest revision as of 22:53, 12 February 2010

Eventlet

Eventlet is a networking library written in Python. It achieves high scalability and concurrency by using non-blocking io while at the same time retaining high programmer usability by using coroutines to make the non-blocking io operations appear blocking at the source code level.


Linden Lab open-sourced Eventlet in 2007, and it's been under continuous development since. Several applications have been built on top of Eventlet, such as Spawning and Proxylet.

Other resources

Article talks about coros, eventlet and spawning