简体   繁体   English

显然随机内存耗尽错误

[英]Apparently random memory exhausted error

I'm having a weird issue that I'm having trouble to debug. 我遇到一个奇怪的问题,我无法调试。 I have an application coded over Symfony2 distributed in three webservers behind a load balancer. 我有一个通过Symfony2编码的应用程序,该应用程序分布在负载均衡器后面的三个Web服务器中。 There's an instance of Varnish on each one of the webservers. 每个Web服务器上都有一个Varnish实例。

At random times some of the webservers -one or two, rarely all of them- respond with a 503 error at the homepage for about 10 minutes or so and then everything goes back to normal. 随机出现一些Web服务器(一两个,很少是全部),在主页上显示503错误约10分钟左右,然后一切恢复正常。

The error is caused by a PHP Allowed memory size exhausted fatal error. 该错误是由PHP允许的内存大小用尽致命错误引起的。 But what I fail to understand is why the same app, with the same code, connecting to the same DB, etc. fails from one moment to another and then goes back to normal once again. 但是我无法理解的是为什么同一个应用程序,相同的代码,连接到相同的数据库等等,一次又一次失败,然后又恢复正常。 And even the same app on different servers with the same hardware and software behave differently simultaneously. 甚至在具有相同硬件和软件的不同服务器上的同一应用程序也同时表现不同。

My first guess was that the Varnish cache expired on the failing servers while the ones behaving normally still had a fresh copy cached with no errors. 我的第一个猜测是,有故障的服务器上的Varnish缓存已过期,而行为正常的服务器通常仍没有错误地缓存了一个新副本。 But if I manually flush the cache on all of the servers, the servers which had no errors respond with a 200 OK and the cache is regenerated successfully while the others keep failing. 但是,如果我手动刷新所有服务器上的缓存,则没有错误的服务器将以200 OK响应,并且缓存将成功重新生成,而其他服务器则继续出现故障。

And just to get even more weird... I realized that the same URL failing with some random query arguments responds correctly with some others. 只是变得更加怪异...我意识到,相同的URL带有一些随机查询参数会失败,而其他参数会正确响应。 I mean arguments that do nothing in the code. 我的意思是参数在代码中不起作用。

I'm running out of ideas on how debug this problem. 我没有关于如何调试此问题的想法。 Any clue would be truly appreciated. 任何线索将不胜感激。 Thanks! 谢谢!

UPDATE: I'm also using Memcached to cache Doctrine queries and results. 更新:我还使用Memcached来缓存Doctrine查询和结果。 The Memory exhausted error is triggered when Doctrine attempts to store something in Memcached. 当Doctrine尝试将某些内容存储在Memcached中时,将触发“内存耗尽”错误。 The first guess would be to think that is trying to store a very large result but it still doesn't explain why it fails on one webserver while there's no problem on the others and all of them are processing the same queries from the same DB. 最初的猜测是认为它试图存储很大的结果,但是仍然不能解释为什么它在一个Web服务器上失败,而在其他Web服务器上却没有问题,并且所有人都在处理来自同一数据库的相同查询。

To me it sounds like you have some badly behaving PHP scripts and/or too high max allowed memory for PHP. 对我来说,听起来您的PHP脚本行为不佳和/或PHP的最大允许内存过高。 Memory_limit * max processes with some 15mb per process to spare should never be higher than memory available. Memory_limit *每个进程最多可保留15mb的最大进程不应超过可用内存。 If you need more memory for some requests you should set up an extra pool with fewer max procs. 如果对于某些请求需要更多的内存,则应设置一个具有更少最大进程数的额外池。

Also take into account that varnish can take up a rather big chunk of memory. 还应考虑到清漆会占用相当大的内存。 Limit the cache size AND max concurrent connections. 限制缓存大小和最大并发连接数。 Each connection uses memory but the ammount is highly dependant on your VCL and size of the request (including headers). 每个连接都使用内存,但数量在很大程度上取决于您的VCL和请求的大小(包括标头)。

It might get easier to handle and for sure gives better cache efficiency, if you place varnish at the load balancer layer. 如果将清漆放在负载平衡器层,它可能会变得更易于处理,并且可以确保更好的缓存效率。

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

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