Skip to content

Commit

Permalink
Optionally use uvloop for clients
Browse files Browse the repository at this point in the history
uvloop is a bit faster than the standard asyncion event loop.

Unfortunately, there's an issue with the ZEO tests and using uvloop in
the ZEO server:

  MagicStack/uvloop#39

Fortunately, most of the performamce benefits of using uvloop seems to
be in the client.

For now, we'll just use ivloop on the client side, as the incremental
effort of using it in the server aren't worth futher wrestling with
the tests. (I spent quite a bit of time just narrowing down the cause
of the test issue.)

With this PR, if uvloop can be imported, it will be used for the
client. (uvloop requires Python 3.5 or later and doesn't support Windows.)
  • Loading branch information
Jim Fulton committed Aug 8, 2016
1 parent cf3abed commit 6c16307
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ matrix:
python: 2.7
env: ZEO4_SERVER=1
- os: linux
python: 3.4
python: 3.5
env: ZEO4_SERVER=1
- os: linux
python: 3.5
env: ZEO4_SERVER=1
env: BUILOUT_OPTIONS=extra=,uvloop
install:
- pip install zc.buildout
- buildout
- buildout $BUILOUT_OPTIONS
cache:
directories:
- eggs
Expand Down
7 changes: 6 additions & 1 deletion src/ZEO/asyncio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

if PY3:
import asyncio
try:
from uvloop import new_event_loop
except ImportError:
from asyncio import new_event_loop
else:
import trollius as asyncio
from trollius import new_event_loop

from ZEO.Exceptions import ClientDisconnected, ServerException
import concurrent.futures
Expand Down Expand Up @@ -836,7 +841,7 @@ def __init__(self, addrs, client, cache,
def run(self):
loop = None
try:
loop = asyncio.new_event_loop()
loop = new_event_loop()
self.setup_delegation(loop)
self.started.set()
loop.run_forever()
Expand Down
1 change: 1 addition & 0 deletions src/ZEO/tests/testssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def test_ssl_pw(self):
@mock.patch(('asyncio' if PY3 else 'trollius') + '.async')
@mock.patch(('asyncio' if PY3 else 'trollius') + '.set_event_loop')
@mock.patch(('asyncio' if PY3 else 'trollius') + '.new_event_loop')
@mock.patch('ZEO.asyncio.client.new_event_loop')
class SSLConfigTestMockiavellian(ZEOConfigTestBase):

@mock.patch('ssl.create_default_context')
Expand Down

0 comments on commit 6c16307

Please sign in to comment.