NetTalk Central

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

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Monitor mem usage - and act upon it
« on: April 18, 2011, 02:12:52 AM »
Hi Bruce,
You mentioned in the ng that if the question was asked here you'd explain the how-to.

Well, I'm asking  ;)

Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Monitor mem usage - and act upon it
« Reply #1 on: April 18, 2011, 03:18:09 AM »
updated: August 31 2011 to include the call to SendError. Requires 5.34 or later.

a) create a global mem variable, a LONG, unthreaded, called say ThreadsCount

b) In WebHandler, before the line;
p_web.ProcessRequest(p_ReqString)

add
p_web._wait()
ThreadsCount += 1
p_web._release()

and after the call to
p_web.ProcessRequest(p_ReqString)

put
p_web._wait()
ThreadsCount -= 1
p_web._release()

c) In WebServer procedure, StartNewThread method, after loc:RequestData :=: p_RequestData

If ThreadsCount >= x
  self.SendError(500,'Server Busy','Server Busy, try again shortly')
  Return
End

The value you use for x will depend on the memory usage of each thread. And the only real way to know how high it can go is to monitor the value under load, and see at what point the server dies.
As a debugging tool you could write out the value to DebugView, or perhaps write it away to an Ini file or something here.

Cheers
Bruce
« Last Edit: August 31, 2011, 04:14:21 AM by Bruce »

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: Monitor mem usage - and act upon it
« Reply #2 on: April 19, 2011, 04:56:35 AM »
Nice!

Peter