

Ask HN: Ideas for load balancing under Apache? - JohnQUnknown

I am currently facing a challenge were I must load balance a series of domains for a client&#x2F;friend, but there are some issues that I&#x27;ve been unable to fix just yet, allow me to explain:<p>* Solution <i></i>must<i></i> be a low-cost solution as money is a determining factor here.
* Client currently only has 2 VPS servers (and can&#x27;t afford to get more)
* Server specs are: 2.3 GHz monocore CPU, 1 GB RAM, 20 GB SSD Storage (both of them).
* Both servers are running Debian 7.5 Wheezy.
* Client has already installed and running zPanel in one of the servers and has configured a series of Wordpress sites.
* Client uses some WP Plugins to generate content, this hangs the server every time as CPU consumption is a lot.
* I have transfered the DB Server to the second server to help leverage the load.
* Client can&#x27;t afford downtime in the websites.
* Just managed to convince him that zPanel would not be necessary (I will write a couple of bash scripts to automate vhost creation and wordpress configuration).<p>My question&#x2F;challenge here is: How can I help leverage CPU load in the server with little to no downtime?
I have read about HAPROXY and I know for sure that this would be relatively easy with nginx, but the main setup is done with Apache and one of the sites refused to work properly under nginx (still can&#x27;t figure out why, probably .htaccess or the use of some other Apache Module, I haven&#x27;t investigated enough).
Any ideas? Any help is much appreciated.
======
JohnQUnknown
Hello again and thanks for your responses, I have been analyzing the server
performance and checked logs for when CPU peaks and I know now, as I
previously stated, that the issue is when that particular plugin (Traffic
Commando) runs.

I have been analyzing its code and it's not optimized at all (not that I was
surprised when I found out), it seems to not have any kind of limitant on how
many posts it creates on the wordpress site (it creates posts to the DB) and
it hogs up all resources. I have convinced my friend/client that the best way
is to avoid using that plugin for now until it is optimized (by me,
obviously... sigh), and it seems like we will start using some kind of caching
system as well as CDNs to leverage the toll the sites take with traffic (I'm
not really worried about that).

All in all, I guess it'll come up as a total rewrite of the plugin he is using
and implementing a caching system along with a CDN system for static files as
suggested in your comments.

Thanks a lot again for all your help!

~~~
jesusmichael
You could run the plugin as a cron job on off-peak traffic hours.

~~~
JohnQUnknown
I actually did that, I disabled the wp-cron function and switched to crontab.
I am currently monitoring the server to see if this helps or if the issue is
somewhere else.

Thanks for the suggestion!

------
jeffmould
You could use Cloudflare and their free level.

As for the WordPress sites, I would make sure there is at least a caching
plugin installed for each of the sites.

------
wmf
Replace your two crappy VPSes with one slightly less crappy VPS.

------
devnonymous
My recommendation would be to actually measure the performance of the servers,
isolate and address any possible bottle-necks in the application side of
things[1] before attempting to solve the problem using load-balancing. If, for
instance the problem is with your DB or with the communication with the DB,
splitting the incoming traffic really won't help much and depending on the
actual case, might worsen the situation.

At the very least, get the numbers for:

    
    
      1. Response time for a single static file request
      2. Response time for a non-db php request (eg: phpinfo() )
      3. Response time from the application for a non-db request
      4. Response time from the application with a db request
      5. .... with/without plugins ...you get the idea
    

This will tell you where you need to concentrate your performance improvement
efforts on.

Also, look at solutions that are easy to implement and offer immense benefit
for very low effort like server-side caching
(eg:[https://github.com/BenjaminAdams/wp-redis-
cache](https://github.com/BenjaminAdams/wp-redis-cache) /
[http://www.jimwestergren.com/wordpress-with-redis-as-a-
front...](http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-
cache/) )

cheers,

[1] Your statement that _Client uses some WP Plugins to generate content, this
hangs the server every time as CPU consumption is a lot._ is an alert.

------
jesusmichael
I'm not sure what your goal is here... manage CPU load or traffic load? Sounds
like you have a couple of problems.

1\. Web services (http), how much traffic? What version of PHP? Did you shut
down all unnecessary modules?

2\. Inbound traffic (content generation) These processes are creating content
on the fly, or writing to the DB?

Reality is it would cost you less (time is money), to put in a couple of
multi-core processors and 4Gs of RAM, and its going to be necessary if traffic
continues to grow.

Also you can offload much of the static serving load to AWS S3. There is a CDN
for Wordpress that's free too.

