From f73d562fc0ee3ff43f65cc418f213a79a727cb19 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Tue, 11 Apr 2017 16:00:31 +0100 Subject: [PATCH] python: Allow tuning the session probe_interval from IDL This patch is adding a new parameter called "probe_interval" to the constructor of the Idl class. This new parameter will be used to tune the database connection probing for that IDL session, some users might want to tune it to be less agressive than the current 5s default in OVS or even disable it. Reported-at: https://bugs.launchpad.net/networking-ovn/+bug/1680146 Signed-off-by: Lucas Alvares Gomes Acked-by: Daniel Alvarez Signed-off-by: Russell Bryant --- AUTHORS.rst | 1 + python/ovs/db/idl.py | 12 +++++++++--- python/ovs/jsonrpc.py | 11 +++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index c8371dc8d..a8592f063 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -191,6 +191,7 @@ Linda Sun lsun@vmware.com Lior Neudorfer lior@guardicore.com Lorand Jakab lojakab@cisco.com Luca Giraudo lgiraudo@nicira.com +Lucas Alvares Gomes lucasagomes@gmail.com Lucian Petrut lpetrut@cloudbasesolutions.com Luigi Rizzo rizzo@iet.unipi.it Luis E. P. l31g@hotmail.com diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index 079a03ba1..60548bcf5 100644 --- a/python/ovs/db/idl.py +++ b/python/ovs/db/idl.py @@ -94,7 +94,7 @@ class Idl(object): IDL_S_MONITOR_REQUESTED = 1 IDL_S_MONITOR_COND_REQUESTED = 2 - def __init__(self, remote, schema): + def __init__(self, remote, schema, probe_interval=None): """Creates and returns a connection to the database named 'db_name' on 'remote', which should be in a form acceptable to ovs.jsonrpc.session.open(). The connection will maintain an in-memory @@ -112,7 +112,12 @@ class Idl(object): As a convenience to users, 'schema' may also be an instance of the SchemaHelper class. - The IDL uses and modifies 'schema' directly.""" + The IDL uses and modifies 'schema' directly. + + If "probe_interval" is zero it disables the connection keepalive + feature. If non-zero the value will be forced to at least 1000 + milliseconds. If None it will just use the default value in OVS. + """ assert isinstance(schema, SchemaHelper) schema = schema.get_idl_schema() @@ -120,7 +125,8 @@ class Idl(object): self.tables = schema.tables self.readonly = schema.readonly self._db = schema - self._session = ovs.jsonrpc.Session.open(remote) + self._session = ovs.jsonrpc.Session.open(remote, + probe_interval=probe_interval) self._monitor_request_id = None self._last_seqno = None self.change_seqno = 0 diff --git a/python/ovs/jsonrpc.py b/python/ovs/jsonrpc.py index 69f7abeb8..09e9c8b0a 100644 --- a/python/ovs/jsonrpc.py +++ b/python/ovs/jsonrpc.py @@ -376,7 +376,7 @@ class Session(object): self.seqno = 0 @staticmethod - def open(name): + def open(name, probe_interval=None): """Creates and returns a Session that maintains a JSON-RPC session to 'name', which should be a string acceptable to ovs.stream.Stream or ovs.stream.PassiveStream's initializer. @@ -387,7 +387,12 @@ class Session(object): If 'name' is a passive connection method, e.g. "ptcp:", the new session listens for connections to 'name'. It maintains at most one connection at any given time. Any new connection causes the previous one (if any) - to be dropped.""" + to be dropped. + + If "probe_interval" is zero it disables the connection keepalive + feature. If non-zero the value will be forced to at least 1000 + milliseconds. If None it will just use the default value in OVS. + """ reconnect = ovs.reconnect.Reconnect(ovs.timeval.msec()) reconnect.set_name(name) reconnect.enable(ovs.timeval.msec()) @@ -397,6 +402,8 @@ class Session(object): if not ovs.stream.stream_or_pstream_needs_probes(name): reconnect.set_probe_interval(0) + elif probe_interval is not None: + reconnect.set_probe_interval(probe_interval) return Session(reconnect, None) -- 2.39.2