mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Make the automatic splice() mode's heuristics a service option
-s[N]:MIN,STREAK,SMALL sets where the automatic mode splices, as -g does for grace delay: a direction is spliced after STREAK reads in a row of MIN bytes or more (SMALL from a TLS socket), copied again after more than STREAK splices in a row of less than SMALL, and a body of known length is spliced if MIN or more of it is left. The defaults, 16384,2,4096, are what was built in; a value left out or 0 keeps its default. The man page describes it, and its HTML copy, which still said splice() was not built by default, now has the current text. A test case relays answers of every size, chunked ones and a 3 MB upload through every mode, two of them with heuristics set, and compares them byte for byte. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cfe52878d0
commit
61041ebe7d
7 files changed
+207
-32
No files matched your search
@@ -235,6 +235,11 @@ extern struct extparam confboot;
|
||||
#define SPLICE_DOWNLOAD 1
|
||||
#define SPLICE_UPLOAD 2
|
||||
#define SPLICE_AUTO 4
|
||||
/* where SPLICE_AUTO splices, by default (-s[N]:MIN,STREAK,SMALL): see
|
||||
sockmap.c */
|
||||
#define SPLICE_MIN 16384
|
||||
#define SPLICE_STREAK 2
|
||||
#define SPLICE_SMALL 4096
|
||||
int sockmap(struct clientparam * param, int timeo, int usesplice);
|
||||
int udpsockmap(struct clientparam * param, int timeo);
|
||||
int udpbind(struct clientparam * param);
|
||||
|
||||
+21
-2
@@ -436,6 +436,10 @@ static int srvprepare(struct srvstart *s, int argc, char **argv){
|
||||
" -s[N] Use splice(): -s1 server to client, -s2 client to server, -s3 both\n"
|
||||
" directions; -s (-s7, the default) both, -s5 or -s6 one, only where it\n"
|
||||
" pays (large transfers); -s0 never. Not with data filters\n"
|
||||
" :MIN,STREAK,SMALL tune where it pays (-s:16384,2,4096): splice after\n"
|
||||
" STREAK reads in a row of MIN bytes or more (SMALL from a TLS socket),\n"
|
||||
" copy again after more than STREAK splices of less than SMALL; a body of\n"
|
||||
" known length is spliced if MIN or more of it is left\n"
|
||||
" -C connection closed by any of the sides terminates the session, by default\n"
|
||||
" the session is kept until both sides close it (TCP half-close)\n"
|
||||
" -U(0-3) (for socks) what to do when the destination changes within an UDP\n"
|
||||
@@ -716,10 +720,22 @@ static int srvprepare(struct srvstart *s, int argc, char **argv){
|
||||
#endif
|
||||
srv->s_option = 1 + atoi(argv[i]+2);
|
||||
#ifdef WITHSPLICE
|
||||
else
|
||||
srv->usesplice = (*(argv[i]+2)? atoi(argv[i]+2) :
|
||||
else {
|
||||
/* -s[N][:MIN,STREAK,SMALL] */
|
||||
char *heur = strchr(argv[i]+2, ':');
|
||||
|
||||
srv->usesplice = ((argv[i][2] && argv[i][2] != ':')? atoi(argv[i]+2) :
|
||||
SPLICE_DOWNLOAD|SPLICE_UPLOAD|SPLICE_AUTO) &
|
||||
(SPLICE_DOWNLOAD|SPLICE_UPLOAD|SPLICE_AUTO);
|
||||
if(heur){
|
||||
int min = 0, streak = 0, small = 0;
|
||||
|
||||
sscanf(heur+1, "%d,%d,%d", &min, &streak, &small);
|
||||
if(min > 0) srv->splicemin = min;
|
||||
if(streak > 0) srv->splicestreak = streak;
|
||||
if(small > 0) srv->splicesmall = small;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case 'o':
|
||||
@@ -1498,6 +1514,9 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
|
||||
#ifdef WITHSPLICE
|
||||
/* where it pays: large transfers, -s0 to never */
|
||||
srv->usesplice = SPLICE_DOWNLOAD|SPLICE_UPLOAD|SPLICE_AUTO;
|
||||
srv->splicemin = SPLICE_MIN;
|
||||
srv->splicestreak = SPLICE_STREAK;
|
||||
srv->splicesmall = SPLICE_SMALL;
|
||||
#endif
|
||||
srv->halfclose = 1;
|
||||
srv->udpauth = 3;
|
||||
|
||||
+19
-19
@@ -44,18 +44,16 @@ ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t le
|
||||
|
||||
/* With SPLICE_AUTO, when a direction allowed to splice actually does
|
||||
(without it, an allowed direction always does).
|
||||
A body of known length is spliced if at least SPLICE_MIN of it is left
|
||||
A body of known length is spliced if at least splicemin of it is left
|
||||
to read once what is already buffered is counted: a smaller one, or one
|
||||
read whole with its headers, is cheaper to copy.
|
||||
A stream of unknown length starts copied and is spliced after
|
||||
SPLICE_STREAK reads in a row of at least SPLICE_MIN each, and goes back to
|
||||
copying after SPLICE_STREAK+1 splices in a row of less than SPLICE_SMALL. */
|
||||
#define SPLICE_MIN 16384
|
||||
#define SPLICE_SMALL 4096
|
||||
#define SPLICE_STREAK 2
|
||||
/* a large read from a TLS socket: TLS hands out a record at a time, at most
|
||||
16K and often less */
|
||||
#define SPLICE_TLSMIN SPLICE_SMALL
|
||||
splicestreak reads in a row of at least splicemin each, and goes back to
|
||||
copying after splicestreak+1 splices in a row of less than splicesmall.
|
||||
From a TLS socket a read of splicesmall counts as large: TLS hands out a
|
||||
record at a time, at most 16K and often less. The service sets the three
|
||||
(-s[N]:MIN,STREAK,SMALL), SPLICE_MIN, SPLICE_STREAK and SPLICE_SMALL by
|
||||
default. */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -149,6 +147,8 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
into the buffer first (drain), once the pipe is empty, so as to keep the
|
||||
order; tail: the last read left some, the next only collects it */
|
||||
int draincli = 0, drainsrv = 0, tailcli = 0, tailsrv = 0;
|
||||
int splicemin = param->srv->splicemin, splicestreak = param->srv->splicestreak,
|
||||
splicesmall = param->srv->splicesmall;
|
||||
|
||||
if((!param->nolongdatfilter && (param->ndatfilterscli > 0 || param->ndatfilterssrv)) || param->nosplice) usesplice = 0;
|
||||
allowcli = (usesplice & SPLICE_UPLOAD) != 0;
|
||||
@@ -190,8 +190,8 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
|
||||
if(inclientbuf >= fromclient) FROMCLIENT = 0;
|
||||
#ifdef WITHSPLICE
|
||||
/* a body of known length large enough is spliced from the start */
|
||||
if(autosplice && allowsrv && param->waitserver64 && fromserver > inserverbuf && fromserver - inserverbuf >= SPLICE_MIN) splicesrv = 1;
|
||||
if(autosplice && allowcli && param->waitclient64 && fromclient > inclientbuf && fromclient - inclientbuf >= SPLICE_MIN) splicecli = 1;
|
||||
if(autosplice && allowsrv && param->waitserver64 && fromserver > inserverbuf && fromserver - inserverbuf >= (uint64_t)splicemin) splicesrv = 1;
|
||||
if(autosplice && allowcli && param->waitclient64 && fromclient > inclientbuf && fromclient - inclientbuf >= (uint64_t)splicemin) splicecli = 1;
|
||||
#endif
|
||||
if(param->srvinbuf == param->srvoffset) param->srvinbuf =param->srvoffset = 0;
|
||||
if(param->cliinbuf == param->clioffset) param->cliinbuf =param->clioffset = 0;
|
||||
@@ -504,8 +504,8 @@ log("done read from client to pipe");
|
||||
graceclitraf += res;
|
||||
gracesrvnum = gracesrvtraf = 0;
|
||||
if(autosplice && !param->waitclient64){
|
||||
if(res >= SPLICE_SMALL) streakcli = 0;
|
||||
else if(++streakcli > SPLICE_STREAK) wantbufcli = 1;
|
||||
if(res >= splicesmall) streakcli = 0;
|
||||
else if(++streakcli > splicestreak) wantbufcli = 1;
|
||||
}
|
||||
inclientpipe += res;
|
||||
if(inclientpipe >= MAXSPLICE) TOCLIENTPIPE = 0;
|
||||
@@ -567,8 +567,8 @@ log("done read from server to pipe\n");
|
||||
gracesrvtraf += res;
|
||||
graceclinum = graceclitraf = 0;
|
||||
if(autosplice && !param->waitserver64){
|
||||
if(res >= SPLICE_SMALL) streaksrv = 0;
|
||||
else if(++streaksrv > SPLICE_STREAK) wantbufsrv = 1;
|
||||
if(res >= splicesmall) streaksrv = 0;
|
||||
else if(++streaksrv > splicestreak) wantbufsrv = 1;
|
||||
}
|
||||
param->nreads++;
|
||||
param->statssrv64 += res;
|
||||
@@ -620,8 +620,8 @@ log("done read from client to buf");
|
||||
else if(autosplice && allowcli && !param->waitclient64){
|
||||
int tls = splicetls? splicetls(param, param->clisock) : 0;
|
||||
|
||||
if(res >= (tls? SPLICE_TLSMIN : SPLICE_MIN)){
|
||||
if(++streakcli >= SPLICE_STREAK){
|
||||
if(res >= (tls? splicesmall : splicemin)){
|
||||
if(++streakcli >= splicestreak){
|
||||
/* a stream: splice from now on, after what is
|
||||
buffered has been sent */
|
||||
splicecli = TOCLIENTPIPE = FROMCLIENTPIPE = 1;
|
||||
@@ -675,8 +675,8 @@ log("done read from server to buf");
|
||||
else if(autosplice && allowsrv && !param->waitserver64){
|
||||
int tls = splicetls? splicetls(param, param->remsock) : 0;
|
||||
|
||||
if(res >= (tls? SPLICE_TLSMIN : SPLICE_MIN)){
|
||||
if(++streaksrv >= SPLICE_STREAK){
|
||||
if(res >= (tls? splicesmall : splicemin)){
|
||||
if(++streaksrv >= splicestreak){
|
||||
splicesrv = TOSERVERPIPE = FROMSERVERPIPE = 1;
|
||||
streaksrv = 0;
|
||||
}
|
||||
|
||||
@@ -653,6 +653,8 @@ struct srvparam {
|
||||
unsigned char fakeip6[16];
|
||||
#ifdef WITHSPLICE
|
||||
int usesplice;
|
||||
/* the automatic mode's heuristics, -s[N]:MIN,STREAK,SMALL */
|
||||
int splicemin, splicestreak, splicesmall;
|
||||
#endif
|
||||
int halfclose;
|
||||
int udpauth;
|
||||
|
||||
Reference in new issue
Block a user