From: wessels <> Date: Tue, 21 Jul 1998 09:16:04 +0000 (+0000) Subject: New refresh algorithm. No longer set entry->lastmod == entry->timestamp X-Git-Tag: SQUID_3_0_PRE1~3028 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1c3e77cd17c0d0727042c796860ac27e21019e09;p=thirdparty%2Fsquid.git New refresh algorithm. No longer set entry->lastmod == entry->timestamp when the Last-Modified header is absent. Also, don't do ISM validations without a Last-Modified timestamp. --- diff --git a/src/client_side.cc b/src/client_side.cc index 94ef3f24f0..c4ad34ca7e 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.359 1998/07/20 20:37:38 wessels Exp $ + * $Id: client_side.cc,v 1.360 1998/07/21 03:16:04 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -234,6 +234,7 @@ clientProcessExpired(void *data) char *url = http->uri; StoreEntry *entry = NULL; debug(33, 3) ("clientProcessExpired: '%s'\n", http->uri); + assert(entry->lastmod >= 0); /* * check if we are allowed to contact other servers * @?@: Instead of a 504 (Gateway Timeout) reply, we may want to return @@ -253,8 +254,7 @@ clientProcessExpired(void *data) storeClientListAdd(entry, http); storeClientListAdd(http->old_entry, http); entry->lastmod = http->old_entry->lastmod; - debug(33, 5) ("clientProcessExpired: setting lmt = %d\n", - (int) entry->lastmod); + debug(33, 5) ("clientProcessExpired: lastmod %d\n", (int) entry->lastmod); entry->refcount++; /* EXPIRED CASE */ http->entry = entry; http->out.offset = 0; @@ -405,17 +405,21 @@ modifiedSince(StoreEntry * entry, request_t * request) { int object_length; MemObject *mem = entry->mem_obj; + time_t mod_time = entry->lastmod; debug(33, 3) ("modifiedSince: '%s'\n", storeUrl(entry)); - if (entry->lastmod < 0) + if (mod_time < 0) + mod_time = entry->timestamp; + debug(33,3)("modifiedSince: mod_time = %d\n", (int) mod_time); + if (mod_time < 0) return 1; /* Find size of the object */ object_length = mem->reply->content_length; if (object_length < 0) object_length = contentLen(entry); - if (entry->lastmod > request->ims) { + if (mod_time > request->ims) { debug(33, 3) ("--> YES: entry newer than client\n"); return 1; - } else if (entry->lastmod < request->ims) { + } else if (mod_time < request->ims) { debug(33, 3) ("--> NO: entry older than client\n"); return 0; } else if (request->imslen < 0) { @@ -884,7 +888,9 @@ isTcpHit(log_type code) return 0; } -/* returns true if If-Range specs match reply, false otherwise */ +/* + * returns true if If-Range specs match reply, false otherwise + */ static int clientIfRangeMatch(clientHttpRequest * http, HttpReply * rep) { @@ -1159,7 +1165,14 @@ clientCacheHit(void *data, char *buf, ssize_t size) /* * We hold a stale copy; it needs to be validated */ - if (r->protocol == PROTO_HTTP) { + if (e->lastmod < 0) { + /* + * Previous reply didn't have a Last-Modified header, + * we cannot revalidate it. + */ + http->log_type = LOG_TCP_MISS; + clientProcessMiss(http); + } else if (r->protocol == PROTO_HTTP) { http->log_type = LOG_TCP_REFRESH_MISS; clientProcessExpired(http); } else { diff --git a/src/main.cc b/src/main.cc index 0080ab55dc..c46092e7e6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.255 1998/07/20 17:19:51 wessels Exp $ + * $Id: main.cc,v 1.256 1998/07/21 03:16:05 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -499,6 +499,7 @@ mainInitialize(void) mimeInit(Config.mimeTablePathname); pconnInit(); eventInit(); + refreshInit(); } serverConnectionsOpen(); if (theOutIcpConnection >= 0 && (!Config2.Accel.on || Config.onoff.accel_with_proxy)) diff --git a/src/protos.h b/src/protos.h index 1499a09fa5..e31dc8a81b 100644 --- a/src/protos.h +++ b/src/protos.h @@ -609,6 +609,7 @@ extern void refreshAddToList(const char *, int, time_t, int, time_t); extern int refreshCheck(const StoreEntry *, request_t *, time_t delta); extern time_t refreshWhen(const StoreEntry * entry); extern time_t getMaxAge(const char *url); +extern void refreshInit(void); extern void serverConnectionsClose(void); extern void shut_down(int); diff --git a/src/refresh.cc b/src/refresh.cc index a8ff2d71ad..329421b92b 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -1,6 +1,6 @@ /* - * $Id: refresh.cc,v 1.25 1998/07/20 17:20:03 wessels Exp $ + * $Id: refresh.cc,v 1.26 1998/07/21 03:16:07 wessels Exp $ * * DEBUG: section 22 Refresh Calculation * AUTHOR: Harvest Derived @@ -35,6 +35,19 @@ #include "squid.h" +struct { + int total; + int revalidate_stale; + int request_max_age_stale; + int response_expires_stale; + int response_expires_fresh; + int conf_max_age_stale; + int last_modified_factor_fresh; + int last_modified_factor_stale; + int conf_min_age_fresh; + int default_stale; +} refreshCounts; + /* * Defaults: * MIN NONE @@ -47,6 +60,7 @@ static const refresh_t * refreshLimits(const char *); static const refresh_t *refreshUncompiledPattern(const char *); +static OBJH refreshStats; static const refresh_t * refreshLimits(const char *url) @@ -91,8 +105,10 @@ refreshCheck(const StoreEntry * entry, request_t * request, time_t delta) else uri = urlCanonical(request); debug(22, 3) ("refreshCheck: '%s'\n", uri); + refreshCounts.total++; if (EBIT_TEST(entry->flag, ENTRY_REVALIDATE)) { debug(22, 3) ("refreshCheck: YES: Required Authorization\n"); + refreshCounts.revalidate_stale++; return 1; } if ((R = refreshLimits(uri))) { @@ -110,41 +126,45 @@ refreshCheck(const StoreEntry * entry, request_t * request, time_t delta) if (request->max_age > -1) { if (age > request->max_age) { debug(22, 3) ("refreshCheck: YES: age > client-max-age\n"); + refreshCounts.request_max_age_stale++; return 1; } } - if (age <= min) { - debug(22, 3) ("refreshCheck: NO: age < min\n"); - return 0; - } - if (-1 < entry->expires) { + if (entry->expires > -1) { if (entry->expires <= check_time) { debug(22, 3) ("refreshCheck: YES: expires <= curtime\n"); + refreshCounts.response_expires_stale++; return 1; } else { debug(22, 3) ("refreshCheck: NO: expires > curtime\n"); + refreshCounts.response_expires_fresh++; return 0; } } if (age > max) { debug(22, 3) ("refreshCheck: YES: age > max\n"); + refreshCounts.conf_max_age_stale++; return 1; } - if (entry->timestamp <= entry->lastmod) { - if (request->protocol != PROTO_HTTP) { - debug(22, 3) ("refreshCheck: NO: non-HTTP request\n"); + if (entry->lastmod > -1 && entry->timestamp > entry->lastmod) { + factor = (double) age / (double) (entry->timestamp - entry->lastmod); + debug(22, 3) ("refreshCheck: factor = %f\n", factor); + if (factor < pct) { + debug(22, 3) ("refreshCheck: NO: factor < pct\n"); + refreshCounts.last_modified_factor_fresh++; return 0; + } else { + debug(22, 3) ("refreshCheck: YES: factor >= pct\n"); + refreshCounts.last_modified_factor_stale++; + return 1; } - debug(22, 3) ("refreshCheck: YES: lastvalid <= lastmod (%d <= %d)\n", - (int) entry->timestamp, (int) entry->lastmod); - return 1; } - factor = (double) age / (double) (entry->timestamp - entry->lastmod); - debug(22, 3) ("refreshCheck: factor = %f\n", factor); - if (factor < pct) { - debug(22, 3) ("refreshCheck: NO: factor < pct\n"); + if (age <= min) { + debug(22, 3) ("refreshCheck: NO: age < min\n"); + refreshCounts.conf_min_age_fresh++; return 0; } + refreshCounts.default_stale++; return 1; } @@ -213,3 +233,38 @@ getMaxAge(const char *url) else return REFRESH_DEFAULT_MAX; } + +static void +refreshStats(StoreEntry * sentry) +{ + storeAppendPrintf(sentry, "refreshCounts.total\t%d\n", + refreshCounts.total); + storeAppendPrintf(sentry, "refreshCounts.revalidate_stale\t%d\n", + refreshCounts.revalidate_stale); + storeAppendPrintf(sentry, "refreshCounts.request_max_age_stale\t%d\n", + refreshCounts.request_max_age_stale); + storeAppendPrintf(sentry, "refreshCounts.response_expires_stale\t%d\n", + refreshCounts.response_expires_stale); + storeAppendPrintf(sentry, "refreshCounts.response_expires_fresh\t%d\n", + refreshCounts.response_expires_fresh); + storeAppendPrintf(sentry, "refreshCounts.conf_max_age_stale\t%d\n", + refreshCounts.conf_max_age_stale); + storeAppendPrintf(sentry, "refreshCounts.last_modified_factor_fresh\t%d\n", + refreshCounts.last_modified_factor_fresh); + storeAppendPrintf(sentry, "refreshCounts.last_modified_factor_stale\t%d\n", + refreshCounts.last_modified_factor_stale); + storeAppendPrintf(sentry, "refreshCounts.conf_min_age_fresh\t%d\n", + refreshCounts.conf_min_age_fresh); + storeAppendPrintf(sentry, "refreshCounts.default_stale\t%d\n", + refreshCounts.default_stale); +} + +void +refreshInit(void) +{ + cachemgrRegister("refresh", + "Refresh Algorithm Statistics", + refreshStats, + 0, + 1); +} diff --git a/src/store.cc b/src/store.cc index 9f49c4fb08..33e89e764a 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.429 1998/07/20 20:21:11 wessels Exp $ + * $Id: store.cc,v 1.430 1998/07/21 03:16:08 wessels Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -983,10 +983,7 @@ storeTimestampsSet(StoreEntry * entry) if (served_date < 0) served_date = squid_curtime; entry->expires = reply->expires; - if (reply->last_modified > -1) - entry->lastmod = reply->last_modified; - if (entry->lastmod < 0) - entry->lastmod = served_date; + entry->lastmod = reply->last_modified; entry->timestamp = served_date; }