Skip to content

Commit a53a323

Browse files
authored
Merge pull request #1169 from tempesta-tech/ik-early-apm-update
Update server APM stats right after response was received
2 parents 00e82dd + 0a8dce3 commit a53a323

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

tempesta_fw/http.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,6 +3162,16 @@ tfw_http_resp_cache_cb(TfwHttpMsg *msg)
31623162
TfwHttpReq *req = resp->req;
31633163

31643164
TFW_DBG2("%s: req = %p, resp = %p\n", __func__, req, resp);
3165+
/*
3166+
* Response will never be sent: client has disconnected already.
3167+
* Don't adjust response, simply destroy it.
3168+
*/
3169+
if (unlikely(test_bit(TFW_HTTP_B_REQ_DROP, req->flags))) {
3170+
TFW_DBG2("%s: resp=[%p] dropped: client disconnected\n",
3171+
__func__, resp);
3172+
tfw_http_resp_pair_free(req);
3173+
return;
3174+
}
31653175
/*
31663176
* Typically we're at a node far from the node where @resp was
31673177
* received, so we do an inter-node transfer. However, this is
@@ -3171,26 +3181,11 @@ tfw_http_resp_cache_cb(TfwHttpMsg *msg)
31713181
*/
31723182
if (tfw_http_adjust_resp(resp)) {
31733183
tfw_http_conn_msg_free((TfwHttpMsg *)resp);
3174-
tfw_http_send_resp(req, 500, "response dropped:"
3175-
" processing error");
3184+
tfw_http_send_resp(req, 500,
3185+
"response dropped: processing error");
31763186
TFW_INC_STAT_BH(serv.msgs_otherr);
31773187
return;
31783188
}
3179-
/*
3180-
* Responses from cache don't have @resp->conn. Also, for those
3181-
* responses @req->jtxtstamp is not set and remains zero.
3182-
*
3183-
* TODO: Currently APM holds the pure roundtrip time (RTT) from
3184-
* the time a request is forwarded to the time a response to it
3185-
* is received and parsed. Perhaps it makes sense to penalize
3186-
* server connections which get broken too often. What would be
3187-
* a fast and simple algorithm for that? Keep in mind, that the
3188-
* value of RTT has an upper boundary in the APM.
3189-
*/
3190-
if (resp->conn)
3191-
tfw_apm_update(((TfwServer *)resp->conn->peer)->apmref,
3192-
resp->jrxtstamp,
3193-
resp->jrxtstamp - req->jtxtstamp);
31943189
tfw_http_resp_fwd(resp);
31953190
}
31963191

@@ -3290,6 +3285,7 @@ tfw_http_resp_gfsm(TfwHttpMsg *hmresp, TfwFsmData *data)
32903285
static int
32913286
tfw_http_resp_cache(TfwHttpMsg *hmresp)
32923287
{
3288+
TfwHttpResp *resp = (TfwHttpResp *)hmresp;
32933289
TfwHttpReq *req = hmresp->req;
32943290
TfwFsmData data;
32953291
time_t timestamp = tfw_current_timestamp();
@@ -3299,7 +3295,7 @@ tfw_http_resp_cache(TfwHttpMsg *hmresp)
32993295
* for age calculations, and for APM and Load Balancing.
33003296
*/
33013297
hmresp->cache_ctl.timestamp = timestamp;
3302-
((TfwHttpResp *)hmresp)->jrxtstamp = jiffies;
3298+
resp->jrxtstamp = jiffies;
33033299
/*
33043300
* If 'Date:' header is missing in the response, then
33053301
* set the date to the time the response was received.
@@ -3311,6 +3307,16 @@ tfw_http_resp_cache(TfwHttpMsg *hmresp)
33113307
* fwd_queue.
33123308
*/
33133309
tfw_http_popreq(hmresp, true);
3310+
/*
3311+
* TODO: Currently APM holds the pure roundtrip time (RTT) from
3312+
* the time a request is forwarded to the time a response to it
3313+
* is received and parsed. Perhaps it makes sense to penalize
3314+
* server connections which get broken too often. What would be
3315+
* a fast and simple algorithm for that? Keep in mind, that the
3316+
* value of RTT has an upper boundary in the APM.
3317+
*/
3318+
tfw_apm_update(((TfwServer *)resp->conn->peer)->apmref,
3319+
resp->jrxtstamp, resp->jrxtstamp - req->jtxtstamp);
33143320
/*
33153321
* Health monitor request means that its response need not to
33163322
* send anywhere.

0 commit comments

Comments
 (0)