Update of /cvsroot/webware/Webware/WebKit
In directory usw-pr-cvs1:/tmp/cvs-serv14266
Modified Files:
ThreadedAppServer.py
Log Message:
Some tweaking of the threadcount management algorithm. Threads are so cheap to create and destroy, so be more aggressive in creating them. It makes a very large performance difference to have more threads.
Index: ThreadedAppServer.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/ThreadedAppServer.py,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** ThreadedAppServer.py 2002/01/26 16:42:51 1.53
--- ThreadedAppServer.py 2002/01/27 03:37:03 1.54
***************
*** 120,125 ****
inputsockets.append(monitor.insock)
! threadCheckInterval = 100 #does this need to be configurable???
! threadUpdateDivisor = 10 #grabstat interval
threadCheck=0
--- 120,125 ----
inputsockets.append(monitor.insock)
! threadCheckInterval = self.maxServerThreads*2
! threadUpdateDivisor = 5 #grabstat interval
threadCheck=0
***************
*** 180,184 ****
"""
count = self.activeThreadCount()
! if len(self.threadUseCounter) > 10:
self.threadUseCounter.pop(0)
self.threadUseCounter.append(count)
--- 180,184 ----
"""
count = self.activeThreadCount()
! if len(self.threadUseCounter) > self.maxServerThreads:
self.threadUseCounter.pop(0)
self.threadUseCounter.append(count)
***************
*** 194,198 ****
--- 194,200 ----
avg=0
max=0
+ debug=0
+ if debug: print "ThreadUse Samples=%s" % str(self.threadUseCounter)
for i in self.threadUseCounter:
avg = avg + i
***************
*** 204,210 ****
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
--- 206,212 ----
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
***************
*** 212,221 ****
# 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):
if debug: print "Spawning new thread"
t = Thread(target=self.threadloop)
--- 214,228 ----
# 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):
+ debug=0
if debug: print "Spawning new thread"
t = Thread(target=self.threadloop)
***************
*** 225,240 ****
self.threadCount = self.threadCount+1
if debug: print "New Thread Spawned, threadCount=", self.threadCount
! self.threadUseCounter=[] #reset
! def absorbThread(self):
! 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):
--- 232,257 ----
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):
|