Charles-François Natali added the comment:

I just realized that using DefaultSelector isn't optimal for Connection:
It's fine for forkserver, since it's a long lived process, but for
Connection.poll(), this means that it'll use epoll or kqueue: which
means allocating a new epoll/kqueue object for each conn.poll().
That's a couple syscalls more (epoll_create()/epoll_ctl()/close()),
but most important it uses an extra FD per connection.

The attached patch uses PollSelector if available, otherwise SelectSelector.

----------
Added file: http://bugs.python.org/file31629/connection_selector.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18934>
_______________________________________
diff -r 3070fdd58645 Lib/multiprocessing/connection.py
--- a/Lib/multiprocessing/connection.py Fri Sep 06 13:08:08 2013 -0400
+++ b/Lib/multiprocessing/connection.py Fri Sep 06 20:45:04 2013 +0200
@@ -878,13 +878,21 @@
 
     import selectors
 
+    # poll/select have the advantage of not requiring any extra file
+    # descriptor, contrarily to epoll/kqueue. Also, they're a bit faster for
+    # short-lived polling, since they require a single syscall.
+    if hasattr(selectors, 'PollSelector'):
+        _WaitSelector = selectors.PollSelector
+    else:
+        _WaitSelector = selectors.SelectSelector
+
     def wait(object_list, timeout=None):
         '''
         Wait till an object in object_list is ready/readable.
 
         Returns list of those objects in object_list which are ready/readable.
         '''
-        with selectors.DefaultSelector() as selector:
+        with _WaitSelector() as selector:
             for obj in object_list:
                 selector.register(obj, selectors.EVENT_READ)
 
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to