From 8a7e9aeb660a4387ad53bfa2b04afd2b313207d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Wed, 15 Mar 2006 18:06:55 +0000 Subject: [PATCH] merge 1.5 --- org.glite.lb.server-bones/examples/cnt_example.c | 32 ++++++----- org.glite.lb.server-bones/project/build.number | 4 +- .../project/version.properties | 5 +- org.glite.lb.server-bones/src/srvbones.c | 64 ++++++++++++++-------- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/org.glite.lb.server-bones/examples/cnt_example.c b/org.glite.lb.server-bones/examples/cnt_example.c index 5f73a23..80b6af3 100644 --- a/org.glite.lb.server-bones/examples/cnt_example.c +++ b/org.glite.lb.server-bones/examples/cnt_example.c @@ -21,6 +21,7 @@ static struct option opts[] = { { "debug", no_argument, NULL, 'd'}, { "msg", required_argument, NULL, 'm'}, { "port", required_argument, NULL, 'p'}, + { "repeat", required_argument, NULL, 'r'}, }; int debug = 0; @@ -49,11 +50,11 @@ int main(int argc, char **argv) int opt, sock, n; - + int repeat = 1; me = strrchr(argv[0], '/'); if ( me ) me++; else me = argv[0]; - while ( (opt = getopt_long(argc, argv,"p:m:hd", opts, NULL)) != EOF ) + while ( (opt = getopt_long(argc, argv,"p:m:hdr:", opts, NULL)) != EOF ) { switch ( opt ) { @@ -64,6 +65,7 @@ int main(int argc, char **argv) port = atoi(optarg); break; case 'd': debug = 1; break; + case 'r': repeat = atoi(optarg); break; case 'h': usage(me); return 0; case '?': usage(me); return 1; } @@ -84,19 +86,21 @@ int main(int argc, char **argv) exit(1); } n = strlen(msg? msg: DEF_MSG); - if ( writen(sock, msg? msg: DEF_MSG, n) != n ) - { - dprintf(("error writing message\n")); - exit(1); - } - printf("reply: "); fflush(stdout); - n = readln(sock, buff); - if ( n < 0 ) - { - perror("read() reply error"); - return 1; + for (;repeat; repeat--) { + if ( writen(sock, msg? msg: DEF_MSG, n) != n ) + { + dprintf(("error writing message\n")); + exit(1); + } + printf("reply: "); fflush(stdout); + n = readln(sock, buff); + if ( n < 0 ) + { + perror("read() reply error"); + return 1; + } + writen(0, buff, n); } - writen(0, buff, n); close(sock); return 0; diff --git a/org.glite.lb.server-bones/project/build.number b/org.glite.lb.server-bones/project/build.number index 54c73e8..450336a 100644 --- a/org.glite.lb.server-bones/project/build.number +++ b/org.glite.lb.server-bones/project/build.number @@ -1,2 +1,2 @@ -#Sat Oct 15 06:44:59 CEST 2005 -module.build=111 +#Wed Mar 15 04:51:17 CET 2006 +module.build=0191 diff --git a/org.glite.lb.server-bones/project/version.properties b/org.glite.lb.server-bones/project/version.properties index f995e99..cb5e58b 100644 --- a/org.glite.lb.server-bones/project/version.properties +++ b/org.glite.lb.server-bones/project/version.properties @@ -1,4 +1,3 @@ #Fri Sep 02 14:17:59 CEST 2005 -module.version=2.2.0 -module.build=2 -module.age=1 +module.version=2.1.4 +module.age=0 diff --git a/org.glite.lb.server-bones/src/srvbones.c b/org.glite.lb.server-bones/src/srvbones.c index 12f748e..b4b8b3f 100644 --- a/org.glite.lb.server-bones/src/srvbones.c +++ b/org.glite.lb.server-bones/src/srvbones.c @@ -22,10 +22,12 @@ #define SLAVES_COUNT 5 /* default number of slaves */ #define SLAVE_OVERLOAD 10 /* queue items per slave */ -#define SLAVE_CONNS_MAX 500 /* commit suicide after that many connections */ +#define SLAVE_REQS_MAX 500 /* commit suicide after that many connections */ #define IDLE_TIMEOUT 30 /* keep idle connection that many seconds */ #define CONNECT_TIMEOUT 5 /* timeout for establishing a connection */ #define REQUEST_TIMEOUT 10 /* timeout for a single request */ +#define NEW_CLIENT_DURATION 10 /* how long a client is considered new, i.e. busy + connection is not closed to serve other clients */ #ifndef dprintf #define dprintf(x) { if (debug) printf x; } @@ -44,7 +46,7 @@ static int services_ct; static int set_slaves_ct = SLAVES_COUNT; static int set_slave_overload = SLAVE_OVERLOAD; -static int set_slave_conns_max = SLAVE_CONNS_MAX; +static int set_slave_reqs_max = SLAVE_REQS_MAX; static struct timeval set_idle_to = {IDLE_TIMEOUT, 0}; static struct timeval set_connect_to = {CONNECT_TIMEOUT, 0}; static struct timeval set_request_to = {REQUEST_TIMEOUT, 0}; @@ -256,7 +258,8 @@ static int dispatchit(int sock_slave, int sock, int sidx) else { services[sidx].on_reject_hnd(conn); - dprintf(("[master] Reject due to overload\n")); + dprintf(("[master] Rejected new connection due to overload\n")); + if ( !debug ) syslog(LOG_ERR, "Rejected new connection due to overload\n"); } close(conn); @@ -276,16 +279,17 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) sigset_t sset; struct sigaction sa; struct timeval client_done, - client_start; + client_start, + new_client_duration = { NEW_CLIENT_DURATION, 0 }; void *clnt_data = NULL; int conn = -1, srv = -1, - conn_cnt = 0, + req_cnt = 0, sockflags, h_errno, pid, i, - first_request = 0; + first_request = 0; /* 1 -> first request from connected client expected */ @@ -322,19 +326,23 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) */ exit(1); - while ( !die && (conn_cnt < set_slave_conns_max || conn >= 0) ) + while ( !die && req_cnt < set_slave_reqs_max) { fd_set fds; int max = sock, connflags, newconn = -1, - newsrv = -1, - kick_client = 0; + newsrv = -1; + + enum { KICK_DONT = 0, KICK_IDLE, KICK_LOAD, KICK_HANDLER, KICK_COUNT } + kick_client = KICK_DONT; + static char * kicks[] = { "don't kick", "idle client", "high load", - "no request handler" + "no request handler", + "request count limit reached", }; unsigned long seq; struct timeval now,to; @@ -367,9 +375,8 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) sigprocmask(SIG_BLOCK, &sset, NULL); gettimeofday(&now,NULL); - if (conn >= 0 && check_timeout(set_idle_to, client_done, now)) kick_client = 1; - if ( conn >= 0 && !kick_client && FD_ISSET(conn, &fds) ) + if ( conn >= 0 && FD_ISSET(conn, &fds) ) { /* * serve the request @@ -377,11 +384,12 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) int rv; dprintf(("[%d] incoming request\n", getpid())); + if ( !services[srv].on_request_hnd ) { - kick_client = 3; + kick_client = KICK_HANDLER; } else { - + req_cnt++; first_request = 0; to = set_request_to; if ((rv = services[srv].on_request_hnd(conn,to.tv_sec>=0 ? &to : NULL,clnt_data)) == ENOTCONN) { @@ -417,14 +425,20 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) gettimeofday(&client_done, NULL); } - continue; + if (!check_timeout(new_client_duration,client_start,now)) continue; } + } else { + if (conn >= 0 && check_timeout(set_idle_to, client_done, now)) + kick_client = KICK_IDLE; } - if ( !first_request && FD_ISSET(sock, &fds) && conn_cnt < set_slave_conns_max ) + if ( (conn < 0 || !first_request) && FD_ISSET(sock, &fds) && req_cnt < set_slave_reqs_max ) { - if ( conn >= 0 ) usleep(100000 + 1000 * (random() % 200)); + /* Prefer slaves with no connection, then kick idle clients, + * active ones last. Wait less if we have serviced a request in the meantime. + * Tuned for HZ=100 timer. */ + if ( conn >= 0 ) usleep( kick_client || FD_ISSET(conn, &fds) ? 11000 : 21000); if ( do_recvmsg(sock, &newconn, &seq, &newsrv) ) switch ( errno ) { case EINTR: /* XXX: signals are blocked */ @@ -434,9 +448,11 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) if (!debug) syslog(LOG_CRIT,"recvmsg(): %m\n"); exit(1); } - kick_client = 2; + kick_client = KICK_LOAD; } + if (req_cnt >= set_slave_reqs_max) kick_client = KICK_COUNT; + if ( kick_client && conn >= 0 ) { if ( services[srv].on_disconnect_hnd ) @@ -469,7 +485,7 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) exit(1); } - conn_cnt++; + req_cnt++; dprintf(("[%d] serving %s connection %lu\n", getpid(), services[srv].id? services[srv].id: "", seq)); @@ -502,8 +518,12 @@ static int slave(slave_data_init_hnd data_init_hnd, int sock) dprintf(("[%d] Terminating on signal %d\n", getpid(), die)); if ( !debug ) syslog(LOG_INFO, "Terminating on signal %d", die); } - dprintf(("[%d] Terminating after %d connections\n", getpid(), conn_cnt)); - if ( !debug ) syslog(LOG_INFO, "Terminating after %d connections", conn_cnt); + + if (conn >= 0 && services[srv].on_disconnect_hnd ) + services[srv].on_disconnect_hnd(conn, NULL, clnt_data); + + dprintf(("[%d] Terminating after %d requests\n", getpid(), req_cnt)); + if ( !debug ) syslog(LOG_INFO, "Terminating after %d requests", req_cnt); exit(0); @@ -618,7 +638,7 @@ static void glite_srvbones_set_slave_overload(int n) static void glite_srvbones_set_slave_conns_max(int n) { - set_slave_conns_max = (n == -1)? SLAVE_CONNS_MAX: n; + set_slave_reqs_max = (n == -1)? SLAVE_REQS_MAX: n; } static void set_timeout(struct timeval *to, struct timeval *val) -- 1.8.2.3