Adds the ability to check the callback queue length for a loop #124
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.
This PR proposes adding a way to check the total number of queued callbacks for a loop.
One of the issues we've encountered with
httpuv
/Plumber APIs (and a anotherlater
-based event loop) is figuring out how "busy" they are. In event-based languages like Node you can easily count how many requests are "in-flight" to determine if they are being serviced fast enough, but I'm not aware of a way to do this in R at present.To enable these kinds of measurements, this PR introduces
loop_queue_length()
(and corresponding C++ APIs). It is similar toloop_empty()
but provides a more granular measure of what remains to be executed. Unlikelist_queue()
, it is an exported function meant to be used externally. I'm happy to take naming suggestions, too.As an example of how it might be used, here is a simple
httpuv
server that emulates an expensive 500ms operation and prints out the length of the remaining queue after each request:You can generate "load" to test this with e.g.
$ wrk -c 5 -t 1 -d 5 http://127.0.0.1:8081/
.The changes include documentation and tests.