Skip to content

Additional stats #1017

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 25, 2016
Merged

Additional stats #1017

merged 6 commits into from
Aug 25, 2016

Conversation

deweerdt
Copy link
Member

@deweerdt deweerdt commented Aug 8, 2016

This commit adds duration and jemalloc statistics, both are optional:
jemalloc is enabled at compile time and the duration statistics are
enabled by a 'duration-stats' configuration keyword.
The commit also adds a total number of connections counter.

Duration statistics build on the existing per request duration stats
that are available for logging, each observation is stored in a
structure that allows computing quantiles. When the status page is
queried, values for the minimal, 25th, 50th, 75th and 99th percentile
are output.

{
int32_t delta_sec = (int32_t)until->tv_sec - (int32_t)from->tv_sec;
int32_t delta_usec = (int32_t)until->tv_usec - (int32_t)from->tv_usec;
int64_t delta = (int64_t)(delta_sec * 1000*1000L) + delta_usec;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to convert either of delta_sec or 1000*1000L to int64_t before multiplication, so that the operation would be done in 64-bit on ILP32.

@kazuho
Copy link
Member

kazuho commented Aug 12, 2016

Thank you for the PR. The design looks fine, and I think the proposed feature would be a great addition to H2O.

I have left several comments in-line, please let me know how you think.

This commit adds duration and jemalloc statistics, both are optional:
jemalloc is enabled at compile time and the duration statistics are
enabled by a 'duration-stats' configuration keyword.
The commit also adds a total number of connections counter.

Duration statistics build on the existing per request duration stats
that are available for logging, each observation is stored in a
structure that allows computing quantiles. When the status page is
queried, values for the minimal, 25th, 50th, 75th and 99th percentile
are output.
  - h2o_timeval_substract
  - h2o_timeval_is_null
- Wrap all jemalloc code in a big `if()` statement
We use this to define how the following durations are computed:
`connect_time`, `header_time`, `body_time`, `request_total_time`, `process_time`,
`response_time`, `duration`.

We then use this both in `durations.c` and `logconf.c` to compute said
durations.
@deweerdt deweerdt force-pushed the deweerdt/additional-stats branch 2 times, most recently from 86f01d0 to 1dcb989 Compare August 22, 2016 21:52
@deweerdt
Copy link
Member Author

@kazuho I believe 1dcb989 addresses all your comments so far.

@@ -44,6 +45,21 @@ int h2o_time_parse_rfc1123(const char *s, size_t len, struct tm *tm);
*/
void h2o_time2str_log(char *buf, time_t time);

static inline int64_t h2o_timeval_substract(struct timeval *from, struct timeval *until)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/substract/subtract/?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0b9026f, thanks for noticing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in french, the word is "soustraction"

Oh! And I've just learned that sous-chef means sub-chef!

} \
*okp = 1; \
return h2o_timeval_subtract((from), (until)); \
} \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merging the two functions as int h2o_time_compute_##name(struct st_h2o_req_t *req, int64_t *delta_usec), and use the function from both logconf.c and durations.c?

Generally speaking, I think we should better refrain from introducing functions for just returning different types. Also, I think that the return value should be whether if the function succeeded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merging the two functions as int h2o_time_compute_##name(struct st_h2o_req_t *req, int64_t *delta_usec), and use the function from both logconf.c and durations.c?

The reason i didn't do that is that it seemed wasteful to combine the values into a usec just to split them again for the logconf.c case. I'll combine them into a single function.

Copy link
Member

@kazuho kazuho Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification.

I appreciate your concern about performance.

I think that in case we emit a log line it is highly likely that there are other stringifications will be performed as well (e.g. IP address, status code, content length, etc.), and that the impact of an extra multiply+divide would be negligible.

Or I am open to changing the signature to int h2o_time_compute_##name(struct st_h2o_req_t *req, struct timeval *delta_tv) if it seems more adequate to you.

@deweerdt
Copy link
Member Author

@kazuho 9803e82 addresses all your comments so far.

assert(ret.len < BUFSIZE);

return ret;
if (JEMALLOC_STATS) {
Copy link
Member

@kazuho kazuho Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change if (JEMALLOC_STATS) { ... } to #if JEMALLOC_STATS ... #endif? The reason I suggested this is since there is not guarantee that a compiler strips non-reachable code (i.e. the block inside if (0) { }). In such case, reference to malloc_stats_print would cause a link-time error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, i misread your suggestion, thank you for the reminder. Updating.

@kazuho
Copy link
Member

kazuho commented Aug 23, 2016

Thank you for the updates. Aside from the #if thing, I think the PR is ready for merge.

There's no guarantee that the compiler will actually compile the code
out. An `#if` does guarantee that.
@deweerdt
Copy link
Member Author

Thank you for the updates. Aside from the #if thing, I think the PR is ready for merge.

Fixed in 5764880. Thank you.

@kazuho kazuho merged commit 4fcf15f into h2o:master Aug 25, 2016
@kazuho
Copy link
Member

kazuho commented Aug 25, 2016

Thank you for the updates! Merged to master.

@deweerdt deweerdt deleted the deweerdt/additional-stats branch August 25, 2016 22:02
kazuho added a commit that referenced this pull request Aug 26, 2016
kazuho added a commit that referenced this pull request Feb 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants