Difference between revisions of "Apache: Mengatasi Overload"

From OnnoWiki
Jump to navigation Jump to search
Line 1: Line 1:
 
Sumber: http://goodmanemail.com/apache-setup.html
 
Sumber: http://goodmanemail.com/apache-setup.html
  
Setting Apache web server up on linux to handle overload/'digg effect' more gracefully
 
  
 +
==Masalah==
  
The problem:
+
Konfigurasi defauly apache mengijinkan banyak sekali process jika banyak traffic. Memory mungkin aman-aman saja. Yang akan menjadi masalah adalah cputime, mungkin setiap request akan memperoleh 0.3-5% cputime saja. Akibatnya, proses menjadi terlalu lama sehingga menyebabkan timeout, refresh dan bahkan menambah banyak beban.
  
All default apache installations I have seen allow it to create far too many processes so when lots of traffic comes along apache makes about 200 processes, memory is fine but each request only gets about 0.3-5% of the available cputime. This means it takes too long to process the request causing timeouts, refreshes and even more load. This can continue untill the content is taken down with the user feeling that done have enough hardware to handle the traffic, or the machine eats through all the swap trying to handle the load and panics.
+
==Solusi==
  
 +
Solusinya adalah membatasi apache threads menjadi sangat sedikit (misalnya 16 atau kurang). Artinya, setiap request menjadi memperoleh lebih banyak cpu time.
  
The solution:
+
==Implementasi==
  
I have sucesfully combated this issue on my servers by setting up the preform MPM limits more effectively. In my experience this causes very few (no more than 16 in my case) apache threads to be created meaning each request has a large share of the CPU time - and is dealt with much more quickly - before the requesting browser gives up! Requests that come along while the server is busy are queued up and dealt with as soon as more resources become available, this normally is before the requesting browser has given up. In extreme cases (in my case a lot of traffic hitting an unoptimised wordpress weblog) some requests are dropped however the bulk of the requests were serviced within 4 seconds and only about 1% of requests failed to go through.
+
Edit file konfigurasi apache, kemungkinan di
Implementation:
 
  
I am not responsible for anything that may occur from following these instructions.
+
/etc/apache2/apache2.conf  -- Ubuntu
 +
/etc/httpd/conf/httpd.conf -- CentOS
  
Locate your apache config file, in my case this was /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf on this centos box. Then find the section related to the preform MPM.
+
Turunkan semua nilai sebanyak mungkin.
 
+
Naikan nilai MaxRequestsPerChild. Contoh sebagai berikut,
Reduce all the values considerably and increase the MaxRequestsPerChild. The numbers that work for you will depend on your setup, I suggest you have a play around to see what works best for you. I am pasting my own section below, these settings work nicely for me on a dual pentium 1.1ghz machine with 1.5 gb of ram (the machine this article is hosted on)
 
  
 
  <IfModule prefork.c>
 
  <IfModule prefork.c>
Line 30: Line 30:
  
  
Gotchas and finishing up:
+
Contoh lain dengan mengecilkan semua parameter seperti berikut
 +
 
 +
<IfModule mpm_prefork_module>
 +
    StartServers          5
 +
    MinSpareServers      5
 +
    MaxSpareServers      10
 +
    MaxClients          256
 +
    MaxRequestsPerChild  0
 +
</IfModule>
 +
 
 +
<IfModule mpm_worker_module>
 +
    StartServers          2
 +
    MinSpareThreads      20
 +
    MaxSpareThreads      60
 +
    ThreadLimit          16
 +
    ThreadsPerChild      5
 +
    MaxClients          256
 +
    MaxRequestsPerChild  0
 +
</IfModule>
 +
 
 +
<IfModule mpm_event_module>
 +
    StartServers          2
 +
    MaxClients          256
 +
    MinSpareThreads      20
 +
    MaxSpareThreads      60
 +
    ThreadLimit          16
 +
    ThreadsPerChild      5
 +
    MaxRequestsPerChild  0
 +
</IfModule>
  
It'd be ironic if this got on the front page and my server went down, but be mindfull that this site is hosted on an adsl connection in the UK, I expect my router is likely to die before this server tho! Some workloads are too high for this technique to be sensible, in those cases I suggest using varnish http accelerator or squid configured as a reverse proxy.
 
  
If you have found this article interesting or usefull please remember to digg it!
+
==Saran Lain==
  
 +
Beberapa kondisi overload mungkin juga tidak mungkin ditangani menggunakan teknik di atas. Untuk itu mungkin ada baiknya menggunakan http accelerator atau squid yang dikonfigurasi sebagai reverse proxy.
  
  

Revision as of 05:16, 20 April 2011

Sumber: http://goodmanemail.com/apache-setup.html


Masalah

Konfigurasi defauly apache mengijinkan banyak sekali process jika banyak traffic. Memory mungkin aman-aman saja. Yang akan menjadi masalah adalah cputime, mungkin setiap request akan memperoleh 0.3-5% cputime saja. Akibatnya, proses menjadi terlalu lama sehingga menyebabkan timeout, refresh dan bahkan menambah banyak beban.

Solusi

Solusinya adalah membatasi apache threads menjadi sangat sedikit (misalnya 16 atau kurang). Artinya, setiap request menjadi memperoleh lebih banyak cpu time.

Implementasi

Edit file konfigurasi apache, kemungkinan di

/etc/apache2/apache2.conf  -- Ubuntu
/etc/httpd/conf/httpd.conf -- CentOS

Turunkan semua nilai sebanyak mungkin. Naikan nilai MaxRequestsPerChild. Contoh sebagai berikut,

<IfModule prefork.c>
StartServers 2
MinSpareServers 3
MaxSpareServers 5
ServerLimit 16
MaxClients 16
MaxRequestsPerChild 400000
</IfModule>


Contoh lain dengan mengecilkan semua parameter seperti berikut

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          256
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      20
    MaxSpareThreads      60
    ThreadLimit          16
    ThreadsPerChild       5
    MaxClients          256
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_event_module>
    StartServers          2
    MaxClients          256
    MinSpareThreads      20
    MaxSpareThreads      60
    ThreadLimit          16
    ThreadsPerChild       5
    MaxRequestsPerChild   0
</IfModule>


Saran Lain

Beberapa kondisi overload mungkin juga tidak mungkin ditangani menggunakan teknik di atas. Untuk itu mungkin ada baiknya menggunakan http accelerator atau squid yang dikonfigurasi sebagai reverse proxy.


Referensi

Pranala Menarik