Reuse channels

store a cache of the channels so a single pid can re-use a connection
this needs to be per pid as when you fork you keep the original memory
space and we can't control currency across pids
This commit is contained in:
Thomas Jackson 2014-02-08 15:36:38 -08:00
parent 44fa27ab7e
commit 2c0a878a06

View File

@ -5,9 +5,14 @@ Encapsulate the different transports available to Salt. Currently this is only
import salt.payload
import salt.auth
import os
class Channel(object):
# store a cache of the channels so a single pid can re-use a connection
# this needs to be per pid as when you fork you keep the original memory
# space and we can't control currency across pids
channel_cache = {}
@staticmethod
def factory(opts, **kwargs):
# Default to ZeroMQ for now
@ -19,7 +24,10 @@ class Channel(object):
ttype = opts['pillar']['master']['transport_type']
if ttype == 'zeromq':
return ZeroMQChannel(opts, **kwargs)
pid = os.getpid()
if pid not in Channel.channel_cache:
Channel.channel_cache[pid] = ZeroMQChannel(opts, **kwargs)
return Channel.channel_cache[pid]
else:
raise Exception("Channels are only defined for ZeroMQ")
# return NewKindOfChannel(opts, **kwargs)