Friday, January 15, 2016

[Apache2] To increase the concurrent request number of apache server

This post is just the memo for my a little task. Our web app is a Django app in Apache2 web server.
I currently tested our several RESTful APIs and found the maximum concurrent request number is not good enough (around 350) so that I try to tune it to the accepted level, for instance: more than 500.

I also found that if the concurrent request is bigger than the number (350), then I will often see the apache benchmark tool showing the error: apr_socket_recv: Connection reset by peer (104), which means web server suddenly disconnected in the middle of the session.

So, there are two things coming up to my mind: Apache2 configuration and Linux tuning.

For Apache2:
I follow this document to change the mpm_worker.conf as follows:

The defulat value:

ServerLimit 16
StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25

What I changed in my mpm_worker.conf
vi /etc/apache2/mods-available/mpm_worker.conf

<IfModule mpm_worker_module>
        ServerLimit              40
        StartServers             4
        MaxClients               1000
        MinSpareThreads          25
        MaxSpareThreads          75
        ThreadLimit              64
        ThreadsPerChild          25
        MaxRequestWorkers        2500
        MaxConnectionsPerChild   25

For Linux tuning:
I follow this document to enlarge the system variables.

sysctl net.core.somaxconn=1024
sysctl net.core.netdev_max_backlog=2000
sysctl net.ipv4.tcp_max_syn_backlog=2048

No comments: