Commit 6c163072 authored by Jim Fulton's avatar Jim Fulton

Optionally use uvloop for clients

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:

  https://github.com/MagicStack/uvloop/issues/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.)
parent cf3abed4
...@@ -18,14 +18,14 @@ matrix: ...@@ -18,14 +18,14 @@ matrix:
python: 2.7 python: 2.7
env: ZEO4_SERVER=1 env: ZEO4_SERVER=1
- os: linux - os: linux
python: 3.4 python: 3.5
env: ZEO4_SERVER=1 env: ZEO4_SERVER=1
- os: linux - os: linux
python: 3.5 python: 3.5
env: ZEO4_SERVER=1 env: BUILOUT_OPTIONS=extra=,uvloop
install: install:
- pip install zc.buildout - pip install zc.buildout
- buildout - buildout $BUILOUT_OPTIONS
cache: cache:
directories: directories:
- eggs - eggs
......
...@@ -2,8 +2,13 @@ from .._compat import PY3 ...@@ -2,8 +2,13 @@ from .._compat import PY3
if PY3: if PY3:
import asyncio import asyncio
try:
from uvloop import new_event_loop
except ImportError:
from asyncio import new_event_loop
else: else:
import trollius as asyncio import trollius as asyncio
from trollius import new_event_loop
from ZEO.Exceptions import ClientDisconnected, ServerException from ZEO.Exceptions import ClientDisconnected, ServerException
import concurrent.futures import concurrent.futures
...@@ -836,7 +841,7 @@ class ClientThread(ClientRunner): ...@@ -836,7 +841,7 @@ class ClientThread(ClientRunner):
def run(self): def run(self):
loop = None loop = None
try: try:
loop = asyncio.new_event_loop() loop = new_event_loop()
self.setup_delegation(loop) self.setup_delegation(loop)
self.started.set() self.started.set()
loop.run_forever() loop.run_forever()
......
...@@ -120,6 +120,7 @@ class SSLConfigTest(ZEOConfigTestBase): ...@@ -120,6 +120,7 @@ class SSLConfigTest(ZEOConfigTestBase):
@mock.patch(('asyncio' if PY3 else 'trollius') + '.async') @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') + '.set_event_loop')
@mock.patch(('asyncio' if PY3 else 'trollius') + '.new_event_loop') @mock.patch(('asyncio' if PY3 else 'trollius') + '.new_event_loop')
@mock.patch('ZEO.asyncio.client.new_event_loop')
class SSLConfigTestMockiavellian(ZEOConfigTestBase): class SSLConfigTestMockiavellian(ZEOConfigTestBase):
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment