|
From: <gne...@us...> - 2007-10-20 11:57:22
|
Update of /cvsroot/aolserver/aolserver/nsd In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv9787 Modified Files: nsd.h pools.c queue.c Log Message: Continuing work on BUG #1615787; instead of performing in boundary situations in the worst case more than the configured maxconns requests, a new connection thread is created automatically after the exit of a thread coming to the end of it work cycle, when jobs are pending and no other thread is able to process these. Index: nsd.h =================================================================== RCS file: /cvsroot/aolserver/aolserver/nsd/nsd.h,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** nsd.h 20 Jun 2006 03:21:42 -0000 1.117 --- nsd.h 20 Oct 2007 11:57:19 -0000 1.118 *************** *** 984,988 **** extern int NsTclGetPool(Tcl_Interp *interp, char *pool, Pool **poolPtrPtr); extern Tcl_ObjCmdProc NsTclListPoolsObjCmd; ! extern void NsCreateConnThread(Pool *poolPtr); extern void NsJoinConnThreads(void); extern int NsStartDrivers(void); --- 984,988 ---- extern int NsTclGetPool(Tcl_Interp *interp, char *pool, Pool **poolPtrPtr); extern Tcl_ObjCmdProc NsTclListPoolsObjCmd; ! extern void NsCreateConnThread(Pool *poolPtr, int joinThreads); extern void NsJoinConnThreads(void); extern int NsStartDrivers(void); Index: pools.c =================================================================== RCS file: /cvsroot/aolserver/aolserver/nsd/pools.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** pools.c 2 Aug 2005 21:58:52 -0000 1.10 --- pools.c 20 Oct 2007 11:57:19 -0000 1.11 *************** *** 482,486 **** poolPtr->threads.current = poolPtr->threads.idle = poolPtr->threads.min; for (i = 0; i < poolPtr->threads.min; ++i) { ! NsCreateConnThread(poolPtr); } } --- 482,486 ---- poolPtr->threads.current = poolPtr->threads.idle = poolPtr->threads.min; for (i = 0; i < poolPtr->threads.min; ++i) { ! NsCreateConnThread(poolPtr, 1); } } Index: queue.c =================================================================== RCS file: /cvsroot/aolserver/aolserver/nsd/queue.c,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** queue.c 19 Oct 2007 18:00:01 -0000 1.40 --- queue.c 20 Oct 2007 11:57:19 -0000 1.41 *************** *** 185,200 **** create = 1; } /* Note that in situations, where the maximum number of connection threads is reached (poolPtr->threads.idle == 0 and create == 0) the request is queued without resources to process these. ! One has to take care about that one restarts the queue, when resources become available again. */ - ++poolPtr->queue.wait.num; Ns_MutexUnlock(&poolPtr->lock); if (create) { ! NsCreateConnThread(poolPtr); } else { Ns_CondSignal(&poolPtr->cond); --- 185,201 ---- create = 1; } + /* Note that in situations, where the maximum number of connection threads is reached (poolPtr->threads.idle == 0 and create == 0) the request is queued without resources to process these. ! One has to take care about processing he entries of the queue, when resources become available again. */ + ++poolPtr->queue.wait.num; Ns_MutexUnlock(&poolPtr->lock); if (create) { ! NsCreateConnThread(poolPtr, 1); } else { Ns_CondSignal(&poolPtr->cond); *************** *** 390,394 **** is better than a hang. */ ! while (poolPtr->threads.maxconns <= 0 || ncons-- > 0 || poolPtr->queue.wait.num > 1) { /* --- 391,398 ---- is better than a hang. */ ! while (poolPtr->threads.maxconns <= 0 ! || ncons-- > 0 ! /*|| poolPtr->queue.wait.num > 1*/ ! ) { /* *************** *** 406,420 **** status = NS_OK; ! ! if (poolPtr->queue.wait.num == 0) { /* nothing is queued, we wait for a queue entry */ ! while (!poolPtr->shutdown ! && status == NS_OK ! && poolPtr->queue.wait.firstPtr == NULL) { ! status = Ns_CondTimedWait(&poolPtr->cond, &poolPtr->lock, timePtr); ! } } if (poolPtr->queue.wait.firstPtr == NULL) { msg = "timeout waiting for connection"; --- 410,422 ---- status = NS_OK; ! while (!poolPtr->shutdown ! && status == NS_OK ! && poolPtr->queue.wait.firstPtr == NULL) { /* nothing is queued, we wait for a queue entry */ ! status = Ns_CondTimedWait(&poolPtr->cond, &poolPtr->lock, timePtr); } + if (poolPtr->queue.wait.firstPtr == NULL) { msg = "timeout waiting for connection"; *************** *** 503,506 **** --- 505,520 ---- Ns_MutexUnlock(&poolPtr->lock); + if (poolPtr->queue.wait.num > 0 && poolPtr->threads.idle == 0 && !poolPtr->shutdown) { + /* We are exiting from a thread in a situation, where more + queue entries are waiting. Since no other mechanism ensures + that the entries are processed, we recreate a new connection thread. + */ + Ns_MutexLock(&poolPtr->lock); + poolPtr->threads.current++; + poolPtr->threads.idle++; + Ns_MutexUnlock(&poolPtr->lock); + NsCreateConnThread(poolPtr, 0); /* joinThreads == 0 to avoid deadlock */ + } + Ns_Log(Notice, "exiting: %s", msg); Ns_ThreadExit(dataPtr); *************** *** 646,650 **** void ! NsCreateConnThread(Pool *poolPtr) { ConnData *dataPtr; --- 660,664 ---- void ! NsCreateConnThread(Pool *poolPtr, int joinThreads) { ConnData *dataPtr; *************** *** 654,658 **** */ ! NsJoinConnThreads(); /* --- 668,674 ---- */ ! if (joinThreads) { ! NsJoinConnThreads(); ! } /* |