Take into account the in queue wait time when executing a data query (#12885)
Take into account the in queue wait time when executing a query with a timeout
Stelios Fragkakis committed
May 12, 2022 at 22:39 UTC
60ee48f7bb01e5bb4b60424c062aeb571af209ed
2 files changed
+21
-7
aclk/aclk_query.c
+9
-7
@@ -111,13 +111,15 @@ static int http_api_v2(struct aclk_query_thread *query_thr, aclk_query_t query)
111
w->tv_in = query->created_tv;
112
now_realtime_timeval(&w->tv_ready);
113
114
- if (query->timeout && (dt_usec(&query->created_tv, &w->tv_ready) / 1000.0) > query->timeout) {
115
- log_access("QUERY CANCELED: QUEUE TIME EXCEEDED %0.2f ms (LIMIT %d ms)",
116
- dt_usec(&query->created_tv, &w->tv_ready) / 1000.0, query->timeout);
117
- retval = 1;
118
- w->response.code = HTTP_RESP_BACKEND_FETCH_FAILED;
119
- aclk_http_msg_v2_err(query_thr->client, query->callback_topic, query->msg_id, w->response.code, CLOUD_EC_SND_TIMEOUT, CLOUD_EMSG_SND_TIMEOUT, NULL, 0);
120
- goto cleanup;
114
+ if (query->timeout) {
115
+ double in_queue = (int)dt_usec(&w->tv_in, &w->tv_ready) / 1000;
116
+ if (in_queue > query->timeout) {
117
+ log_access("QUERY CANCELED: QUEUE TIME EXCEEDED %0.2f ms (LIMIT %d ms)", in_queue, query->timeout);
118
+ retval = 1;
119
+ w->response.code = HTTP_RESP_BACKEND_FETCH_FAILED;
120
+ aclk_http_msg_v2_err(query_thr->client, query->callback_topic, query->msg_id, w->response.code, CLOUD_EC_SND_TIMEOUT, CLOUD_EMSG_SND_TIMEOUT, NULL, 0);
121
+ goto cleanup;
122
+ }
123
}
124
125
RRDHOST *temp_host = NULL;
web/api/web_api_v1.c
+12
@@ -592,6 +592,18 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
592
long group_time = (group_time_str && *group_time_str)?str2l(group_time_str):0;
593
int max_anomaly_rates = (max_anomaly_rates_str && *max_anomaly_rates_str) ? str2i(max_anomaly_rates_str) : 0;
594
595
+ if (timeout) {
596
+ struct timeval now;
597
+ now_realtime_timeval(&now);
598
+ int inqueue = (int)dt_usec(&w->tv_in, &now) / 1000;
599
+ timeout -= inqueue;
600
+ if (timeout <= 0) {
601
+ buffer_flush(w->response.data);
602
+ buffer_strcat(w->response.data, "Query timeout exceeded");
603
+ return HTTP_RESP_BACKEND_FETCH_FAILED;
604
+ }
605
+ }
606
+
607
debug(D_WEB_CLIENT, "%llu: API command 'data' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', format '%u', options '0x%08x'"
608
, w->id
609
, chart