Posts: 861
Threads: 0
Joined: Oct 2012
Reputation:
8
Help optimize ROK's server apache settings!
11-19-2013, 07:41 PM
Is apache crashing, or is it possibly the database from the sheer volume of queries?
Posts: 861
Threads: 0
Joined: Oct 2012
Reputation:
8
Help optimize ROK's server apache settings!
11-19-2013, 07:46 PM
Actually, I'm seeing super high times on loading static assets (jquery, css, etc). So it's likely apache. Are apache and mysql on the same machine?
Posts: 861
Threads: 0
Joined: Oct 2012
Reputation:
8
Help optimize ROK's server apache settings!
11-19-2013, 07:57 PM
Yeah, so it's the sheer volume of requests. For every html page load (that is a single apache request), it's making an additional 30-ish http requests (each image is 1 request, each css file is 1 request, each js file is one request, etc). So each visitor is making 30 requests. If you have 20 visitors per second, that puts you at the 600 client limit. And when it reaches the max number of clients, it has to queue them up while the others get served. And the queue will grow until it starts dropping connections, hence why we are getting denials.
So, there are a few options (in order of how good they are to implement in terms of $ and time)
1. Use a CDN for static assets. This is a *great* option, as CDNs are more tuned for static file access (and are inherently more scalable).
2. Add additional server(s) - have them load balanced. This will distribute the load across multiple machines, and remove the "single point of failure"
3. Implement more caching - I believe WP has caching plugins, although I'm not familiar with how they work
4. Increase the server size - probably expensive and more downtime. Not a great idea (at least not now).
Posts: 26
Threads: 0
Joined: Nov 2010
Reputation:
2
Help optimize ROK's server apache settings!
11-19-2013, 08:40 PM
Whoa - just saw that you were trying to serve 7,000 comments off that post? That's going to be a huge DB bottleneck (that may present itself as a PHP/Apache problem, when in reality, they are waiting on the DB). Sites much bigger than this (with 25-50 servers) can't handle that load without timing out.
Turn off comments on that post and start a new one for follow ups. Also, caching or a CDN works wonders when all of your traffic is to one URL, so it may be hard to start up, but it's perfect for this situation.
Also, it's too late now, but server monitoring services like NewRelic do a great job of helping you figure out exactly what is wrong at times like this, for future reference.
Posts: 861
Threads: 0
Joined: Oct 2012
Reputation:
8
Help optimize ROK's server apache settings!
11-19-2013, 08:43 PM
ROK is disqus commenting, correct?
Posts: 861
Threads: 0
Joined: Oct 2012
Reputation:
8
Help optimize ROK's server apache settings!
11-19-2013, 09:26 PM
Of course, if you just want to get it back usable, we could deny requests from people have a specific referrer (for example, coming from jezebel[dot]com). Is that something you want to try?
Posts: 9,583
Threads: 0
Joined: Jan 2011
Reputation:
217
Help optimize ROK's server apache settings!
11-19-2013, 10:34 PM
The collective power and knowledge in this forum is, when you stop and think about it, astounding.
Tuthmosis Twitter | IRT Twitter
Posts: 95
Threads: 0
Joined: Jan 2011
Reputation:
6
Help optimize ROK's server apache settings!
11-19-2013, 10:45 PM
As a couple of others have pointed out, Apache is quite inefficient and slow compared to something like Nginx, and hogs up more resources on the server.
Something that you could try to alleviate problems in the short term would be the following:
Install Nginx on the server, and put it in front of Apache as a reverse proxy server. What this allows you to do is let Nginx handle every incoming request and only pass things to Apache if and when required.
This will enable you to serve off all static assets and resources directly from Nginx without the request having to touch Apache. And Nginx is really fast and efficient at doing this.
Another more involved setup is to put Varnish in between Nginx and Apache in the above setup to add another level of caching. Varnish can cache a lot of stuff from blocks of content, to entire pages. So in such a setup, Apache will see only the absolute minimum of requests and therefore never end up in a bloated resource hogging state.
The other easier setup would be to if server administration is not your cup of tea, would be to sign up on something like CloudFlare which acts as CDN and can cache most of your pages and serve them directly without the request ever having to hit your server.
If you have any particular questions or doubts on how to some of the above steps, give me a shout and I can explain more.
Game is not about sex. Sex is a by-product, albeit an excellent one, it is the thrill of the hunt!!
Posts: 395
Threads: 0
Joined: Jul 2013
Reputation:
5
Help optimize ROK's server apache settings!
11-19-2013, 10:48 PM
I think the best quick fix here is to install CloudFlare, as others have suggested. I'm sure some of the haters will get their boyfriends/hangers-on to implement a DOS (denial of service) attack soon enough, so CF will protect against that too.
Basically they cache and optimize the content, and pull it from your server to their server, then serve the request from their servers, which are placed at locations around the world. But while they do it, they also combat DOS attacks, and anyway those attacks end up being handled by their servers not yours. It's basically like putting a security guard in front of your server who controls who gets access to content.
As for Apache tuning, I work mostly with IIS tuning (which is a different model due to shared processes) but one item that stands out is that keep-alives are off. I believe that the benefits of keeping this on, on a page with so many items (30+ images, scripts, etc) is that the browser can use its existing idle connection to the server to pull the next item, instead of making a new connection. That's a big performance improvement because connection set-up time is slow.
The drawback is that you have lots of open connections, but most Unix systems can handle that well. The thing I'd worry about is the overhead to keep killing off the keep-alive connections as they idle out, but I'm not familiar enough with Apache to comment on how well it does this.
Posts: 39
Threads: 0
Joined: Feb 2012
Reputation:
0
Help optimize ROK's server apache settings!
11-20-2013, 01:12 AM
A CDN and protecting against a DDOS attack would be my priorities. CloudFlare is free but Roosh if you wanna go for CloudFlare Pro I'd be happy to chip in $10 for the first month.
Should I just go put $10 in the ROK tip jar instead?
Posts: 19,387
Threads: 0
Joined: Aug 2008
Reputation:
414
Help optimize ROK's server apache settings!
11-20-2013, 04:02 AM
Thanks for the help so far guys. Here has been my triage solution:
-Use CDN for static files
-Turn on Keep Alive with a timeout of 2 seconds
-Reduce max clients to 350
-Reduce timeout to 10 seconds
-Ask people via our Twitter feed not to share our site anymore.
As of 4am EST, the site is doing fine with 1,000 simultaneous users.
Installing NGINX was planned, but I don't want to do any major upgrades until this viral episode passes.
Posts: 2,261
Threads: 0
Joined: Apr 2011
Reputation:
29
Help optimize ROK's server apache settings!
11-20-2013, 06:07 AM
Nginx, good Russian software. Their site is cool, no bullshit -
http://nginx.org/
"A flower can not remain in bloom for years, but a garden can be cultivated to bloom throughout seasons and years." - xsplat