简体   繁体   中英

Guidance on about memory leak

I have the below scenario that it looks to be causing, what I think, memory leak, but haven't confirmed this if is disk cache instead ...

Anyway, I have one almost full ajax site that pulls out data from another server. Thus the data needs to be cached somehow. I figured that once the page is rendered I could save the html code directly and on a second request, if the cache file exists and matches the request, to provide the user that specific cache file.

The cache file is around 30Kb to 100Kb in size (html code only), however I have almost a 1M pages, thus there are a lot of cached files. Total size at the moment is over 2.1GB disk space.

I'm using file_get_contents to get the contents of the cache files and render them to the user.

Btw, I'm using symfony2 framework too, just in case the info is useful and also with doctrine.

At this point, I have used

$em->getConnection()->getConfiguration()->setSQLLogger(null);
$em->clear();

for avoiding doctrine's memory leak just in case. Symfony2 in dev only says its using around 20MB to 40MB of RAM depending on the page and queries. Around 20MB of RAM when serving cached file.

Using cPanel that has Cloudlinux and physical ram is limited to 2GB. I'm currently using 1GB of ram and may increase ...

If this is disk cache, which I'm almost sure, linux will eventually clear the cache or will drop the cache if ram is further needed. Well that's the safe case.

I'm asking if there's a way to check if there are memory leaks from my script, what keeps on using ram. I know that file_get_contents is using mmap when reading the files so that would cause the RAM to be used for disk cache most likely.

I'm using in most queries the findBy() or findOneBy() functions for querying the database. I think I have only one custom query with QueryBuilder .

The page is really fast, I don't see a problem with it loading, but only concerned about its usage.

I know that you guys will probably ask to provide code, I would but can't really know what to include / which part. I've mentioned almost everything that seemed useful.

Thanks again, and terribly sorry for the long question.

Well by the time I've finished writing this question I've found that its actually disk cache ram usage based on

~# cat meminfo 
MemTotal:        2097152 kB
MemFree:          989916 kB
Cached:          1107236 kB
Buffers:               0 kB
Active:           149680 kB
Inactive:         957556 kB
Active(anon):          0 kB
Inactive(anon):        0 kB
Active(file):     149680 kB
Inactive(file):   957556 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:      24575976 kB
SwapFree:       24575976 kB
Dirty:               492 kB
Writeback:             0 kB
AnonPages:             0 kB
Shmem:                 0 kB
Slab:                  0 kB
SReclaimable:          0 kB
SUnreclaim:            0 kB
MemCommitted:    2097152 kB
MemAvailable:   32891128 kB
MemPortion:       509936 kB
Shadow:            13476 kB
Shadow(anon):          0 kB
Shadow(file):      13476 kB
IdleClean:             0 kB
IdleDirtyFile:         0 kB
IdleDirtySwap:         0 kB

and on information found here: https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-meminfo.html

mainly:

Inactive — The total amount of buffer or page cache memory, in kilobytes, that are free and available. This is memory that has not been recently used and can be reclaimed for other purposes.

while using:

Inactive:         957556 kB

Safe to assume that 957.56MB is being cached but not used and most likely will be reclaimed back when needed. Hopping it will help someone else that had this confusion :)

Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM