Commit 0d73d31b authored by Swann Perarnau's avatar Swann Perarnau

[fix] use the same zmq context for all objects

pyzmq recommends the use of a single context for all objects in the same
application:
https://pyzmq.readthedocs.io/en/latest/api/zmq.html#zmq.Context.instance

More importantly, each context creates at least one thread, resulting in
a lot of threads with a lot of open file descriptors. This path reduces
that number by quite a bit.
parent fb396383
Pipeline #5101 passed with stages
in 5 minutes and 52 seconds
...@@ -162,7 +162,7 @@ class UpstreamRPCClient(object): ...@@ -162,7 +162,7 @@ class UpstreamRPCClient(object):
def __init__(self, address): def __init__(self, address):
self.address = address self.address = address
self.uuid = str(uuid.uuid4()) self.uuid = str(uuid.uuid4())
self.zmq_context = zmq.Context() self.zmq_context = zmq.Context.instance()
self.socket = self.zmq_context.socket(zmq.DEALER) self.socket = self.zmq_context.socket(zmq.DEALER)
self.socket.setsockopt(zmq.IDENTITY, self.uuid) self.socket.setsockopt(zmq.IDENTITY, self.uuid)
self.socket.connect(address) self.socket.connect(address)
...@@ -195,7 +195,7 @@ class UpstreamRPCServer(object): ...@@ -195,7 +195,7 @@ class UpstreamRPCServer(object):
def __init__(self, address): def __init__(self, address):
self.address = address self.address = address
self.zmq_context = zmq.Context() self.zmq_context = zmq.Context.instance()
self.socket = self.zmq_context.socket(zmq.ROUTER) self.socket = self.zmq_context.socket(zmq.ROUTER)
self.socket.bind(address) self.socket.bind(address)
...@@ -234,7 +234,7 @@ class UpstreamPubServer(object): ...@@ -234,7 +234,7 @@ class UpstreamPubServer(object):
def __init__(self, address): def __init__(self, address):
self.address = address self.address = address
self.zmq_context = zmq.Context() self.zmq_context = zmq.Context.instance()
self.socket = self.zmq_context.socket(zmq.PUB) self.socket = self.zmq_context.socket(zmq.PUB)
self.socket.setsockopt(zmq.LINGER, 0) self.socket.setsockopt(zmq.LINGER, 0)
self.socket.bind(address) self.socket.bind(address)
...@@ -251,7 +251,7 @@ class UpstreamPubClient(object): ...@@ -251,7 +251,7 @@ class UpstreamPubClient(object):
def __init__(self, address): def __init__(self, address):
self.address = address self.address = address
self.zmq_context = zmq.Context() self.zmq_context = zmq.Context.instance()
self.socket = self.zmq_context.socket(zmq.SUB) self.socket = self.zmq_context.socket(zmq.SUB)
self.socket.setsockopt(zmq.SUBSCRIBE, '') self.socket.setsockopt(zmq.SUBSCRIBE, '')
self.socket.connect(address) self.socket.connect(address)
......
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