Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a timestamp to the Rook request object.#262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
atheriel wants to merge1 commit intorstudio:main
base:main
Choose a base branch
Loading
fromatheriel:timestamps-in-requests

Conversation

@atheriel
Copy link
Contributor

@atherielatheriel commentedApr 6, 2020
edited
Loading

This PR adds ahttpuv.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:

httpuv::runServer("127.0.0.1",8080,list(call=function(req) {elapsed_ms<- difftime(Sys.time(),req$httpuv.timestamp,units="secs")*1000list(status=200L,headers=list("Content-Type"="text/plain"),body= sprintf("Latency (ms): %.3f\n",elapsed_ms)    )  }))

Importantly, this timestamp is captured when the request is received at the C++ level in the background thread, which has two advantages:

  1. 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.

  2. 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 inhttpuv-based applications, and reduces the overhead of common ways to do so -- e.g. using Plumber hooks.

I'm unsure about whetherhttpuv.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 internalSys.time() implementation, the source is intime.c:currentTime().

@atheriel
Copy link
ContributorAuthor

CI failures seem unrelated.

@wch
Copy link
Collaborator

wch commentedApr 6, 2020

The CI failures are due toRcppCore/Rcpp#1048.

atheriel reacted with thumbs up emoji

Requests objects now have a `httpuv.timestamp` member containing atimestamp compatible with Sys.time().This timestamp is captured when the request is received at the C++ levelin the background thread, which has two advantages:1. We can much more accurately capture the total time the client   actually waits for the request to get processed.2. 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 requestlatency in httpuv-based applications, and reduces the overhead of commonways to do so -- e.g. using Plumber hooks.Signed-off-by: Aaron Jacobs <aaron.jacobs@crescendotechnology.com>
@atherielatherielforce-pushed thetimestamps-in-requests branch fromb16a5f4 toa24c919CompareMay 5, 2021 16:34
@atheriel
Copy link
ContributorAuthor

Tweaked slightly and rebased to fix merge conflicts.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign ourContributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let usrecheck it.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@atheriel@wch@CLAassistant

[8]ページ先頭

©2009-2025 Movatter.jp