Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix publisher leak #34683

Merged
merged 11 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
import salt.utils.sdb
from salt.utils.locales import sdecode

try:
import psutil
HAS_PSUTIL = True
except ImportError:
HAS_PSUTIL = False
import salt.grains.core

log = logging.getLogger(__name__)

_DFLT_LOG_DATEFMT = '%H:%M:%S'
Expand All @@ -60,6 +67,30 @@
_DFLT_IPC_MODE = 'ipc'
_MASTER_TRIES = 1

def _gather_buffer_space():
'''
Gather some system data and then calculate
buffer space.

Result is in bytes.
'''
if HAS_PSUTIL:
# Oh good, we have psutil. This will be quick.
total_mem = psutil.virtual_memory().total
else:
# We need to load up some grains. This will be slow.
os_data = salt.grains.core.os_data()
grains = salt.grains.core._memdata(os_data)
total_mem = grains['mem_total']
# Return the higher number between 5% of the system memory and 100MB
return min([total_mem * 0.05, 10 << 20])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Return the higher number", but doesn't min return the lower number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I was going too fast. Thanks for catching this!


# For the time being this will be a fixed calculation
# TODO: Allow user configuration
_DFLT_IPC_WBUFFER = _gather_buffer_space() * .5
# TODO: Reserved for future use
_DFLT_IPC_RBUFFER = _gather_buffer_space() * .5

FLO_DIR = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
'daemons', 'flo')
Expand Down Expand Up @@ -444,6 +475,10 @@
# ZMQ HWM for EventPublisher pub socket
'event_publisher_pub_hwm': int,

# IPC buffer size
# Refs https://github.com/saltstack/salt/issues/34215
'ipc_write_buffer': int,

# The number of MWorker processes for a master to startup. This number needs to scale up as
# the number of connected minions increases.
'worker_threads': int,
Expand Down Expand Up @@ -1176,6 +1211,7 @@
'minion_data_cache': True,
'enforce_mine_cache': False,
'ipc_mode': _DFLT_IPC_MODE,
'ipc_write_buffer': _DFLT_IPC_WBUFFER,
'ipv6': False,
'tcp_master_pub_port': 4512,
'tcp_master_pull_port': 4513,
Expand Down Expand Up @@ -1541,6 +1577,7 @@ def _read_conf_file(path):
return conf_opts



def _absolute_path(path, relative_to=None):
'''
Return an absolute path. In case ``relative_to`` is passed and ``path`` is
Expand Down
6 changes: 5 additions & 1 deletion salt/transport/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,10 @@ class IPCMessagePublisher(object):
A Tornado IPC Publisher similar to Tornado's TCPServer class
but using either UNIX domain sockets or TCP sockets
'''
def __init__(self, socket_path, io_loop=None):
def __init__(self, opts, socket_path, io_loop=None):
'''
Create a new Tornado IPC server
:param dict opts: Salt options
:param str/int socket_path: Path on the filesystem for the
socket to bind to. This socket does
not need to exist prior to calling
Expand All @@ -444,6 +445,7 @@ def __init__(self, socket_path, io_loop=None):
for a tcp localhost connection.
:param IOLoop io_loop: A Tornado ioloop to handle scheduling
'''
self.opts = opts
self.socket_path = socket_path
self._started = False

Expand Down Expand Up @@ -505,10 +507,12 @@ def publish(self, msg):

def handle_connection(self, connection, address):
log.trace('IPCServer: Handling connection to address: {0}'.format(address))
log.trace('IPCPublisher write buffer set to: {0}'.format(self.opts['ipc_write_buffer']))
try:
stream = IOStream(
connection,
io_loop=self.io_loop,
max_write_buffer_size = self.opts['ipc_write_buffer']
)
self.streams.add(stream)
except Exception as exc:
Expand Down
2 changes: 2 additions & 0 deletions salt/utils/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ def __init__(self, opts, publish_handler, io_loop=None):
raise

self.publisher = salt.transport.ipc.IPCMessagePublisher(
self.opts,
epub_uri,
io_loop=self.io_loop
)
Expand Down Expand Up @@ -953,6 +954,7 @@ def run(self):
)

self.publisher = salt.transport.ipc.IPCMessagePublisher(
self.opts,
epub_uri,
io_loop=self.io_loop
)
Expand Down