Mailing List Archive

r879 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2006-08-21 22:25:28 +0200 (Mon, 21 Aug 2006)
New Revision: 879

Modified:
trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
Log:
Fix these two up to current standard.

Poll is tested, epoll isn't.

While the three implementations share a lot of identical code
right now, I will wait a bit before unifying more of them, at
least until performance proves that this is the right way for
kqueue.

XXX: they're really not acceptors any more, they're herders.



Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2006-08-21 20:23:47 UTC (rev 878)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2006-08-21 20:25:28 UTC (rev 879)
@@ -14,15 +14,8 @@
#include <stdlib.h>
#include <unistd.h>

-#include <sys/uio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
#include <sys/epoll.h>

-#ifndef HAVE_SRANDOMDEV
-#include "compat/srandomdev.h"
-#endif
-
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
@@ -52,28 +45,13 @@
{

CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- clock_gettime(CLOCK_MONOTONIC, &sp->t_idle);
- TAILQ_INSERT_TAIL(&sesshead, sp, list);
- vca_add(sp->fd, sp);
}

-static void
-accept_f(int fd)
-{
- struct sess *sp;
-
- sp = vca_accept_sess(fd);
- if (sp == NULL)
- return;
- http_RecvPrep(sp->http);
- vca_rcvhdev(sp);
-}
-
static void *
vca_main(void *arg)
{
struct epoll_event ev;
- struct timespec t;
+ struct timespec ts;
struct sess *sp, *sp2;
int i;

@@ -82,49 +60,45 @@
epfd = epoll_create(16);
assert(epfd >= 0);

- AZ(pipe(pipes));
vca_add(pipes[0], pipes);

- if (heritage.socket >= 0)
- vca_add(heritage.socket, accept_f);
-
while (1) {
- if (epoll_wait(epfd, &ev, 1, 5000) > 0) {
+ if (epoll_wait(epfd, &ev, 1, 100) > 0) {
if (ev.data.ptr == pipes) {
i = read(pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (http_RecvPrepAgain(sp->http))
- vca_handover(sp, 0);
- else
- vca_rcvhdev(sp);
- } else if (ev.data.ptr == accept_f) {
- accept_f(heritage.socket);
+ TAILQ_INSERT_TAIL(&sesshead, sp, list);
+ vca_add(sp->fd, sp);
} else {
CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC);
- i = http_RecvSome(sp->fd, sp->http);
- if (i != -1) {
+ i = vca_pollsession(sp);
+ if (i >= 0) {
TAILQ_REMOVE(&sesshead, sp, list);
vca_del(sp->fd);
- vca_handover(sp, i);
+ if (i == 0)
+ vca_handover(sp, i);
+ else
+ SES_Delete(sp);
}
}
}
/* check for timeouts */
- clock_gettime(CLOCK_MONOTONIC, &t);
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec -= params->sess_timeout;
TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (sp->t_idle.tv_sec + params->sess_timeout < t.tv_sec) {
- TAILQ_REMOVE(&sesshead, sp, list);
- vca_del(sp->fd);
- vca_close_session(sp, "timeout");
- vca_return_session(sp);
+ if (sp->t_open.tv_sec > ts.tv_sec)
continue;
- }
+ if (sp->t_open.tv_sec == ts.tv_sec &&
+ sp->t_open.tv_nsec > ts.tv_nsec)
+ continue;
+ TAILQ_REMOVE(&sesshead, sp, list);
+ vca_del(sp->fd);
+ vca_close_session(sp, "timeout");
+ SES_Delete(sp);
}
}
-
- INCOMPL();
}

/*--------------------------------------------------------------------*/
@@ -133,18 +107,17 @@
vca_epoll_recycle(struct sess *sp)
{

- if (sp->fd < 0) {
+ if (sp->fd < 0)
SES_Delete(sp);
- return;
- }
- (void)clock_gettime(CLOCK_REALTIME, &sp->t_open);
- VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
- assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
+ else
+ assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
}

static void
vca_epoll_init(void)
{
+
+ AZ(pipe(pipes));
AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
}


Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2006-08-21 20:23:47 UTC (rev 878)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2006-08-21 20:25:28 UTC (rev 879)
@@ -15,14 +15,6 @@
#include <unistd.h>
#include <poll.h>

-#include <sys/uio.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#ifndef HAVE_SRANDOMDEV
-#include "compat/srandomdev.h"
-#endif
-
#include "heritage.h"
#include "shmlog.h"
#include "cache.h"
@@ -80,89 +72,58 @@

/*--------------------------------------------------------------------*/

-static void
-vca_rcvhdev(struct sess *sp)
-{
-
- CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- clock_gettime(CLOCK_MONOTONIC, &sp->t_idle);
- TAILQ_INSERT_TAIL(&sesshead, sp, list);
- vca_poll(sp->fd);
-}
-
-static void
-accept_f(int fd)
-{
- struct sess *sp;
-
- sp = vca_accept_sess(fd);
- if (sp == NULL)
- return;
-
- http_RecvPrep(sp->http);
- vca_rcvhdev(sp);
-}
-
static void *
vca_main(void *arg)
{
unsigned v;
struct sess *sp, *sp2;
- struct timespec t;
+ struct timespec ts;
int i;

(void)arg;

- AZ(pipe(pipes));
vca_poll(pipes[0]);

- if (heritage.socket >= 0)
- vca_poll(heritage.socket);
-
while (1) {
- v = poll(pollfd, npoll, 5000);
+ v = poll(pollfd, npoll, 100);
if (v && pollfd[pipes[0]].revents) {
v--;
i = read(pipes[0], &sp, sizeof sp);
assert(i == sizeof sp);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- if (http_RecvPrepAgain(sp->http))
- vca_handover(sp, 0);
- else
- vca_rcvhdev(sp);
+ TAILQ_INSERT_TAIL(&sesshead, sp, list);
+ vca_poll(sp->fd);
}
- if (heritage.socket >= 0 &&
- pollfd[heritage.socket].revents) {
- accept_f(heritage.socket);
- v--;
- }
- clock_gettime(CLOCK_MONOTONIC, &t);
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec -= params->sess_timeout;
TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
+ if (v == 0)
+ break;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
if (pollfd[sp->fd].revents) {
v--;
- i = http_RecvSome(sp->fd, sp->http);
+ i = vca_pollsession(sp);
if (i < 0)
continue;
-
- vca_unpoll(sp->fd);
TAILQ_REMOVE(&sesshead, sp, list);
- vca_handover(sp, i);
- continue;
- }
- if (sp->t_idle.tv_sec + params->sess_timeout < t.tv_sec) {
- TAILQ_REMOVE(&sesshead, sp, list);
vca_unpoll(sp->fd);
- vca_close_session(sp, "timeout");
- vca_return_session(sp);
+ if (i == 0)
+ vca_handover(sp, i);
+ else
+ SES_Delete(sp);
continue;
}
- if (v == 0)
- break;
+ if (sp->t_open.tv_sec > ts.tv_sec)
+ continue;
+ if (sp->t_open.tv_sec == ts.tv_sec &&
+ sp->t_open.tv_nsec > ts.tv_nsec)
+ continue;
+ TAILQ_REMOVE(&sesshead, sp, list);
+ vca_unpoll(sp->fd);
+ vca_close_session(sp, "timeout");
+ SES_Delete(sp);
}
}
-
- INCOMPL();
}

/*--------------------------------------------------------------------*/
@@ -171,18 +132,16 @@
vca_poll_recycle(struct sess *sp)
{

- if (sp->fd < 0) {
+ if (sp->fd < 0)
SES_Delete(sp);
- return;
- }
- (void)clock_gettime(CLOCK_REALTIME, &sp->t_open);
- VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
- assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
+ else
+ assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
}

static void
vca_poll_init(void)
{
+ AZ(pipe(pipes));
AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
}