Skip to content

Commit 08ac48c

Browse files
committed
modules/stats: further improve latency measurements
libuv's updating the stamp just once per event loop might be too coarse, as processing multiple packets (e.g. DNSSEC validation) may take milliseconds together. Of course we still don't measure e.g. the time when incoming client requests stay in OS buffers.
1 parent 33151c4 commit 08ac48c

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bugfixes
55
--------
66
- /management/unix-socket: revert to absolute path (#926, !1664)
77
- fix `tags` when used in /local-data/rules/*/records (!1670)
8+
- stats: request latency was very incorrect in some cases (!1676)
89

910
Improvements
1011
------------

lib/rplan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ static struct kr_query *kr_rplan_push_query(struct kr_rplan *rplan,
157157
qry->request = rplan->request;
158158

159159
gettimeofday(&qry->timestamp, NULL);
160+
uv_update_time(uv_default_loop());
160161
qry->timestamp_mono = kr_now();
161162
qry->creation_time_mono = parent ? parent->creation_time_mono : qry->timestamp_mono;
162163
kr_zonecut_init(&qry->zone_cut, (const uint8_t *)"", rplan->pool);

modules/stats/stats.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,14 @@ static int collect(kr_layer_t *ctx)
262262
collect_answer(data, param->answer);
263263
/* Count cached and unresolved */
264264
if (rplan->resolved.len > 0) {
265-
/* Histogram of answer latency. */
265+
/* Histogram of answer latency.
266+
*
267+
* We update the notion of time. Once per .finish isn't that expensive.
268+
* defer_* also updates this if active, but not in ideal moment for stats.
269+
*/
270+
uv_update_time(uv_default_loop());
266271
uint64_t elapsed = kr_now() - rplan->initial->creation_time_mono;
272+
267273
stat_const_add(data, metric_answer_sum_ms, elapsed);
268274
if (elapsed <= 1) {
269275
stat_const_add(data, metric_answer_1ms, 1);

0 commit comments

Comments
 (0)