Remove asyncio sleep from Worker threads #85
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.
A 0.1 second sleep was introduced in #22 to reduce CPU usage due to the
RXWorker
busy looping. However, this sleep constrains PyTAK from receiving more than 10 messages per seconds. Decreasing the sleep period increases CPU usage again.This commit removes the unneeded sleep from both
RXWorker.run()
andWorker.run()
and allows PyTAK to keep up with received messages in busy TAK environments without undue CPU usage.CPU usage is kept down by ensuring that
Worker
coroutines sleep appropriately:RXWorker.run()
was already sleeping inself.reader.readuntil()
orself.reader.recv()
.TXWorker.run()
, we replaceself.queue.get_nowait()
withself.queue.get()
. We address the reason for usingget_nowait()
by introducing a new method for testing purposes,TXWorker.run_once()
, which `TXWorker.run() calls in a loop.