Changed listener to not busy-wait #13157
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe problem solved by the proposed pull request
Under certain circumstances, when running the
listener
command with the-n
argument, it would incorrectly timeout. For example, by usinguorb top
, I can see that thetelemetry_status
message is being published once per second. However, when runninglistener telemetry_status -n 100
, I receive two messages, then the messageWaited for 2 seconds without a message. Giving up.
Test data / coverage
I ran a series of
listener
commands on different topics, with every possible combination of the-i
,-r
, and-n
parameters.Describe your preferred solution
I suspect that the issue had something to do with the
listener
performing a busy-wait between messages, therefore using up all available CPU. This can be demonstrated by runninglistener cpuload -n 10
and observing that the load on every message except for the first is 100%. So, I changed thelistener
to poll on messages asynchronously. This fixed the issue withtelemetry_status
.Additional context
Some work has been done recently on the listener, in #12799 and #13006 .