Commit 1cedfdb0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk@4494 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 70ba79fd
......@@ -233,6 +233,12 @@ struct worker {
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 @@ struct sess {
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 @@ struct vbe_conn {
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_New(void);
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);
......
......@@ -91,6 +91,17 @@ VBE_ReleaseConn(struct vbe_conn *vc)
}
}
#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 @@ vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa,
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,9 +126,9 @@ vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa,
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);
......@@ -412,7 +424,7 @@ VBE_GetFd(const struct director *d, struct sess *sp)
return (d->getfd(d, sp));
}
/* Cheack health -----------------------------------------------------*/
/* Check health ------------------------------------------------------*/
int
VBE_Healthy(const struct director *d, const struct sess *sp)
......@@ -442,11 +454,19 @@ static struct vbe_conn *
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
......
......@@ -864,6 +864,9 @@ cnt_miss(struct sess *sp)
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 @@ cnt_pass(struct sess *sp)
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 @@ cnt_recv(struct sess *sp)
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];
......
......@@ -335,6 +335,7 @@ FetchHdr(struct sess *sp)
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 @@ FetchHdr(struct sess *sp)
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 @@ FetchHdr(struct sess *sp)
/* 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,9 +402,12 @@ FetchHdr(struct sess *sp)
/* 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;
......
......@@ -179,8 +179,6 @@ ses_setup(struct sessmem *sm)
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 @@ SES_Init()
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;
}
......@@ -453,42 +453,42 @@ void
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);
}
/*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment