From 2f976e18b8f932dda4eb567b47c6dc1e1dd0d6b9 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 11 Nov 2010 14:28:47 +0100 Subject: [PATCH] [OPTIM] session: don't recheck analysers when buffer flags have not changed Analysers were re-evaluated when some flags were still present in the buffers, even if they had not changed since previous pass, resulting in a waste of CPU cycles. Ensuring that the flags have changed has saved some useless calls : function min calls per session (before -> after) http_request_forward_body 5 -> 4 http_response_forward_body 3 -> 2 http_sync_req_state 10 -> 8 http_sync_res_state 8 -> 6 http_resync_states 8 -> 6 --- src/session.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/session.c b/src/session.c index 9beb06cae..c34ed9f65 100644 --- a/src/session.c +++ b/src/session.c @@ -1214,8 +1214,8 @@ struct task *process_session(struct task *t) s->req->flags &= ~BF_READ_NOEXP; /* Keep a copy of req/rep flags so that we can detect shutdowns */ - rqf_last = s->req->flags; - rpf_last = s->rep->flags; + rqf_last = s->req->flags & ~BF_MASK_ANALYSER; + rpf_last = s->rep->flags & ~BF_MASK_ANALYSER; /* we don't want the stream interface functions to recursively wake us up */ if (s->req->prod->owner == t) @@ -1364,7 +1364,7 @@ struct task *process_session(struct task *t) resync_request: /* Analyse request */ - if ((s->req->flags & BF_MASK_ANALYSER) || + if (((s->req->flags & ~rqf_last) & BF_MASK_ANALYSER) || ((s->req->flags ^ rqf_last) & BF_MASK_STATIC) || s->si[0].state != rq_prod_last || s->si[1].state != rq_cons_last) { @@ -1537,7 +1537,7 @@ struct task *process_session(struct task *t) goto resync_response; } } - else if ((s->rep->flags & BF_MASK_ANALYSER) || + else if (((s->rep->flags & ~rpf_last) & BF_MASK_ANALYSER) || (s->rep->flags ^ rpf_last) & BF_MASK_STATIC || s->si[0].state != rp_cons_last || s->si[1].state != rp_prod_last) { @@ -1627,7 +1627,7 @@ struct task *process_session(struct task *t) * we're just in a data phase here since it means we have not * seen any analyser who could set an error status. */ - if (!(s->flags & SN_ERR_MASK)) { + if (unlikely(!(s->flags & SN_ERR_MASK))) { if (s->req->flags & (BF_READ_ERROR|BF_READ_TIMEOUT|BF_WRITE_ERROR|BF_WRITE_TIMEOUT)) { /* Report it if the client got an error or a read timeout expired */ s->req->analysers = 0;