我如何限制apache2的资源?

时间:2022-06-02 00:18:23

I have a very slow home server (raspberry pi) with 700 MHz CPU. When I develop some sites, it sometimes happens that I input a large (5 MB) .jpg file into an image resizer (imagecreatefromjpeg(), imagecreatetruecolor(), imagecopy()) which causes the server to hang.

我有一个非常慢的家用服务器(raspberry pi),700 MHz CPU。当我开发一些网站时,有时我会将一个大的(5 MB).jpg文件输入图像缩放器(imagecreatefromjpeg(),imagecreatetruecolor(),imagecopy()),这会导致服务器挂起。

I'd say it's processing the file, but even when I wait for minutes, it never ends.

我会说它正在处理文件,但即使我等了几分钟,它也永远不会结束。

The problem is that I cannot even access the shell to stop/restart apache2; the only solution is to power off the server completely.

问题是我甚至无法访问shell来停止/重启apache2;唯一的解决方案是完全关闭服务器电源。

I was wondering whether there's any way to limit HW resources for apache2; for example if I could limit only 80% CPU usage for it, maybe I could still access the shell and stop it.

我想知道是否有办法限制apache2的硬件资源;例如,如果我只能限制80%的CPU使用率,也许我仍然可以访问shell并停止它。

I tried setting the timeout and max_execution_time directives, but they don't seem to stop apache2 from working infinitely and freezing the server.

我尝试设置timeout和max_execution_time指令,但它们似乎并没有阻止apache2无限制地工作并冻结服务器。

Any ideas how to solve this?

任何想法如何解决这个问题?

2 个解决方案

#1


0  

I don't think you can limit the cpu usage of apache from its own settings.

我不认为你可以从自己的设置限制apache的cpu使用。

You can try using a separate app like cpulimit (see: how-to):

您可以尝试使用单独的应用程序,如cpulimit(请参阅:操作方法):

$ sudo apt-get install cpulimit
$ man cpulimit

You can also try these to optimize the overall performance of your server.

您还可以尝试这些来优化服务器的整体性能。

  • Edit your /etc/apache2/apache2.conf and use these values:

    编辑/etc/apache2/apache2.conf并使用以下值:

    <IfModule mpm_prefork_module>
        StartServers          2
        MinSpareServers       2
        MaxSpareServers       3
        MaxClients           50
        MaxRequestsPerChild   0
    </IfModule>
    
  • Expand your swap in /etc/dphys-swapfile set:

    扩展/ etc / dphys-swapfile集中的交换:

    CONF_SWAPSIZE=512
    

    Then run:

    $ sudo dphys-swapfile setup
    $ sudo dphys-swapfile swapon
    
  • Overclock your raspberry (it's safer than it sounds) here:

    超频覆盆子(它听起来比听起来更安全):

    $ sudo raspi-config
    

    I use it at 950MHz. There is a higher option (1000MHz), but some people on the forum complained about SD corruption with that one.

    我在950MHz使用它。有更高的选择(1000MHz),但论坛上的一些人抱怨SD腐败。

  • You can also set the graphic memory to 16 in raspi-config memory_split if you do not use the graphical interface.

    如果不使用图形界面,还可以在raspi-config memory_split中将图形内存设置为16。

#2


-1  

You can install apache-mod_ratelimit. Also, see Control Apache with httpd.conf.

你可以安装apache-mod_ratelimit。另请参阅使用httpd.conf控制Apache。

#1


0  

I don't think you can limit the cpu usage of apache from its own settings.

我不认为你可以从自己的设置限制apache的cpu使用。

You can try using a separate app like cpulimit (see: how-to):

您可以尝试使用单独的应用程序,如cpulimit(请参阅:操作方法):

$ sudo apt-get install cpulimit
$ man cpulimit

You can also try these to optimize the overall performance of your server.

您还可以尝试这些来优化服务器的整体性能。

  • Edit your /etc/apache2/apache2.conf and use these values:

    编辑/etc/apache2/apache2.conf并使用以下值:

    <IfModule mpm_prefork_module>
        StartServers          2
        MinSpareServers       2
        MaxSpareServers       3
        MaxClients           50
        MaxRequestsPerChild   0
    </IfModule>
    
  • Expand your swap in /etc/dphys-swapfile set:

    扩展/ etc / dphys-swapfile集中的交换:

    CONF_SWAPSIZE=512
    

    Then run:

    $ sudo dphys-swapfile setup
    $ sudo dphys-swapfile swapon
    
  • Overclock your raspberry (it's safer than it sounds) here:

    超频覆盆子(它听起来比听起来更安全):

    $ sudo raspi-config
    

    I use it at 950MHz. There is a higher option (1000MHz), but some people on the forum complained about SD corruption with that one.

    我在950MHz使用它。有更高的选择(1000MHz),但论坛上的一些人抱怨SD腐败。

  • You can also set the graphic memory to 16 in raspi-config memory_split if you do not use the graphical interface.

    如果不使用图形界面,还可以在raspi-config memory_split中将图形内存设置为16。

#2


-1  

You can install apache-mod_ratelimit. Also, see Control Apache with httpd.conf.

你可以安装apache-mod_ratelimit。另请参阅使用httpd.conf控制Apache。