From 9f5990b1d022b0a2ea2ec492c585533e5a2a1671 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 12 Dec 2011 00:01:01 +0100 Subject: OPTIM: improve performance in L4 mode on small objects by avoiding a recv() When we're not interested in parsing the response, we don't need to perform a 4kB recv() first and we don't need to allocate the buffer either. Let's rearrange the code to make this possible. --- inject.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/inject.c b/inject.c index 88df698..0f61537 100644 --- a/inject.c +++ b/inject.c @@ -1697,11 +1697,19 @@ int EventRead(int fd) { do { moretoread = 0; +#ifndef DONT_ANALYSE_HTTP_HEADERS if (obj->buf == NULL) { /* pas encore alloué */ obj->read = obj->buf = (char *)alloc_pool(buffer); } - if (obj->buf + BUFSIZE <= obj->read) { /* on ne stocke pas les data dépassant le buffer */ + if (obj->read < obj->buf + BUFSIZE) { /* on ne stocke que les data qui tiennent dans le buffer */ + int readsz = BUFSIZE - (obj->read - obj->buf); + ret=recv(fd, obj->read, readsz, MSG_NOSIGNAL/*|MSG_WAITALL*/); /* lire et stocker les data */ + if (ret > 0) + obj->read += ret; + } else +#endif + { int readsz; #ifdef ENABLE_SPLICE @@ -1727,11 +1735,6 @@ int EventRead(int fd) { readsz = sizeof(trash); ret=recv(fd, trash, readsz,MSG_NOSIGNAL/*|MSG_WAITALL*/); /* lire les data mais ne pas les stocker */ } - } else { - int readsz = BUFSIZE - (obj->read - obj->buf); - ret=recv(fd, obj->read, readsz, MSG_NOSIGNAL/*|MSG_WAITALL*/); /* lire et stocker les data */ - if (ret > 0) - obj->read += ret; } if (ret > 0) { -- 1.7.2.3