r4494 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Tue Jan 26 23:56:39 CET 2010
Author: phk
Date: 2010-01-26 23:56:39 +0100 (Tue, 26 Jan 2010)
New Revision: 4494
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_fetch.c
trunk/varnish-cache/bin/varnishd/cache_session.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Move the backend timeouts out of struct sess, they don't belong there.
Put the fields VCL tweaks in the worker, and figure out the real
numbers when we connect/have connected to a backend, and but the
numbers in the vbe_conn.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2010-01-26 22:56:39 UTC (rev 4494)
@@ -233,6 +233,12 @@
double ttl;
double grace;
unsigned do_esi;
+
+ /* Timeouts */
+ double connect_timeout;
+ double first_byte_timeout;
+ double between_bytes_timeout;
+
};
/* Work Request for worker thread ------------------------------------*/
@@ -390,11 +396,6 @@
double t_resp;
double t_end;
- /* Timeouts */
- double connect_timeout;
- double first_byte_timeout;
- double between_bytes_timeout;
-
/* Acceptable grace period */
double grace;
@@ -436,6 +437,10 @@
VTAILQ_ENTRY(vbe_conn) list;
struct backend *backend;
int fd;
+
+ /* Timeouts */
+ double first_byte_timeout;
+ double between_bytes_timeout;
};
/* Prototypes etc ----------------------------------------------------*/
@@ -612,8 +617,6 @@
struct sess *SES_Alloc(void);
void SES_Delete(struct sess *sp);
void SES_Charge(struct sess *sp);
-void SES_ResetBackendTimeouts(struct sess *sp);
-void SES_InheritBackendTimeouts(struct sess *sp);
/* cache_shmlog.c */
void VSL_Init(void);
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-01-26 22:56:39 UTC (rev 4494)
@@ -91,6 +91,17 @@
}
}
+#define FIND_TMO(tmx, dst, sp, be) \
+ do { \
+ dst = sp->wrk->tmx; \
+ if (dst == 0.0) \
+ dst = be->tmx; \
+ if (dst == 0.0) \
+ dst = params->tmx; \
+ assert(dst > 0.0); \
+ } while (0)
+
+
/*--------------------------------------------------------------------
* Attempt to connect to a given addrinfo entry.
*
@@ -105,6 +116,7 @@
socklen_t salen, const struct backend *bp)
{
int s, i, tmo;
+ double tmod;
char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];
@@ -114,10 +126,10 @@
if (s < 0)
return (s);
- tmo = (int)(sp->connect_timeout * 1000);
- if (bp->connect_timeout > 10e-3)
- tmo = (int)(bp->connect_timeout * 1000);
+ FIND_TMO(connect_timeout, tmod, sp, bp);
+ tmo = (int)(tmod * 1000.0);
+
if (tmo > 0)
i = TCP_connect(s, sa, salen, tmo);
else
@@ -412,7 +424,7 @@
return (d->getfd(d, sp));
}
-/* Cheack health -----------------------------------------------------*/
+/* Check health ------------------------------------------------------*/
int
VBE_Healthy(const struct director *d, const struct sess *sp)
@@ -442,11 +454,19 @@
vdi_simple_getfd(const struct director *d, struct sess *sp)
{
struct vdi_simple *vs;
+ struct vbe_conn *vc;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
- return (vbe_GetVbe(sp, vs->backend));
+ vc = vbe_GetVbe(sp, vs->backend);
+ if (vc != NULL) {
+ FIND_TMO(first_byte_timeout,
+ vc->first_byte_timeout, sp, vc->backend);
+ FIND_TMO(between_bytes_timeout,
+ vc->between_bytes_timeout, sp, vc->backend);
+ }
+ return (vc);
}
static unsigned
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2010-01-26 22:56:39 UTC (rev 4494)
@@ -864,6 +864,9 @@
sp->wrk->bereq = sp->wrk->http[0];
http_Setup(sp->wrk->bereq, sp->wrk->ws);
http_FilterHeader(sp, HTTPH_R_FETCH);
+ sp->wrk->connect_timeout = 0;
+ sp->wrk->first_byte_timeout = 0;
+ sp->wrk->between_bytes_timeout = 0;
VCL_miss_method(sp);
switch(sp->handling) {
case VCL_RET_ERROR:
@@ -930,6 +933,9 @@
http_Setup(sp->wrk->bereq, sp->wrk->ws);
http_FilterHeader(sp, HTTPH_R_PASS);
+ sp->wrk->connect_timeout = 0;
+ sp->wrk->first_byte_timeout = 0;
+ sp->wrk->between_bytes_timeout = 0;
VCL_pass_method(sp);
if (sp->handling == VCL_RET_ERROR) {
sp->step = STP_ERROR;
@@ -1020,8 +1026,6 @@
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
AZ(sp->obj);
- SES_ResetBackendTimeouts(sp);
-
/* By default we use the first backend */
AZ(sp->director);
sp->director = sp->vcl->director[0];
Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-01-26 22:56:39 UTC (rev 4494)
@@ -335,6 +335,7 @@
char *b;
struct http *hp;
int i;
+ double tmo;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
@@ -357,8 +358,6 @@
return (__LINE__);
}
vc = sp->vbe;
- /* Inherit the backend timeouts from the selected backend */
- SES_InheritBackendTimeouts(sp);
/*
* Now that we know our backend, we can set a default Host:
@@ -390,7 +389,10 @@
/* Receive response */
HTC_Init(sp->wrk->htc, sp->wrk->ws, vc->fd);
- TCP_set_read_timeout(vc->fd, sp->first_byte_timeout);
+
+ TCP_set_read_timeout(vc->fd, vc->first_byte_timeout);
+ tmo = vc->first_byte_timeout;
+
do {
i = HTC_Rx(sp->wrk->htc);
if (i < 0) {
@@ -400,10 +402,13 @@
/* XXX: other cleanup ? */
return (__LINE__);
}
- TCP_set_read_timeout(vc->fd, sp->between_bytes_timeout);
- }
- while (i == 0);
+ if (vc->between_bytes_timeout != tmo) {
+ TCP_set_read_timeout(vc->fd, vc->between_bytes_timeout);
+ tmo = vc->between_bytes_timeout;
+ }
+ } while (i == 0);
+
hp = sp->wrk->beresp;
if (http_DissectResponse(sp->wrk, sp->wrk->htc, hp)) {
Modified: trunk/varnish-cache/bin/varnishd/cache_session.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_session.c 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache_session.c 2010-01-26 22:56:39 UTC (rev 4494)
@@ -179,8 +179,6 @@
WS_Init(sp->ws, "sess", sm->wsp, sm->workspace);
sp->http = sm->http[0];
sp->http0 = sm->http[1];
-
- SES_ResetBackendTimeouts(sp);
}
/*--------------------------------------------------------------------
@@ -300,39 +298,3 @@
Lck_New(&stat_mtx);
Lck_New(&ses_mem_mtx);
}
-
-/* XXX: We should use NAN as default marker */
-
-void
-SES_ResetBackendTimeouts(struct sess *sp)
-{
- sp->connect_timeout = params->connect_timeout;
- sp->first_byte_timeout = params->first_byte_timeout;
- sp->between_bytes_timeout = params->between_bytes_timeout;
-}
-
-void
-SES_InheritBackendTimeouts(struct sess *sp)
-{
- struct backend *be;
-
- AN(sp);
- AN(sp->vbe);
- AN(sp->vbe->backend);
-
- be = sp->vbe->backend;
- /*
- * We only inherit the backend's timeout if the session timeout
- * has not already been set in the VCL, as the order of precedence
- * is parameter < backend definition < VCL.
- */
- if (be->connect_timeout > 1e-3 &&
- sp->connect_timeout == params->connect_timeout)
- sp->connect_timeout = be->connect_timeout;
- if (be->first_byte_timeout > 1e-3 &&
- sp->first_byte_timeout == params->first_byte_timeout)
- sp->first_byte_timeout = be->first_byte_timeout;
- if (be->between_bytes_timeout > 1e-3 &&
- sp->between_bytes_timeout == params->between_bytes_timeout)
- sp->between_bytes_timeout = be->between_bytes_timeout;
-}
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-01-26 21:58:30 UTC (rev 4493)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-01-26 22:56:39 UTC (rev 4494)
@@ -453,42 +453,42 @@
VRT_l_bereq_connect_timeout(struct sess *sp, double num)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- sp->connect_timeout = (num > 0 ? num : 0);
+ sp->wrk->connect_timeout = (num > 0 ? num : 0);
}
double
VRT_r_bereq_connect_timeout(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- return sp->connect_timeout;
+ return (sp->wrk->connect_timeout);
}
void
VRT_l_bereq_first_byte_timeout(struct sess *sp, double num)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- sp->first_byte_timeout = (num > 0 ? num : 0);
+ sp->wrk->first_byte_timeout = (num > 0 ? num : 0);
}
double
VRT_r_bereq_first_byte_timeout(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- return sp->first_byte_timeout;
+ return (sp->wrk->first_byte_timeout);
}
void
VRT_l_bereq_between_bytes_timeout(struct sess *sp, double num)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- sp->between_bytes_timeout = (num > 0 ? num : 0);
+ sp->wrk->between_bytes_timeout = (num > 0 ? num : 0);
}
double
VRT_r_bereq_between_bytes_timeout(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- return sp->between_bytes_timeout;
+ return (sp->wrk->between_bytes_timeout);
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list