0

Context:

I have a video game client that requests a php page from the server to process user logins. This happens in a loop (terrible) and is therefore making MANY requests, per client. I plan to fix this, but that is not the point of the question.

Before my server was a Dreamhost VPS. This server managed to handle all the game clients just fine, only spawning a single Apache process to handle the login.

I just moved to a digital ocean sever as I built a new website and the dreamhost server was always very slow for the price I was paying.

The new digital ocean server does NOT handle the game client logging in now. It spawns a new Apache process for each request, meaning a single user launching the game will bring the server to it's knees, spawning hundreds of Apache processes until the login request is handled.

Question:

I would like to know if there is an Apache configuration change I can make that will limit the processes spawned from the game clients requests. I am patching the game, but I can't be sure every user will update. I have got myself in a pickle. Bonus points if the change helps fights DDoS attacks!

The server is running Ubuntu, using Digital oceans 'Wordpress' image. It has 1 GB ram and I setup a 4 GB swap file to prevent the site from crashing. A slow site is better than a dead site! I have trying enabling caching at the Apache level, but I don't know what I am doing and nothing I have done has had any affect.

5
  • Sounds like you're using the prefork Apache MPM. Look into configuring that to use sane values for your setup.
    – austinian
    Jul 17, 2015 at 19:16
  • I am using prefork. Pretend I know knowing about it though. What would sane values be?
    – Cyberdogs7
    Jul 17, 2015 at 21:21
  • This depends on how much RAM you expect a process to take up, given your web application. See the documentation. You'll want to change the variable MaxClients, which "sets the limit on the number of simultaneous requests that will be served. [...] the default value is 256"
    – austinian
    Jul 17, 2015 at 21:59
  • Another thing you could do is switch to the worker MPM, which handles all the requests with one process that uses a thread pool to process requests, and configure it to sane settings for your application/hardware.
    – austinian
    Jul 17, 2015 at 22:03
  • Use Nginx, it's much, much less resource intensive. It uses a few MB of RAM.
    – Tim
    Mar 22, 2016 at 1:08

2 Answers 2

0

One way to approach this temporarily until you patch the game would be to use Apache's mod_qos module to limit the maximum number of connections from a given IP.

You can use the QS_SrvMaxConnPerIP directive to accomplish this (see http://opensource.adnovum.ch/mod_qos/ for documentation).

An example which would limit connections per IP to 20 once there are at least 75 connections total on the server is as follows:

<IfModule mod_qos.c>
    QS_SrvMaxConnPerIP 20 75
</IfModule>
6
  • Thank you very much! I will give this a shot. I know I screwed up bad with the game code, but this is a great patch for now.
    – Cyberdogs7
    Jul 17, 2015 at 19:17
  • Where would I add this? I tried adding it to /etc/apache2/apache2.conf but there was no change
    – Cyberdogs7
    Jul 18, 2015 at 2:58
  • That should be the right place. Did you restart the apache service? If so, you might need to change apache to use MPM Worker instead of MPM Prefork if that's what you're using as from what I've read mod_qos doesn't support prefork. If you don't want to do that, you could use iptables - check out serverfault.com/a/301564/101203 - I haven't tried this personally though.
    – sa289
    Jul 18, 2015 at 3:11
  • I did restart it and I installed the MPM Worker instead of Prefork
    – Cyberdogs7
    Jul 18, 2015 at 3:58
  • Ok, I enabled the mpm_worker but now I am getting a configtest failure about needing thread safe php
    – Cyberdogs7
    Jul 18, 2015 at 4:26
0

Depending on which module your apache is compile with

<IfModule prefork.c>
 MaxConnectionsPerChild 40
 MaxRequestWrokers 10
 MaxSpareServers 13
 MinSpareServer 4
 StartServers 4
 ServerLimit 13
 MaxClients 10

<IfModule mpm_prefork_module>
 MaxConnectionsPerChild 40
 MaxRequestWrokers 10
 MaxSpareServers 13
 MinSpareServer 4
 StartServers 4
 ServerLimit 13
 MaxClients 10
</IfModule>

You can see the module by httpd -V

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .