0

I'm running apache with a worker MPM and php with fastcgi.

the following are my mpm limits:

StartServers         5
MinSpareThreads      5
MaxSpareThreads      10
ThreadLimit          64
ThreadsPerChild      10
MaxClients           10
MaxRequestsPerChild  2000

I've also setup my php-cgi with the following:

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=500

I'm noticing that my average php-cgi process is using around 200+mb of RAM, even as soon as they are started. However, my php memory_limit is only 128M.

How is this possible, and what can I do to lower the php-cgi memory consumption?

quanta
  • 50,327
  • 19
  • 152
  • 213
Josh Nankin
  • 722
  • 11
  • 27
  • You're confusing *memory* with *RAM*. They're using 200MB of memory, not RAM. Memory is a nearly free resource, since the system can create tons of it at nearly zero cost. – David Schwartz May 23 '12 at 06:37

2 Answers2

1

There are instances where PHP can exceed the configured memory limit (memory malloc'ed directly in extensions) however I suspect this may not be the case.

I'm noticing that my average php-cgi process is using around 200+mb

How did you measure this? Most of the TXT segments will be shared - so actual memory usage is a lot less than what you'd see in the /proc filesystem or in ps/top. While you could try parsing the output of lsof, in practice I find it much more sensible to step back a bit and look at the number of requests in progress (e.g. from the number of connected sockets) and comparing this with the free memory reported (less buffers/cache).

symcbean
  • 19,931
  • 1
  • 29
  • 49
1

Memory limit in PHP is the internal memory limit - i.e. that's the amount that the engine would allow the user script to allocate through it's private allocator. But besides that there's memory that is allocated by the engine for its internal needs, which is not always counted towards the limit (some of it is, but not all of it), the memory being allocated by libraries, etc. So expect real memory usage to be slightly bigger than memory_limit setting.

Also, as mentioned above, some of the figures reported by tools are memory allocated for the code, stack, OS I/O buffers, shared memory between libraries, etc. so look closer into which figure you are checking.

StasM
  • 153
  • 1
  • 1
  • 7