NetTalk Central

Author Topic: Monitor mem usage - and act upon it  (Read 7348 times)

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Monitor mem usage - and act upon it
« 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

Cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Monitor mem usage - and act upon it
« Reply #1 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
Real programmers use copy con newapp.exe