NetTalk Central

NetTalk Web Server => Web Server - Share Knowledge => Topic started by: Bruce on August 23, 2011, 10:18:30 PM

Title: Monitor mem usage - and act upon it
Post by: Bruce on August 23, 2011, 10:18:30 PM
This thread comes up a fair bit, so I thought I'd make a link to it here;

Summary:
how to count the number of threads currently running, and reject the creation of more threads if some arbitrary limit has been reached.

http://www.nettalkcentral.com/index.php?option=com_smf&Itemid=36&topic=2021.0 (http://www.nettalkcentral.com/index.php?option=com_smf&Itemid=36&topic=2021.0)

Cheers
Bruce
Title: Re: Monitor mem usage - and act upon it
Post by: ccordes on September 22, 2011, 01:11:31 PM
Thanks, Bruce.

In practice, having the thread limit that way causes the system to hang as it continually bumps its head on that upper limit. It works out better to have a High limit and a lower release or reopen level.
We count the threads the same way but we have it like this in the StartNewThread embed. The Traces can be left out - I use them to see how often and how long the server is busy.

SELF._Trace('WebServer Mem: Threads:'&ThreadCnt&' /Max:'&MaxThreads)       
If (g:ThreadHighLimit > 0 AND Threadcnt >= g:ThreadHighLimit)
    g:NoService = TRUE
END
IF g:NoService AND ThreadCnt =< g:ThreadReopenLevel
    g:NoService = FALSE
END
IF g:NoService
    SELF._Trace('No Service Threads='&ThreadCnt&' /Max:'&g:ThreadHighLimit&' - Not processing this request')
    self.senderror(500,'Server Busy','Server Busy, try again shortly')
    Return
End

HTH
Chris