我有一个大的php cronjob每20分钟运行一次。 每次执行后,虚拟服务器使用的RAM内存会增加,脚本终止后不能正常释放!
但为什么? 内存不被caching
total used free shared buffers cached Mem: 2048 1948 99 0 0 88 -/+ buffers/cache: 1859 188 Swap: 0 0 0
该脚本使一些curl / multi_curl和更新Mysql数据库。
有一种方法可以查看所有variables和内存使用情况的脚本吗? 或简单的那些没有发布在最后…
程序退出时应该释放内存(不pipe程序是否释放)。 例如。
[kbrandt@ny-kbrandt01: ~] cat eat_mem.c #include <stdlib.h> #include <string.h> #include <unistd.h> int main() { #1 GByte const int m = 1024*1024*1024; #Allocate a gig void *p = (int*)malloc(m); #Write a Gigs worth of zeros to that gig memset(p,0,m); sleep(10); #In theory I should free(p) here (heh... heh... I said "free p", get it?) return 0; } [kbrandt@ny-kbrandt01: ~] gcc eat_mem.c; ./a.out &; sleep 1; free -m;sleep 10; free -m [1] 10666 total used free shared buffers cached Mem: 7872 1848 6023 0 143 431 -/+ buffers/cache: 1273 6599 Swap: 30467 0 30467 [1] + done ./a.out total used free shared buffers cached Mem: 7872 823 7049 0 143 431 -/+ buffers/cache: 247 7624 Swap: 30467 0 30467
所以假设脚本运行cron作业退出,这不是问题。 所以你需要看看哪个程序在内存中增长。 你可以用top来看这个(你可以通过按住F (大写)按住常驻内存大小进行sorting,然后在RES顶部selectq ),然后看看有什么程序在增长。
我的猜测是,这将是MySQL,因为无论你的脚本做什么,它在SQL和SQL的东西最终使用更多的内存。 这可能实际上不是一个问题,如果我不得不猜测,MySQL将采取它可以得到的内存和明智地使用它大部分时间。