Add a timestamp to the Rook request object. #262
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 adds a
httpuv.timestamp
member containing a timestamp compatible withSys.time()
to the Rook request object. You can use these timestamps it to measure and report on request latency:Importantly, this timestamp is captured when the request is received at the C++ level in the background thread, which has two advantages:
We can much more accurately capture the total time the client actually waits for the request to get processed, especially if the R thread is congested or running GC.
We can instrument the time it takes before the R-level callback actually runs.
More broadly, the timestamp makes it easier to log measures of request latency in
httpuv
-based applications, and reduces the overhead of common ways to do so -- e.g. using Plumber hooks.I'm unsure about whether
httpuv.timestamp
is a good name, and am happy to take suggestions for improvements.Also, I have little faith in my C++ (though I've made sure to use C++11-compatible interfaces here).
Finally, if you're interested in R's internal
Sys.time()
implementation, the source is intime.c:currentTime()
.