GitLab maintenance scheduled for Tomorrow, 2019-04-24, from 12:00 to 13:00 CDT - Services will be unavailable during this time.

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):
def __init__(self, address):
self.address = address
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.setsockopt(zmq.IDENTITY, self.uuid)
self.socket.connect(address)
......@@ -195,7 +195,7 @@ class UpstreamRPCServer(object):
def __init__(self, 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.bind(address)
......@@ -234,7 +234,7 @@ class UpstreamPubServer(object):
def __init__(self, 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.setsockopt(zmq.LINGER, 0)
self.socket.bind(address)
......@@ -251,7 +251,7 @@ class UpstreamPubClient(object):
def __init__(self, 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.setsockopt(zmq.SUBSCRIBE, '')
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