Grace delay feature added

`proxy -g8000,3,10`

First parameter is average read size we want to keep, second parameter is
minimal number of packets in the same direction to apply algorythm,
last value is delay added after polling and prior to reading data.
An example above adds 10 millisecond delay before reading data if average
polling size is below 8000 bytes and 3 read operations are made in the same
direction. It's specially usefule with splice. `logdump 1 1` is useful
to see how grace delays work, choose delay value to avoid filling the read
pipe/buffer (typically 64K) but keep the request sizes close to chosen average
on large file upload/download.
This commit is contained in:
Vladimir Dubrovin committed 2022-05-19 18:51:02 +03:00
1 parent 8a8622b30f
commit 55d1bbe155
8 files changed
+49 -2

No files matched your search

+25
View File
@@ -60,6 +60,7 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
int res;
SASIZETYPE sasize;
int needaction = 0;
int graceclinum=0, gracesrvnum=0, graceclitraf=0, gracesrvtraf=0, gracetime=0;
#ifdef WITHSPLICE
uint64_t inclientpipe = 0, inserverpipe = 0;
@@ -158,6 +159,18 @@ sprintf(logbuf, "int FROMCLIENT = %d, TOCLIENTBUF = %d, FROMCLIENTBUF = %d, TOSE
log(logbuf);
#endif
if(needaction && param->srv->gracedelay && !sleeptime){
if(gracetime != conf.time){
gracetime = conf.time;
graceclinum=gracesrvnum=graceclitraf=gracesrvtraf=0;
}
else {
if( (graceclinum && graceclitraf && graceclinum>=param->srv->gracenum && (!param->srv->gracetraf || graceclitraf/graceclinum <= param->srv->gracetraf)) ||
(gracesrvnum && gracesrvtraf && gracesrvnum>=param->srv->gracenum && (!param->srv->gracetraf || gracesrvtraf/gracesrvnum <= param->srv->gracetraf))) {
sleeptime = param->srv->gracedelay;
}
}
}
if(needaction > 2 && !sleeptime){
if(needaction > (MAXFAILATTEMPT+1)){RETURN (93);}
sleeptime = (1<<(needaction-2));
@@ -354,6 +367,9 @@ log(logbuf);
#ifdef WITHLOG
log("done read from client to pipe");
#endif
graceclinum++;
graceclitraf += res;
gracesrvnum = gracesrvtraf = 0;
inclientpipe += res;
if(inclientpipe >= MAXSPLICE) TOCLIENTPIPE = 0;
needaction = 0;
@@ -388,6 +404,9 @@ log(logbuf);
#ifdef WITHLOG
log("done read from server to pipe\n");
#endif
gracesrvnum++;
gracesrvtraf += res;
graceclinum = graceclitraf = 0;
param->nreads++;
param->statssrv64 += res;
inserverpipe += res;
@@ -426,6 +445,9 @@ log("read from client to buf");
#ifdef WITHLOG
log("done read from client to buf");
#endif
graceclinum++;
graceclitraf += res;
gracesrvnum = gracesrvtraf = 0;
inclientbuf += res;
param->cliinbuf += res;
if(param->clibufsize == param->cliinbuf) TOCLIENTBUF = 0;
@@ -451,6 +473,9 @@ log("read from server to buf");
#ifdef WITHLOG
log("done read from server to buf");
#endif
gracesrvnum++;
gracesrvtraf += res;
graceclinum = graceclitraf = 0;
param->nreads++;
param->statssrv64 += res;
inserverbuf += res;