From: wessels <> Date: Sun, 10 Aug 1997 12:34:26 +0000 (+0000) Subject: More work on persistent connections X-Git-Tag: SQUID_3_0_PRE1~4837 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b716a8ad7b0f9209874e63207440d367c92f9660;p=thirdparty%2Fsquid.git More work on persistent connections - added histogram counter - added httpRestart() to retry failed requests when the server closes on us. - missing commSetTimeout() calls when reusing a pconn. - need to disable read and timeout handler when pconn pops a FD. - const fixes --- diff --git a/src/cbdata.cc b/src/cbdata.cc index ee3583e3b6..1a64b636ce 100644 --- a/src/cbdata.cc +++ b/src/cbdata.cc @@ -59,7 +59,7 @@ cbdataFree(void *p) c->valid = 0; if (c->locks) { debug(45, 3) ("cbdataFree: %p has %d locks, not freeing\n", - p, c->locks); + p, c->locks); return; } hash_remove_link(htable, (hash_link *) c); diff --git a/src/client.cc b/src/client.cc index 9ca67a0bf8..662e055faf 100644 --- a/src/client.cc +++ b/src/client.cc @@ -1,6 +1,7 @@ + /* - * $Id: client.cc,v 1.24 1997/08/10 04:42:34 wessels Exp $ + * $Id: client.cc,v 1.25 1997/08/10 06:34:27 wessels Exp $ * * DEBUG: section 0 WWW Client * AUTHOR: Harvest Derived diff --git a/src/comm.cc b/src/comm.cc index 0d2f644c5b..25880e924e 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,5 +1,5 @@ /* - * $Id: comm.cc,v 1.184 1997/08/10 04:42:36 wessels Exp $ + * $Id: comm.cc,v 1.185 1997/08/10 06:34:27 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -332,7 +332,7 @@ commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void * cs->port = port; cs->callback = callback; cs->data = data; - cbdataLock(data); + cbdataLock(cs->data); comm_add_close_handler(fd, commConnectFree, cs); cs->locks++; ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); @@ -363,7 +363,7 @@ commConnectCallback(ConnectStateData * cs, int status) commConnectFree(fd, cs); if (cbdataValid(data)) callback(fd, status, data); - cbdataUnlock(data); + cbdataUnlock(cs->data); } static void @@ -579,13 +579,12 @@ comm_close(int fd) assert(fd >= 0); assert(fd < Squid_MaxFD); F = &fd_table[fd]; - if (!F->open) { - debug(5, 1) ("comm_close: FD %d is not open!\n", fd); - return; - } + assert(F->open); assert(F->type != FD_FILE); CommWriteStateCallbackAndFree(fd, COMM_ERROR); commCallCloseHandlers(fd); + if (F->uses) /* assume persistent connect count */ + pconnHistCount(1, F->uses); fd_close(fd); /* update fdstat */ #if USE_ASYNC_IO aioClose(fd); diff --git a/src/dns.cc b/src/dns.cc index 1018ec287c..41c5d3e68b 100644 --- a/src/dns.cc +++ b/src/dns.cc @@ -1,6 +1,6 @@ /* - * $Id: dns.cc,v 1.39 1997/07/26 04:48:28 wessels Exp $ + * $Id: dns.cc,v 1.40 1997/08/10 06:34:28 wessels Exp $ * * DEBUG: section 34 Dnsserver interface * AUTHOR: Harvest Derived @@ -132,7 +132,7 @@ dnsOpenServer(const char *command) 0, COMM_NOCLOEXEC, "dnsserver listen socket"); - if (cfd == COMM_ERROR) { + if (cfd < 0) { debug(34, 0) ("dnsOpenServer: Failed to create dnsserver\n"); return -1; } diff --git a/src/errorpage.cc b/src/errorpage.cc index 1cdd354d79..83f38cefbe 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -1,6 +1,6 @@ /* - * $Id: errorpage.cc,v 1.62 1997/08/10 04:42:37 wessels Exp $ + * $Id: errorpage.cc,v 1.63 1997/08/10 06:34:29 wessels Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -185,7 +185,7 @@ errorSend(int fd, ErrorState * err) } void -errorAppendEntry(const StoreEntry * entry, ErrorState * err) +errorAppendEntry(StoreEntry * entry, ErrorState * err) { char *buf; int len; diff --git a/src/http.cc b/src/http.cc index 54812e1aaf..eb91041296 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.181 1997/08/10 04:42:38 wessels Exp $ + * $Id: http.cc,v 1.182 1997/08/10 06:34:29 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -211,10 +211,11 @@ static void httpMakePublic _PARAMS((StoreEntry *)); static char *httpStatusString _PARAMS((int status)); static STABH httpAbort; static HttpStateData *httpBuildState _PARAMS((int, StoreEntry *, request_t *, peer *)); -static int httpSocketOpen _PARAMS((StoreEntry *, const request_t *)); +static int httpSocketOpen _PARAMS((StoreEntry *, request_t *)); +static void httpRestart _PARAMS((HttpStateData *)); static void -httpStateFree(int fdunused, void *data) +httpStateFree(int fd, void *data) { HttpStateData *httpState = data; if (httpState == NULL) @@ -668,15 +669,19 @@ httpReadReply(int fd, void *data) debug(50, 2) ("httpReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); } else if (len == 0 && entry->mem_obj->e_current_len == 0) { - httpState->eof = 1; - err = xcalloc(1, sizeof(ErrorState)); - err->type = ERR_ZERO_SIZE_OBJECT; - err->errno = errno; - err->http_status = HTTP_SERVICE_UNAVAILABLE; - err->request = requestLink(httpState->request); - errorAppendEntry(entry, err); - storeAbort(entry, 0); - comm_close(fd); + if (fd_table[fd].uses > 1) { + httpRestart(httpState); + } else { + httpState->eof = 1; + err = xcalloc(1, sizeof(ErrorState)); + err->type = ERR_ZERO_SIZE_OBJECT; + err->errno = errno; + err->http_status = HTTP_SERVICE_UNAVAILABLE; + err->request = requestLink(httpState->request); + errorAppendEntry(entry, err); + storeAbort(entry, 0); + comm_close(fd); + } } else if (len == 0) { /* Connection closed; retrieval done. */ httpState->eof = 1; @@ -947,7 +952,7 @@ httpSendRequest(int fd, void *data) } static int -httpSocketOpen(StoreEntry * entry, const request_t * request) +httpSocketOpen(StoreEntry * entry, request_t * request) { int fd; ErrorState *err; @@ -1015,6 +1020,10 @@ httpStart(request_t * request, StoreEntry * entry, peer * e) if ((fd = pconnPop(e->host, e->http_port)) >= 0) { debug(0, 0) ("httpStart: reusing pconn FD %d\n", fd); httpState = httpBuildState(fd, entry, request, e); + commSetTimeout(httpState->fd, + Config.Timeout.connect, + httpTimeout, + httpState); httpConnectDone(fd, COMM_OK, httpState); return; } @@ -1022,6 +1031,10 @@ httpStart(request_t * request, StoreEntry * entry, peer * e) if ((fd = pconnPop(request->host, request->port)) >= 0) { debug(0, 0) ("httpStart: reusing pconn FD %d\n", fd); httpState = httpBuildState(fd, entry, request, e); + commSetTimeout(httpState->fd, + Config.Timeout.connect, + httpTimeout, + httpState); httpConnectDone(fd, COMM_OK, httpState); return; } @@ -1041,6 +1054,31 @@ httpStart(request_t * request, StoreEntry * entry, peer * e) httpState); } +static void +httpRestart(HttpStateData * httpState) +{ + /* restart a botched request from a persistent connection */ + debug(0, 0) ("Retrying HTTP request for %s\n", httpState->entry->url); + if (httpState->fd >= 0) { + comm_remove_close_handler(httpState->fd, httpStateFree, httpState); + comm_close(httpState->fd); + httpState->fd = -1; + } + httpState->fd = httpSocketOpen(httpState->entry, httpState->request); + if (httpState->fd < 0) + return; + comm_add_close_handler(httpState->fd, httpStateFree, httpState); + commSetTimeout(httpState->fd, + Config.Timeout.connect, + httpTimeout, + httpState); + commConnectStart(httpState->fd, + httpState->request->host, + httpState->request->port, + httpConnectDone, + httpState); +} + static void httpConnectDone(int fd, int status, void *data) { @@ -1073,6 +1111,7 @@ httpConnectDone(int fd, int status, void *data) comm_close(fd); } else { fd_note(fd, entry->url); + fd_table[fd].uses++; commSetSelect(fd, COMM_SELECT_WRITE, httpSendRequest, httpState, 0); } } diff --git a/src/pconn.cc b/src/pconn.cc index d18404b296..03419f6b65 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -133,6 +133,8 @@ pconnPop(const char *host, u_short port) assert(p->nfds > 0); fd = p->fds[0]; pconnRemoveFD(p, fd); + commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + commSetTimeout(fd, -1, NULL, NULL); } xfree(key); return fd; diff --git a/src/protos.h b/src/protos.h index 3b0b840d06..b9969eb462 100644 --- a/src/protos.h +++ b/src/protos.h @@ -527,7 +527,7 @@ extern method_t urlParseMethod _PARAMS((const char *)); extern void urlInitialize _PARAMS((void)); extern request_t *urlParse _PARAMS((method_t, char *)); extern char *urlCanonical _PARAMS((const request_t *, char *)); -extern request_t *requestLink _PARAMS((const request_t *)); +extern request_t *requestLink _PARAMS((request_t *)); extern void requestUnlink _PARAMS((request_t *)); extern int matchDomainName _PARAMS((const char *d, const char *h)); extern int urlCheckRequest _PARAMS((const request_t *)); @@ -542,7 +542,7 @@ extern void logUserAgent _PARAMS((const char *, const char *)); extern peer_t parseNeighborType _PARAMS((const char *s)); extern void errorSend _PARAMS((int fd, ErrorState *)); -extern void errorAppendEntry _PARAMS((const StoreEntry *, ErrorState *)); +extern void errorAppendEntry _PARAMS((StoreEntry *, ErrorState *)); extern void errorInitialize _PARAMS((void)); extern OBJH stat_io_get; diff --git a/src/stat.cc b/src/stat.cc index 6e7ad68c7e..e38fb5136f 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.153 1997/08/10 04:42:47 wessels Exp $ + * $Id: stat.cc,v 1.154 1997/08/10 06:34:32 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -139,6 +139,7 @@ static void info_get_mallstat _PARAMS((int, int, StoreEntry *)); #define PCONN_HIST_SZ 256 int client_pconn_hist[PCONN_HIST_SZ]; +int server_pconn_hist[PCONN_HIST_SZ]; /* process utilization information */ static void @@ -887,8 +888,10 @@ stat_init(cacheinfo ** object, const char *logfilename) obj->proto_stat_data[i].kb.now = 0; } *object = obj; - for (i = 0; i < PCONN_HIST_SZ; i++) + for (i = 0; i < PCONN_HIST_SZ; i++) { client_pconn_hist[i] = 0; + server_pconn_hist[i] = 0; + } } void @@ -899,6 +902,10 @@ pconnHistCount(int what, int i) /* what == 0 for client, 1 for server */ if (what == 0) client_pconn_hist[i]++; + else if (what == 1) + server_pconn_hist[i]++; + else + fatal_dump("pconnHistCount: bad 'what' arg"); } void @@ -908,12 +915,24 @@ pconnHistDump(StoreEntry * e) storeAppendPrintf(e, "Client-side persistent connection counts:\n" "\n" - "req/\n" - "conn count\n" - "---- ---------\n"); + "\treq/\n" + "\tconn count\n" + "\t---- ---------\n"); for (i = 0; i < PCONN_HIST_SZ; i++) { if (client_pconn_hist[i] == 0) continue; - storeAppendPrintf(e, "%4d %9d\n", i, client_pconn_hist[i]); + storeAppendPrintf(e, "\t%4d %9d\n", i, client_pconn_hist[i]); + } + storeAppendPrintf(e, + "\n" + "Server-side persistent connection counts:\n" + "\n" + "\treq/\n" + "\tconn count\n" + "\t---- ---------\n"); + for (i = 0; i < PCONN_HIST_SZ; i++) { + if (server_pconn_hist[i] == 0) + continue; + storeAppendPrintf(e, "\t%4d %9d\n", i, server_pconn_hist[i]); } } diff --git a/src/structs.h b/src/structs.h index 0cd76761df..e6dd6d454b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -302,6 +302,7 @@ struct _fde { int flags; int bytes_read; int bytes_written; + int uses; /* ie # req's over persistent conn */ struct _fde_disk { DWCB *wrt_handle; void *wrt_handle_data; diff --git a/src/url.cc b/src/url.cc index f03d876923..46a9dca91f 100644 --- a/src/url.cc +++ b/src/url.cc @@ -1,6 +1,6 @@ /* - * $Id: url.cc,v 1.61 1997/08/10 04:42:50 wessels Exp $ + * $Id: url.cc,v 1.62 1997/08/10 06:34:33 wessels Exp $ * * DEBUG: section 23 URL Parsing * AUTHOR: Duane Wessels @@ -338,7 +338,7 @@ urlClean(char *dirty) request_t * -requestLink(const request_t * request) +requestLink(request_t * request) { request->link_count++; return request;