Skip to content

Commit 2f96d5d

Browse files
committed
Add new actionrunner.stream_output_buf_size config option and use that
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.
1 parent 25ea404 commit 2f96d5d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

contrib/runners/python_runner/python_runner/python_runner.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ def run(self, action_parameters):
248248
if stdin_params:
249249
command_string = 'echo %s | %s' % (quote_unix(stdin_params), command_string)
250250

251-
LOG.debug('Running command: PATH=%s PYTHONPATH=%s %s' % (env['PATH'], env['PYTHONPATH'],
252-
command_string))
251+
bufsize = cfg.CONF.actionrunner.stream_output_buffer_size
252+
253+
LOG.debug('Running command (bufsize=%s): PATH=%s PYTHONPATH=%s %s' % (bufsize, env['PATH'],
254+
env['PYTHONPATH'],
255+
command_string))
253256
exit_code, stdout, stderr, timed_out = run_command(cmd=args,
254257
stdin=stdin,
255258
stdout=subprocess.PIPE,
@@ -261,7 +264,8 @@ def run(self, action_parameters):
261264
read_stderr_func=read_and_store_stderr,
262265
read_stdout_buffer=stdout,
263266
read_stderr_buffer=stderr,
264-
stdin_value=stdin_params)
267+
stdin_value=stdin_params,
268+
bufsize=bufsize)
265269
LOG.debug('Returning values: %s, %s, %s, %s', exit_code, stdout, stderr, timed_out)
266270
LOG.debug('Returning.')
267271
return self._get_output_values(exit_code, stdout, stderr, timed_out)

st2common/st2common/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,13 @@ def register_opts(ignore_errors=False):
376376
'creates pack virtualenv.'),
377377
cfg.BoolOpt(
378378
'stream_output', default=True,
379-
help='True to store and stream action output (stdout and stderr) in real-time.')
379+
help='True to store and stream action output (stdout and stderr) in real-time.'),
380+
cfg.IntOpt(
381+
'stream_output_buffer_size', default=-1,
382+
help=('Buffer size to use for real time action output streaming. 0 means unbuffered '
383+
'1 means line buffered, -1 means system default, which usually means fully '
384+
'buffered and any other positive value means use a buffer of (approximately) '
385+
'that size'))
380386
]
381387

382388
do_register_opts(action_runner_opts, group='actionrunner')

0 commit comments

Comments
 (0)