Skip to content

Commit

Permalink
Add new actionrunner.stream_output_buf_size config option and use that
Browse files Browse the repository at this point in the history
value for "bufsize" argument inside the Python runner run_command
function call.

For performance reasons, default it to -1, but allow users to change it
via config if they are experiencing performance or similar issues.
  • Loading branch information
Kami committed Oct 29, 2019
1 parent 25ea404 commit 2f96d5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions contrib/runners/python_runner/python_runner/python_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ def run(self, action_parameters):
if stdin_params:
command_string = 'echo %s | %s' % (quote_unix(stdin_params), command_string)

LOG.debug('Running command: PATH=%s PYTHONPATH=%s %s' % (env['PATH'], env['PYTHONPATH'],
command_string))
bufsize = cfg.CONF.actionrunner.stream_output_buffer_size

LOG.debug('Running command (bufsize=%s): PATH=%s PYTHONPATH=%s %s' % (bufsize, env['PATH'],
env['PYTHONPATH'],
command_string))
exit_code, stdout, stderr, timed_out = run_command(cmd=args,
stdin=stdin,
stdout=subprocess.PIPE,
Expand All @@ -261,7 +264,8 @@ def run(self, action_parameters):
read_stderr_func=read_and_store_stderr,
read_stdout_buffer=stdout,
read_stderr_buffer=stderr,
stdin_value=stdin_params)
stdin_value=stdin_params,
bufsize=bufsize)
LOG.debug('Returning values: %s, %s, %s, %s', exit_code, stdout, stderr, timed_out)
LOG.debug('Returning.')
return self._get_output_values(exit_code, stdout, stderr, timed_out)
Expand Down
8 changes: 7 additions & 1 deletion st2common/st2common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,13 @@ def register_opts(ignore_errors=False):
'creates pack virtualenv.'),
cfg.BoolOpt(
'stream_output', default=True,
help='True to store and stream action output (stdout and stderr) in real-time.')
help='True to store and stream action output (stdout and stderr) in real-time.'),
cfg.IntOpt(
'stream_output_buffer_size', default=-1,
help=('Buffer size to use for real time action output streaming. 0 means unbuffered '
'1 means line buffered, -1 means system default, which usually means fully '
'buffered and any other positive value means use a buffer of (approximately) '
'that size'))
]

do_register_opts(action_runner_opts, group='actionrunner')
Expand Down

0 comments on commit 2f96d5d

Please sign in to comment.