macdonjo
By:
macdonjo

What are the best Apache configurations for an API?

March 13, 2017 371 views
Apache Django CentOS

I have the $20/month server and I am hosting a sales page, user panel and API.

The API gets a lot of traffic and the static homepage too. The entire site, all 3 parts, are built with Django/Python with Apache.

The settings I'm running are:

Timeout 10
MaxClients 75
MaxRequestWorkers 512
ServerLimit 32

Daily average traffic stats:
1500 Page Views
500 Unique Visits
200 First Time Visits
300 Returning Visits

The server will go down about once an hour for 1-2 minutes. Are there any configurations I should be using or considering?

1 comment
  • @macdonjo I'm not sure I understand the "The server will go down about once an hour for 1-2 minutes". So you're saying that every hour, the server doesn't work or respond with errors?
    If yes, can you please provide the logs of Apache, Django and (I'm guessing) MySQL, from when the problem occurs, since that will give us something to work with.

    For a $20 droplet, it should be able to sustain multiple thousands of visits every hour without any problems - unless your application is very heavy or slow to respond.

1 Answer

@macdonjo

We'd definitely need to see the logs in this case -- for Apache, MySQL, and Django; unless you know which service is going down, in which case we should take a look there first.

Traffic wise, 500-1,000 visitors a day shouldn't cause that much stress on a 2GB Droplet, so my initial thought would be that you need to fine-tune Apache + MySQL.

What I would recommend starting with is Apache unless your application doesn't rely on caching of MySQL queries and fetching cached data (for repeated requests for the same thing, in cases where data doesn't change instantly from requests to request). In this case, you may need to do both.

To start with Apache, backup your current configuration, then try something such as:

KeepAlive On
KeepAliveTimeout 10
MaxKeepAliveRequests 100
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 150
MaxRequestsPerChild 300

In your configuration, you have both MaxRequestWorkers and MaxClients -- looking at the Apache documentation, MaxRequestWorkers is what it's called now, so you're essentially setting the same thing twice. So you can remove the MaxClients setting altogether.

'MaxRequestWorkers was called MaxClients before version 2.3.13. The old name is still supported.'

https://httpd.apache.org/docs/2.4/mod/mpm_common.html#maxrequestworkers

Have another answer? Share your knowledge.