This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2453 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit fc23fabef99e4da0433fbd2019c23097152c92c4 Author: Stephen Mallette <[email protected]> AuthorDate: Thu Nov 12 14:39:59 2020 -0500 TINKERPOP-2453 Enable websocket compression for python --- CHANGELOG.asciidoc | 2 +- docs/src/reference/gremlin-variants.asciidoc | 16 ++++++++++++---- docs/src/upgrade/release-3.4.x.asciidoc | 11 +++++++++++ .../jython/gremlin_python/driver/tornado/transport.py | 7 +++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 08e6556..03695c6 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -49,7 +49,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Deprecated driver `Channelizer` keep-alive related methods. * Delegate handling of WebSocket handshake to Netty instead of custom code in Java Driver. * Delegate detection of idle connection to Netty instead of custom keep alive logic for `WebSocketChannelizer`. -* Added support for WebSocket frame compression extension ( [RFC7692](https://tools.ietf.org/html/rfc7692) ) for `WebSocketChannelizer` in Java driver. +* Added support for WebSocket frame compression extension ( [RFC7692](https://tools.ietf.org/html/rfc7692) ) for `WebSocketChannelizer` in Java/Python driver. * Added server support for WebSocket compression extension ( [RFC7692](https://tools.ietf.org/html/rfc7692) ). * Fixed bug with Bytecode serialization when `Bytecode.toString()` is used in Javascript. * Fixed "toString" for P and TextP to produce valid script representation from bytecode glv steps containing a string predicate in Javascript. diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc index b3c13cb..417abfc 100644 --- a/docs/src/reference/gremlin-variants.asciidoc +++ b/docs/src/reference/gremlin-variants.asciidoc @@ -770,13 +770,21 @@ can be passed to the `Client` or `DriverRemoteConnection` instance as keyword ar |========================================================= Note that the `transport_factory` can allow for additional configuration of the `TornadoTransport`, which exposes -options to manage `ioloop` timeouts: +options to manage `ioloop` timeouts and compression settings: -```python +[source,python] +---- g = traversal().withRemote( DriverRemoteConnection('ws://localhost:8182/gremlin','g', - transport_factory=lambda: TornadoTransport(read_timeout=10, write_timeout=10))) -``` + transport_factory=lambda: TornadoTransport(read_timeout=10, + write_timeout=10, + compression_options={'compression_level':5,'mem_level':5}))) +---- + +Compression configuration options are described in the +link:https://docs.python.org/3.6/library/zlib.html#zlib.compressobj[zlib documentation]. By default, compression +settings are configured as shown in the above example. + [[gremlin-python-strategies]] === Traversal Strategies diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc index 19ae29e..b96071c 100644 --- a/docs/src/upgrade/release-3.4.x.asciidoc +++ b/docs/src/upgrade/release-3.4.x.asciidoc @@ -80,6 +80,17 @@ const sg = g.withStrategies( See: link:https://issues.apache.org/jira/browse/TINKERPOP-2054[TINKERPOP-2054] +==== WebSocket Compression + +Gremlin Server now supports standard WebSocket compression (per link:https://tools.ietf.org/html/rfc7692[RFC 7692]). +Both the Java and Python drivers support this functionality from the client's perspective. Compression is enabled by +default and should be backward compatible, thus allowing older versions of the driver to connect to newer versions of +the server and vice versa. Using the compression-enabled drivers with a server that also supports that functionality +will greatly reduce network IO requirements. + +See: link:https://issues.apache.org/jira/browse/TINKERPOP-2441[TINKERPOP-2441], +link:https://issues.apache.org/jira/browse/TINKERPOP-2453[TINKERPOP-2453] + ==== Per Request Options With Java it has been possible to pass per-request settings for both scripts and bytecode. While Javascript, Python, diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/tornado/transport.py b/gremlin-python/src/main/jython/gremlin_python/driver/tornado/transport.py index 089a51a..7bf4fe0 100644 --- a/gremlin-python/src/main/jython/gremlin_python/driver/tornado/transport.py +++ b/gremlin-python/src/main/jython/gremlin_python/driver/tornado/transport.py @@ -26,16 +26,19 @@ __author__ = 'David M. Brown ([email protected])' class TornadoTransport(AbstractBaseTransport): - def __init__(self, read_timeout=30, write_timeout=30): + def __init__(self, read_timeout=30, write_timeout=30, + compression_options={'compression_level': 5, 'mem_level': 5}): self._loop = ioloop.IOLoop(make_current=False) + self._ws = None self._read_timeout = read_timeout self._write_timeout = write_timeout + self._compression_options = compression_options def connect(self, url, headers=None): if headers: url = httpclient.HTTPRequest(url, headers=headers) self._ws = self._loop.run_sync( - lambda: websocket.websocket_connect(url)) + lambda: websocket.websocket_connect(url, compression_options=self._compression_options)) def write(self, message): self._loop.run_sync(
