Question

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.

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.

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.

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.

Any ideas how to solve this?

Was it helpful?

Solution

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

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

$ 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:

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

    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.

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top