php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29460 memory usage (leak?) on session
Submitted: 2004-07-30 18:49 UTC Modified: 2005-02-11 01:00 UTC
Votes:17
Avg. Score:4.8 ± 0.5
Reproduced:12 of 12 (100.0%)
Same Version:8 (66.7%)
Same OS:8 (66.7%)
From: kylewong at southa dot com Assigned:
Status: No Feedback Package: Session related
PHP Version: 4.3.8 OS: linux kernel 2.6.1
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-07-30 18:49 UTC] kylewong at southa dot com
Description:
------------
apache 2.0.48, php 4.3.7, 4.3.8
session handler = file
apache keepalive timeout = 1
apache maxclient = 192
apache mpm = prefork
session timeout = 1500
session file storage: tmpfs

problem: php doesn't free memory used by session.

My website is a high traffic site, process around 1800k php pages per day. The server always has around 5000-10000 sessions (25 mminutes) online. Each session file take around 200 bytes to several Kb, total session data take around 20-30MB.

I found that my average httpd process size grow slowly from average 8MB to 1x-2xMB (take around 1-2 hours), my server always has around 200 httpd running (keepalive timeout = 1), system resouce decrease while httpd take more and more memory. 

At fresh start without any session data stored, my system has around 400MB buffer and 800MB cache, httpd size average round 8MB. 

When httpd processes grow to around 15MB, the system has only around 300MB buffer and 300MB cache, of course, server performance drop a lot since my site is very disk intensive (load lots of informations from thousands of serialized objects)

It seems that the httpd process doesn't release all used memory after finish processing a page. 

I found that if I delete all the session data files while apache running, httpd processes start free up memory and system buffer and cache start growing to normal (400MB, 800MB), but after some time, httpd start grow again and system resources used for buffer and cache start decrease.

Also, I found that, when the average httpd process size are at says 20MB, even if I stop and restart apache, all httpd process size will startup at 20MB, and keep growing. That's mean, I can't free up memory used by httpd processes by kill and restart apache, I need to delete the session data files to free up resouces.

Sorry about my bad english, wish that someone can help me in my situation, thanks a lot.







Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-31 06:53 UTC] kylewong at southa dot com
more informations:
apache fresh start without any session data:
http://www2.southa.com/~kylewong/top-1.gif

about 30 minutes later, httpd size grow around 1.5M
http://www2.southa.com/~kylewong/top-2.gif

1 hour later from beginning, httpd size reach 10M, total session data size around 16M, average session file size around 2kb, around 4k sessions online.
http://www2.southa.com/~kylewong/top-3.gif

stop and restart apache without delete session data, most httpd size reach 10M immediately after apache start.
http://www2.southa.com/~kylewong/top-4.gif

stop, delete all session data, and restart apache. 
http://www2.southa.com/~kylewong/top-5.gif
 [2004-07-31 08:14 UTC] kylewong at southa dot com
httpd grow back to 10-12MB
http://www2.southa.com/~kylewong/top-6.gif

2 minutes later after delete all session data while apache running:
http://www2.southa.com/~kylewong/top-7.gif

session.php:
class GallerySession {}

if (session_id()) {
        $useStdClass = 1;
}
/* Start a new session, or resume our current one */
@session_start();

$sessionVar = "fsess";
session_register($sessionVar);

if (isset($$sessionVar)) {
        $gallery->session =& $$sessionVar;
} else {
        /* Register the session variable */
        session_register($sessionVar);

        /* Create a new session container */
        if ($useStdClass) {
                $$sessionVar = new stdClass();
        } else {
                $$sessionVar = new GallerySession();
        }
        $gallery->session =& $$sessionVar;
}
 [2004-07-31 08:34 UTC] kylewong at southa dot com
30 minutes after delete all session data files while apache running. 5500 sessions online, 22M disk space taken by session files. average session file size around 1.5kb.

http://www2.southa.com/~kylewong/top-8.gif
 [2005-02-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-09-07 18:12 UTC] cq92 at hotmail dot com
Probably the easiest way to fix this problem is to create a batch file to empty the sessions folder (*.*) regularily and run it using task scheduler (windows servers). That way it will automatically dump cache folders or session folders at regular intervals, say 4-8 hours daily.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 13:01:30 2024 UTC