From: kameshj at fastmail dot fm Operating system: Any PHP version: Irrelevant PHP Bug Type: Apache2 related Bug description: thread_resources for a thread is not getting freed as when apache kills thread
Description: ------------ Run apache2 in a worker thread model with the following settings StartThreads 3 MaxSpareThreads 4 MaxThreads 10 Loadtests on a very simple php scripts like the one that calls phpinfo() at regular intervals of 5 minutes causes a memory leak(Not really a leak but huge unused memory that gets freed at tsrm_shutdown) This causes the memory consumed by the apache2 procsss to shoot up. ---Investigation Apache2 to handle the concurrent requests increases the number of child threads to max of MaxThreads when no more request to server it kills the threads till the number of threads comes to MaxSpareThreads. In the case of setting given above after the load test of 10 simultaneous requests, Apache kills 6 threads (As MaxThreads-MaxSpareThreads = 10-4 = 6). The thread_resources momory associated with these 6 threads still not freed as soon as the corresponding thread is killed. These kind of spurt loads at regular intervals causes lots of such thread_resources memory to get accumulated not being used for any real purpose. Only when the sapi module comes down it calls tsrm_shutdown then these thread_resources are getting freed. Attaching the patch to fix the issue is available at http://puggy.symonds.net/~kameshj/TSRM.c.patch This patch has a few clean up to existing ts_free_thread. This patch registers ts_free_thread as thread cleanup routine. Reproduce code: --------------- Run apache2 in a worker thread model with the following settings StartThreads 3 MaxSpareThreads 4 MaxThreads 10 write a simple test.php <?php phpinfo(); ?> Run a load test with ab ab -n 40 -c 10 Wait for 5 minutes ab -n 40 -c 10 Wait for 5 minutes ab -n 40 -c 10 Wait for 5 minutes ab -n 40 -c 10 Expected result: ---------------- In the case of setting given above after the load test of 10 simultaneous requests, Apache kills 6 threads (As MaxThreads-MaxSpareThreads = 10-4 = 6). The thread_resources momory associated with these 6 threads still not freed as soon as the corresponding thread is killed. These kind of spurt loads at regular intervals causes lots of such thread_resources memory to get accumulated not being used for any real purpose. Only when the sapi module comes down it calls tsrm_shutdown then these thread_resources are getting freed. Actual result: -------------- thread_resources of a thread that gets killed should get freed as soon as it dies rather than waiting till the tsrm_shutdown -- Edit bug report at http://bugs.php.net/?id=32220&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32220&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32220&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32220&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32220&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32220&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32220&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32220&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32220&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32220&r=support Expected behavior: http://bugs.php.net/fix.php?id=32220&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32220&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32220&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32220&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32220&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32220&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32220&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32220&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32220&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32220&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32220&r=mysqlcfg