camera_calibration: Fix excessive CPU usage due to queue synchronization #432
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.
I was getting near 100% CPU usage with cameracalibrator.py even if no images (after then inital one) are being received and no actual processing is taking place.
This appeared to be caused by the queue synchronization code doing
to wait for incoming images. This does not look too unreasonable, but replacing it with proper thread synchronization via locks fixed the excessive CPU usage.
Specifically, I replaced the deque with a slightly modified standard Queue that drops the oldest item instead of raising an exception when adding an item to an already full queue, just like deque. Queue also uses deque internally anyway, so in that sense the performance should be the same.
I also added a
--queue-size
parameter to allow adjustment of the max queue size. I found this useful when calibrating with images from a bag, where you want to use all available frames and set the playback rate as high as possible.Relates to #112 and #121.