简体   繁体   English

关于内存泄漏的指南

[英]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. 无论如何,我有一个几乎完整的ajax网站,可以从另一台服务器中提取数据。 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. 我认为,一旦呈现页面,我就可以直接保存html代码,并在第二个请求上保存该html文件,如果该缓存文件存在并且与请求匹配,则可以为用户提供该特定的缓存文件。

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. 缓存文件的大小约为30Kb至100Kb(仅html代码),但是我几乎有1M页面,因此缓存的文件很多。 Total size at the moment is over 2.1GB disk space. 目前总大小超过2.1GB磁盘空间。

I'm using file_get_contents to get the contents of the cache files and render them to the user. 我正在使用file_get_contents来获取缓存文件的内容并将其呈现给用户。

Btw, I'm using symfony2 framework too, just in case the info is useful and also with doctrine. 顺便说一句,我也使用symfony2框架,以防万一,信息有用,也有原则。

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. 开发人员中的Symfony2仅表示根据页面和查询使用大约20MB到40MB的RAM。 Around 20MB of RAM when serving cached file. 提供缓存的文件时大约有20MB的RAM。

Using cPanel that has Cloudlinux and physical ram is limited to 2GB. 使用具有Cloudlinux和物理内存的cPanel限制为2GB。 I'm currently using 1GB of ram and may increase ... 我目前使用的是1GB的内存,并且可能会增加...

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. 如果这是我几乎可以确定的磁盘高速缓存,Linux最终将清除高速缓存或在进一步需要ram的情况下删除高速缓存。 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. 我在问是否有一种方法可以检查我的脚本是否存在内存泄漏,什么继续使用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. 我知道在读取文件时, file_get_contents正在使用mmap ,这样很可能导致RAM用于磁盘缓存。

I'm using in most queries the findBy() or findOneBy() functions for querying the database. 我在大多数查询中都使用findBy()findOneBy()函数来查询数据库。 I think I have only one custom query with QueryBuilder . 我认为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 好吧,当我写完这个问题时,我发现它的实际磁盘缓存ram使用基于

~# 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 以及在此找到的信息: 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. 可以安全地假设正在缓存957.56MB,但未使用它,并且很可能在需要时将其回收。 Hopping it will help someone else that had this confusion :) 跳开它会帮助其他有这种困惑的人:)

Cheers. 干杯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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