简体   繁体   English

Python和MySQL神秘的内存泄漏

[英]Python and MySQL mysterious memory leak

I'm running a python app that's querying (selecting) mysql db, reading ~1k rows at a time, performing calculations with them and repeating that for hours. 我正在运行一个查询(选择)mysql db的python应用程序,一次读取约1k行,对它们执行计算并重复数小时。 Table which is read have ~20m readings and it's powered by MyISAM engine. 读取的表具有约2000万个读数,并由MyISAM引擎提供支持。 MySQLdb connector is used to access MySQL from python. MySQLdb连接器用于从python访问MySQL。

Problem is that after few hours all server's memory is used, leaving server with only 16mb memory available. 问题在于,几个小时后,所有服务器的内存都被使用,服务器仅剩下16mb的可用内存。

First idea was memory leak in python app, but memory_profiler and dozer/dowser both showed that all variables are released properly. 第一个想法是python应用程序中的内存泄漏,但是memory_profiler和dozer / dowser都显示所有变量均已正确释放。

Next try to catch the leaker was taking process memory usage snapshot (ps vax | sort -k8n) before and after memory exhaustion. 下一步,尝试捕获泄漏者是在内存耗尽之前和之后拍摄进程内存使用情况快照(ps vax | sort -k8n)。

Snapshot (sorted by mem) when server had 280mb free (info from top): http://pastebin.com/0F3Wht0s 2 hours later... Snapshot hen server had only 18mb free (info from top): http://pastebin.com/9MJkLX2g 服务器有280mb可用时的快照(按mem排序)(顶部信息):2小时后http://pastebin.com/0F3Wht0s ...服务器只有快照的母鸡只有18mb(顶部信息): http:// pastebin .com / 9MJkLX2g

My surprise is that memory consumption of mysqld and statcalculator processes seams almost identical through time. 我的惊讶是,随着时间的推移,mysqld和statcalculator进程的内存消耗几乎完全相同。

I'm obviously missing something related to memory allocation in linux. 我显然缺少与Linux中的内存分配相关的东西。 How to see which process allocated that memory? 如何查看哪个进程分配了该内存?

Server is running Ubuntu Server 10.04, and has 1gb ram in total. 服务器正在运行Ubuntu Server 10.04,总内存为1GB。 MySQL and MySQLdb are from ubuntu repo. MySQL和MySQLdb来自ubuntu存储库。 If any additional info is needed, I'll add here. 如果需要任何其他信息,我将在此处添加。

TLDR : Python app is constantly reading from mysql with selects. TLDR :Python应用程序通过selects不断从mysql中读取。 After few hours of this, memory is all gone, but top shows no increase in memory allocation for neither mysqld or python process. 几个小时后,内存全部消失了,但是top显示mysqld或python进程的内存分配均未增加。

As @ebyrob suggested, LinuxAteMyRam(.com). 如@ebyrob所建议,LinuxAteMyRam(.com)。

As $ free -m confirmed, "missing" memory had been used for disk caching and is actually available for apps. 正如$ free -m确认的那样,“丢失”的内存已用于磁盘缓存,实际上可用于应用程序。

Thanks, @ebyrob. 谢谢,@ ebyrob。

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

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