Update of /cvsroot/webware/Webware/WebKit
In directory usw-pr-cvs1:/tmp/cvs-serv14835
Modified Files:
Tag: MultipleSerApp-1
ThreadedAppServer.py
Log Message:
make threadcount more aggressive. same changes put into HEAD
Index: ThreadedAppServer.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/ThreadedAppServer.py,v
retrieving revision 1.53.2.1
retrieving revision 1.53.2.2
diff -C2 -d -r1.53.2.1 -r1.53.2.2
*** ThreadedAppServer.py 2002/01/26 21:30:16 1.53.2.1
--- ThreadedAppServer.py 2002/01/27 03:39:39 1.53.2.2
***************
*** 80,84 ****
"""
Use a threadsafe storage for the Request Handler instances.
! It doesn't need to be threadsafe when we are getting an instance, but it needs it when each thread
is returning the instance it is using.
"""
--- 80,85 ----
"""
Use a threadsafe storage for the Request Handler instances.
! It doesn't need to be threadsafe when we are getting an instance,
! but it needs it when each thread
is returning the instance it is using.
"""
***************
*** 101,110 ****
def mainloop(self, timeout=1):
from errno import EINTR
!
inputsockets = self._sockets
-
! threadCheckInterval = 100 #does this need to be configurable???
! threadUpdateDivisor = 10 #grabstat interval
threadCheck=0
--- 102,110 ----
def mainloop(self, timeout=1):
from errno import EINTR
! assert timeout != 0, "Select timeout must be > 0"
inputsockets = self._sockets
! threadCheckInterval = self.maxServerThreads*2
! threadUpdateDivisor = 5 #grabstat interval
threadCheck=0
***************
*** 147,151 ****
if threadCheck > threadCheckInterval:
- if debug: print "\nBusy Threads: ", self.activeThreadCount()
threadCheck=0
self.manageThreadCount()
--- 147,150 ----
***************
*** 167,171 ****
"""
count = self.activeThreadCount()
! if len(self.threadUseCounter) > 10:
self.threadUseCounter.pop(0)
self.threadUseCounter.append(count)
--- 166,170 ----
"""
count = self.activeThreadCount()
! if len(self.threadUseCounter) > self.maxServerThreads:
self.threadUseCounter.pop(0)
self.threadUseCounter.append(count)
***************
*** 181,185 ****
--- 180,186 ----
avg=0
max=0
+ debug=0
+ if debug: print "ThreadUse Samples=%s" % str(self.threadUseCounter)
for i in self.threadUseCounter:
avg = avg + i
***************
*** 191,197 ****
if debug: print "ThreadCount: ", self.threadCount
! if len(self.threadUseCounter) < 10: return #we have no observations to use
! margin = self.threadCount / 4 #smoothing factor
if debug: print "margin=", margin
--- 192,198 ----
if debug: print "ThreadCount: ", self.threadCount
! if len(self.threadUseCounter) < self.maxServerThreads: return #not enough samples
! margin = self.threadCount / 2 #smoothing factor
if debug: print "margin=", margin
***************
*** 199,206 ****
# Running low: double thread count
n = min(self.threadCount, self.maxServerThreads-self.threadCount)
for i in range(n):
self.spawnThread()
elif avg < self.threadCount - margin and self.threadCount > self.minServerThreads:
! self.absorbThread()
def spawnThread(self):
--- 200,211 ----
# Running low: double thread count
n = min(self.threadCount, self.maxServerThreads-self.threadCount)
+ if debug: print "Adding %s threads" % n
for i in range(n):
self.spawnThread()
elif avg < self.threadCount - margin and self.threadCount > self.minServerThreads:
! n=min(self.threadCount - self.minServerThreads, self.threadCount - max)
! self.absorbThread(n)
! else: #cleanup any stale threads that we killed but haven't joined
! self.absorbThread(0)
def spawnThread(self):
***************
*** 213,229 ****
self.threadCount = self.threadCount+1
if debug: print "New Thread Spawned, threadCount=", self.threadCount
! self.threadUseCounter=[] #reset
! def absorbThread(self):
debug=0
! if debug: print "Absorbing Thread"
! self.requestQueue.put(None)
for i in self.threadPool:
if not i.isAlive():
rv=i.join() #Don't need a timeout, it isn't alive
self.threadPool.remove(i)
! self.threadCount = self.threadCount-1
! if debug: print "Thread Absorbed, threadCount=", self.threadCount
! self.threadUseCounter=[]
def threadloop(self):
--- 218,242 ----
self.threadCount = self.threadCount+1
if debug: print "New Thread Spawned, threadCount=", self.threadCount
! ## self.threadUseCounter=[] #reset
! def absorbThread(self,count=1):
! """ Absorb a thread.
! We do this by putting a None on the Queue. When a thread gets it,
! that tells it to exit. BUT, even though we put it on, the thread may not
! have retrieved it before we exit this function. So we need to decrement
! the thread count even if we didn't find a thread that isn't alive. We'll
! get it the next time through.
! """
debug=0
! if debug: print "Absorbing %s Threads" % count
! for i in range(count):
! self.requestQueue.put(None)
! self.threadCount = self.threadCount-1
for i in self.threadPool:
if not i.isAlive():
rv=i.join() #Don't need a timeout, it isn't alive
self.threadPool.remove(i)
! if debug: print "Thread Absorbed, Real Thread Count=", len(self.threadPool)
! ## self.threadUseCounter=[] #reset
def threadloop(self):
***************
*** 231,234 ****
--- 244,248 ----
The main request processing loop. Looks simple, doesn't it?
"""
+
self.initThread()
|