简体   繁体   English

在Linux apache上运行Drupal时发生内存泄漏,但是同一应用程序不会在Windows服务器上泄漏mem

[英]Memory leak when run Drupal on linux apache, but same application wont leak mem on windows server

Current my website is using drupal 6 , the apache http is using prefork mpm. 当前我的网站正在使用drupal 6,apache http正在使用prefork mpm。 When i test my web application, the memory wont release at all , it just adds up the memory usage. 当我测试我的Web应用程序时,内存根本不会释放,它只会增加内存使用量。 However on windows , it use mpm_winnt.c , it works great,without memory leak. 但是,在Windows上,它使用mpm_winnt.c可以正常工作,而不会发生内存泄漏。

Does it work if i change it to using worker.c on my linux server? 如果我将其更改为在Linux服务器上使用worker.c,是否可以正常工作?

Worker mode is not available with mod_php for Apache. 工作者模式不适用于Apache的mod_php。 because if PHP5 is known to be multithread-enabled it's really not the case for all PHP librairies and extensions (for example a locale call will enforce locale settings for all PHP threads in the apache proces). 因为如果已知PHP5是启用多线程的,则并非所有PHP库和扩展都并非如此(例如,语言环境调用将对apache进程中的所有PHP线程强制执行语言环境设置)。

So, do not use the worker model. 因此,请勿使用辅助模型。 Except maybe if you use PHP outside of Apache (with php-fpm). 除非您在Apache之外使用PHP(与php-fpm一起使用)。 And on Windows you may experience the same thread corruption problems (but officially, PHP distributions on Windows are considered thread-safe, so as long as you do not add a self-compiled PHP external component...). 在Windows上,您可能会遇到相同的线程损坏问题(但正式地,Windows上的PHP发行版被认为是线程安全的,只要您不添加自编译的PHP外部组件...)。

When you say : 当你说 :

the memory wont release at all 内存根本不会释放

I'm not sure you fully understand what's happening. 我不确定您是否完全了解正在发生的事情。 Apache will fork a big number of child processes. Apache将派生大量子进程。 If you use your Drupal6 application on these childrens and allow a big memory_limit for PHP you can be quite sure Drupal will use this memory limit, so If you said 128M your apache child process, running PHP will take this RAM (if Drupal ask for that, but Drupal with views is a good RAM eater, for sure). 如果您在这些子代上使用Drupal6应用程序,并为PHP设置了一个较大的memory_limit,则可以肯定的是Drupal将使用此内存限制,因此,如果您说您的Apache子进程为128M,则运行PHP将占用此RAM(如果Drupal要求这样做) ,但是具有视图的Drupal当然是不错的RAM使用者。 When the requests ends the Apache subprocess won't release the RAM, as it may need the same amount for the next query. 当请求结束时,Apache子进程将不会释放RAM,因为下一个查询可能需要相同的数量。 So if you allow 100 MaxClients to Apache and 128M of memory limit you may end up with 128M*100=12,5Go of RAM. 因此,如果您允许100个MaxClients使用Apache并具有128M的内存限制,则最终可能会有128M * 100 = 12,5Go的RAM。 Now on Linux the fact that available RAM is used is not a problem, you could think of it as a good thing. 现在在Linux上使用可用RAM的事实已经不是问题,您可以将其视为一件好事。 You have RAM available, why not using it? 您有可用的RAM,为什么不使用它呢? Your problem is maybe that you do not have this amount of RAM (12.5G here, only for Apache) 您的问题可能是您没有足够的RAM(此处为12.5G,仅适用于Apache)

You can enforce a die of an apache subprocess with the MaxRequestsPerChild , let's say with a value of 100, then after 100 requests handled by an apache child process it will be killed and re-created. 您可以使用MaxRequestsPerChild强制执行apache子进程的死,比如说值为100,然后在apache子进程处理了100个请求后,该请求将被杀死并重新创建。 But, if all your requests needs 128M of RAM you'll get the same problem soon. 但是,如果您的所有请求都需要128M RAM,那么您很快就会遇到相同的问题。

  • set low values for MaxClients (less than available RAM/average RAM of one Process), 为MaxClients设置较低的值(小于一个进程的可用RAM /平均RAM),
  • push the MySQL server on another server, big RAM eater as well 将MySQL服务器推到另一台服务器上,同时也占用大量RAM
  • try to find a low limit for memory_limit (this can be quite hard with Drupal, but check for all the Drupal profiling modules, and check all the visibility settings of your blocks you'll get nice hints) 尝试找到memory_limit的下限(对于Drupal来说可能很难,但是请检查所有Drupal分析模块,并检查块的所有可见性设置,您会得到很好的提示)
  • if your project is quite big buy several apache servers and build a solution with http load balancing. 如果您的项目很大,请购买几台apache服务器并使用http负载平衡构建解决方案。
  • use php in fastcgi mode (like php-fpm ), so that at least all non-php pages will be used with a worker apache server (but you'll get same problems of RAM usage inside your fastcgi php server) 在fastcgi模式下使用php(例如php-fpm ),以便至少所有非php页面将与辅助apache服务器一起使用(但在fastcgi php服务器内部会遇到相同的RAM使用问题)

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

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