-
Notifications
You must be signed in to change notification settings - Fork 100
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
default RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED to 1 #169
default RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED to 1 #169
Conversation
Signed-off-by: Dan Rose <dan@digilabs.io>
b7b47a6
to
b19b3af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I thing the changes are fine, IMO this is only a workaround to a bug in launch
.
If you're launching multiple process with launch
that don't use our logging macros, messages should be still in the correct order. We should maybe explore using PYTHONUNBUFFERED
enviroment variable when running subprocesses ...
src/logging.c
Outdated
if (strcmp(line_buffered, "1") == 0) { | ||
g_force_stdout_line_buffered = true; | ||
if (strcmp(line_buffered, "0") == 0) { | ||
g_force_stdout_line_buffered = false; | ||
} else if (strcmp(line_buffered, "0") != 0 && strcmp(line_buffered, "") != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line should be:
} else if (strcmp(line_buffered, "1") != 0 && strcmp(line_buffered, "") != 0) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thank you!
Signed-off-by: Dan Rose <dan@digilabs.io>
Fair. I think it's both. I wouldn't mind this PR being rejected so long as it was fixed in a different way.
A big part of the situation is splitting diagnostics over different streams. If I were writing my own logging, I would just log everything (even low-priority messages) over |
I will detail a little bit what the problem is: in linux (and probably mac), Other possible workarounds:
|
This is related to ros2/launch#188. |
I don't agree with the statement made in the original ticket:
I doubt that the performance hit is actually tiny. When a program outputs frequent messages I would rather expect the performance hit to be fairly significant. I understand that line buffering results in more convenient to read output but I expect this change to impact performance in an undesired way and therefore am hesitant to change it as is (especially without any further investigation into how it actually effects the performance). Just one external article writing about the performance implications: https://eklitzke.org/stdout-buffering |
@dirk-thomas beat me to it. This was the same reason for defaulting to |
@dirk-thomas, I tested it. It's not a significant performance hit, and to notice it, you'd have to be doing a truly massive amount of logging (the 10k messages in the below examples amount to 2.3 MB of log output). For reference, 100k calls to Line buffering off:
Line buffering on:
Code:
|
The default for buffering of non-interactive terminals is fully buffered. We won't be changing that default since the reason for that default in C as well as Python is performance. While some slowdown might be acceptable in many cases we don't think it should be the default. That being said we happy to make changing the default - either for a specific program or from a launch file - as easy and convenient as possible. Demos / tutorials should explicitly use these options if immediate flushing is desired. Since the current state of the PR changes the default I will go ahead and close it. |
Makes sense. I don’t think this is quite the right fix anymore anyway ;-) |
Saner default logging behavior.
fixes #168