Skip to content

Commit 9efafc1

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. (cherry picked from commit 5e6a02b)
1 parent 646fe64 commit 9efafc1

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Improvements
1010
- tests: disable problematic config.http test (#925, !1678)
1111
- validator: accept a confusing NODATA proof with insecure delegation (!1678)
1212

13+
Bugfixes
14+
--------
15+
- stats: request latency was very incorrect in some cases (!1678)
16+
1317

1418
Knot Resolver 5.7.4 (2024-07-23)
1519
================================

lib/rplan.c

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

159159
gettimeofday(&qry->timestamp, NULL);
160+
if (!parent) // start of kr_request; let's make the stamp more precise
161+
uv_update_time(uv_default_loop());
160162
qry->timestamp_mono = kr_now();
161163
qry->creation_time_mono = parent ? parent->creation_time_mono : qry->timestamp_mono;
162164
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
@@ -248,8 +248,14 @@ static int collect(kr_layer_t *ctx)
248248
collect_answer(data, param->answer);
249249
/* Count cached and unresolved */
250250
if (rplan->resolved.len > 0) {
251-
/* Histogram of answer latency. */
251+
/* Histogram of answer latency.
252+
*
253+
* We update the notion of time. Once per .finish isn't that expensive.
254+
* defer_* also updates this if active, but not in ideal moment for stats.
255+
*/
256+
uv_update_time(uv_default_loop());
252257
uint64_t elapsed = kr_now() - rplan->initial->creation_time_mono;
258+
253259
stat_const_add(data, metric_answer_sum_ms, elapsed);
254260
if (elapsed <= 1) {
255261
stat_const_add(data, metric_answer_1ms, 1);

0 commit comments

Comments
 (0)