From: Viktor M. <mih...@us...> - 2005-07-06 13:24:42
|
Update of /cvsroot/sblim/sfcb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6582 Modified Files: control.c httpAdapter.c httpComm.c httpComm.h sfcb.cfg.pre.in Log Message: Bugs fixed: 1231019 Enhanced performance for persistent connections. Now use buffered write operations to avoid the client to fall asleep. New config property: keepaliveMaxRequests limits the number of requests on one connection. Index: httpComm.h =================================================================== RCS file: /cvsroot/sblim/sfcb/httpComm.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- httpComm.h 9 Mar 2005 12:25:12 -0000 1.1.1.1 +++ httpComm.h 6 Jul 2005 13:24:33 -0000 1.2 @@ -67,8 +67,12 @@ #endif +#define SOCKBUFSZ 32768 + typedef struct commHndl { - int socket; + int socket; + FILE *file; + void *buf; #if defined USE_SSL BIO *bio; SSL *ssl; @@ -79,5 +83,7 @@ void commInit(); int commWrite(CommHndl to, void *data, size_t count); int commRead(CommHndl from, void *data, size_t count); +void commFlush(CommHndl hdl); +void commClose(CommHndl hdl); #endif Index: control.c =================================================================== RCS file: /cvsroot/sblim/sfcb/control.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- control.c 1 Jul 2005 16:06:39 -0000 1.10 +++ control.c 6 Jul 2005 13:24:29 -0000 1.11 @@ -77,6 +77,7 @@ {"chunkSize", 1, "50000"}, {"keepaliveTimeout", 1, "15"}, + {"keepaliveMaxRequest", 1, "10"}, {"providerSampleInterval", 1, "30"}, {"providerTimeoutInterval", 1, "60"}, Index: sfcb.cfg.pre.in =================================================================== RCS file: /cvsroot/sblim/sfcb/sfcb.cfg.pre.in,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- sfcb.cfg.pre.in 13 Jun 2005 12:50:33 -0000 1.3 +++ sfcb.cfg.pre.in 6 Jul 2005 13:24:33 -0000 1.4 @@ -8,6 +8,8 @@ basicAuthLib: sfcBasicAuthentication doBasicAuth: false useChunking: true +keepaliveTimeout: 0 +keepaliveMaxRequest: 10 sslKeyFilePath: @sysconfdir@/sfcb/file.pem sslCertificateFilePath: @sysconfdir@/sfcb/server.pem registrationDir: @localstatedir@/lib/sfcb/registration Index: httpComm.c =================================================================== RCS file: /cvsroot/sblim/sfcb/httpComm.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- httpComm.c 1 Jul 2005 16:06:40 -0000 1.5 +++ httpComm.c 6 Jul 2005 13:24:31 -0000 1.6 @@ -85,7 +85,15 @@ } else #endif - rc = write(to.socket,data,count); + if (to.file == NULL) { + rc = write(to.socket,data,count); + } else { + rc = fwrite(data,count,1,to.file); + if (rc == 1) { + /* return number of bytes written */ + rc = count; + } + } _SFCB_RETURN(rc); } @@ -109,3 +117,10 @@ _SFCB_RETURN(rc); } + +void commFlush(CommHndl hndl) +{ + if (hndl.file) { + fflush(hndl.file); + } +} Index: httpAdapter.c =================================================================== RCS file: /cvsroot/sblim/sfcb/httpAdapter.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- httpAdapter.c 1 Jul 2005 16:06:39 -0000 1.14 +++ httpAdapter.c 6 Jul 2005 13:24:29 -0000 1.15 @@ -65,6 +65,8 @@ static int stopAccepting=0; static int running=0; static long keepaliveTimeout=15; +static long keepaliveMaxRequest=10; +static long numRequest; #if defined USE_SSL SSL_CTX *ctx; @@ -275,6 +277,7 @@ commWrite(conn_fd, server, strlen(server)); commWrite(conn_fd, clength, strlen(clength)); commWrite(conn_fd, cclose, strlen(cclose)); + commFlush(conn_fd); exit(1); } @@ -330,6 +333,7 @@ static char cont[] = {"Content-Type: application/xml; charset=\"utf-8\"\r\n"}; static char cach[] = {"Cache-Control: no-cache\r\n"}; static char op[] = {"CIMOperation: MethodResponse\r\n"}; + static char cclose[] = "Connection: close\r\n"; static char end[] = {"\r\n\r\n"}; char str[256]; int len, i, ls[8]; @@ -366,6 +370,10 @@ // PrintF("%s",man); commWrite(conn_fd, op, strlen(op)); PrintF("%s",op); + if (keepaliveTimeout == 0 || numRequest >= keepaliveMaxRequest) { + commWrite(conn_fd, cclose, strlen(cclose)); + PrintF("%s",cclose); + } commWrite(conn_fd, end, strlen(end)); PrintF("%s",end); @@ -387,6 +395,7 @@ } } } + commFlush(conn_fd); PrintF("%s","-----------------\n"); _SFCB_EXIT(); @@ -401,6 +410,7 @@ static char op[] = {"CIMOperation: MethodResponse\r\n"}; static char tenc[] = {"Transfer-encoding: chunked\r\n"}; static char trls[] = {"Trailer: CIMError, CIMStatusCode, CIMStatusCodeDescription\r\n"}; + static char cclose[] = "Connection: close\r\n"; _SFCB_ENTER(TRACE_HTTPDAEMON, "writeChunkHeaders"); @@ -416,7 +426,11 @@ PrintF("%s",tenc); commWrite(*(ctx->commHndl), trls, strlen(trls)); PrintF("%s",trls); - + if (keepaliveTimeout == 0 || numRequest >= keepaliveMaxRequest) { + commWrite(*(ctx->commHndl), cclose, strlen(cclose)); + PrintF("%s",cclose); + } + _SFCB_EXIT(); } @@ -520,6 +534,7 @@ commWrite(*(ctx->commHndl), eStr, strlen(eStr)); PrintF("%s",eStr); } + commFlush(*(ctx->commHndl)); _SFCB_EXIT(); } @@ -775,6 +790,17 @@ } conn_fd.socket=connFd; + conn_fd.file=fdopen(connFd,"a"); + if (conn_fd.file == NULL) { + mlogf(M_ERROR,M_SHOW,"--- failed to create socket stream - continue with raw socket: %s\n",strerror(errno)); + } else { + conn_fd.buf = malloc(SOCKBUFSZ); + if (conn_fd.buf) { + setbuffer(conn_fd.file,conn_fd.buf,SOCKBUFSZ); + } else { + mlogf(M_ERROR,M_SHOW,"--- failed to create socket buffer - continue unbuffered: %s\n",strerror(errno)); + } + } if (sfcbSSLMode) { #if defined USE_SSL conn_fd.bio=BIO_new(BIO_s_socket()); @@ -792,15 +818,17 @@ #endif } + numRequest = 0; FD_ZERO(&httpfds); FD_SET(conn_fd.socket,&httpfds); do { + numRequest += 1; if (doHttpRequest(conn_fd)) { /* eof reached - leave */ break; } - if (keepaliveTimeout==0) { - /* we don't support persistence - quit */ + if (keepaliveTimeout==0 || numRequest >= keepaliveMaxRequest ) { + /* no persistence wanted or exceeded - quit */ break; } /* wait for next request or timeout */ @@ -822,10 +850,16 @@ SSL_shutdown(conn_fd.ssl); else SSL_clear(conn_fd.ssl); SSL_free(conn_fd.ssl); - } else { - close(conn_fd.socket); - } + } else #endif + if (conn_fd.file == NULL) { + close(conn_fd.socket); + } else { + fclose(conn_fd.file); + if (conn_fd.buf) { + free(conn_fd.buf); + } + } if (!doFork) return; @@ -878,6 +912,9 @@ if (getControlNum("keepaliveTimeout", &keepaliveTimeout)) keepaliveTimeout = 15; + if (getControlNum("keepaliveMaxRequest", &keepaliveMaxRequest)) + keepaliveMaxRequest = 10; + i = 1; while (i < argc && argv[i][0] == '-') { if (strcmp(argv[i], "-D") == 0) @@ -922,7 +959,8 @@ if (keepaliveTimeout == 0) { mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout disabled\n"); } else { - mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout %ld seconds\n",keepaliveTimeout); + mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout: %ld seconds\n",keepaliveTimeout); + mlogf(M_INFO,M_SHOW,"--- Maximum requests per connection: %ld\n",keepaliveMaxRequest); } listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |