Handling Incoming Traffic from High-Volume Sites

Events happening in the community are now at Drupal community events on www.drupal.org.
Mike Wacker's picture

At CornellSun.com, we had an article about the deaths of two students in < 24 hours get linked to on the front page of huffingtonpost.com. While the link was there, our site was absolutely overwhelmed with traffic well past what our server could handle. Obviously, we're working on a plan to handle a similar situation in the future, but I thought it would be a good idea to share our experience with this group and also get some feedback.

Here are some of the issues we experienced (we're running MediaTemple's (dv) Extreme server):

  • Pages often would take forever to load or fail to load
  • Attempts to start shell sessions on the server via ssh would often fail
  • Shell commands (including attempts to stop/restart Apache) often failed due to lack of memory
  • Apache would occasionally go down
  • After apache was restarted, shell commands would run into memory issues within 15 seconds

As you can see, that is a lot of traffic, and obviously it is almost exclusively anonymous users. I recall us having an article in the past which ended up on Slashdot and the Drudge report (but not in a very prominent spot), which our server seemed to be able to handle, but this barrage from the Huff Po proved too much.

While Drupal has good caching for pages served to anonymous users, it obviously wasn't enough for us.

We resorted to creating a separate static page which stripped out nearly everything: images, Javascript, interactive features, etc. If I recall correctly, the static page required only 3 HTTP requests: 1 to retrieve the static page, and in the page, 1 for the masthead image, and 1 for the CSS - all Javascript was either inline or pulled the source from an external site (e.g.: Google). I believe (but am not 100% sure) that the deluge of HTTP requests was a major reason why the memory usage was so high - I recall CPU usage being hotter than usual, but not intolerably high.

After creating the static page, we got the URL for that story to redirect to this static page (I did not do that task, but I remember that it was done in our .htaccess file). One disadvantage to this approach was that the URL which appeared in the browser was that of the static page (http://cornellsun.com/student-deaths.html) instead of the original URL (http://cornellsun.com/section/news/content/2010/03/15/cornell-community-...). Ideally, in the future I still would like users to see the URL of the original story, so that if users shared or saved the link when the static page was served, they could get the normal version once we could start serving it again.

After we did this, the site was still kind of slow, but it seemed to be tolerable at this point, and editors working with the website were able to get their work done (whereas that was not the case earlier).

In terms of developing a solution, one thing to keep in mind that while obviously newspapers want to handle links from these high-volume news sites, at the same times such links are very rare. You obviously want to handle this scenario which happens 1% of the time, but you don't want to do something which has the risk of messing up the site the other 99% of the time.

Comments

Are you using the Boost

choloepus's picture

Are you using the Boost module?

Basically, it creates the static pages in the background and the pages are served thru the web server, bypassing mod_php and drupals bootstrap.

Have you done anything to the apache configuration? MaxClients/KeepAlive? Are you using xcache/apc/eaccelerator?

Server suggestions for newspapers using Drupal

AXcess News's picture

I really found this: http://groups.drupal.org/node/5281 helpful when I first began exploring the Drupal forum on newspapers.

After reading your post on traffic problems, which was very detailed [thank you], it made me wonder why there wasn't a reference page created relating to server suggestions for developers considering Drupal for a newspaper site.

If there is such a page, I recommend the group admin add it as a link at the front of the forum, just like the link above is provided.

I am not a developer, but a publisher, and as a person who writes paychecks... I expect not only stories that draw readership (often through the web's power of linking), but a server foundation designed from the ground up in anticipation of building traffic.

It's great to see a story now and then explode w/traffic but finding work arounds that strip out all of the revenue [ads] from a page just so people can read it would make me furious.

While some readers would say...'THIS forum is about DRUPAL, not servers", I say, if your going to use a CMS then look at issues surrounding its limitations as it relates to the server or servers themselves. Afterall, servers are what makes the CMS funciton in the first place and with Drupal and all of its modules taxing a server's memory, its like using a truck that gets great fuel milage but can't carry the weight you haul unless the suspension is beefed up ahead of time.

I would like some feedback on this or helpful links to non-drupal forums that deal with server setup and configuration issues relating to traffic capabilities.

Agree

yelvington's picture

I have to agree with choloepus ... any media site is going to be subject to such experiences, and should be fronted with a caching solution that protects Drupal and MySQL from needless requests. Boost is a very good, very easy to implement solution for small sites. Larger sites should have a reverse proxy server such as Squid or Varnish. The latter is included in the Pantheon Mercury AMI, so it's easy to implement.

There are a lot of other tricks of the optimization trade, discussed in http://groups.drupal.org/high-performance

thanks for the tip

AXcess News's picture

Thank you yelvington for your prompt response to 'traffic' issues and what can be done about it. I appreciate you providing that link - it should be added to the newspaper group's list of links!

Mysql/Apache settings

netbabu's picture

When this kind of unexpected overload happens, some clients(both new and existing ones) make emergency calls and ask for a quick solution. It's not enough if you just increase bandwidth, RAM and CPU power. Most important thing is optimizing mysql and Apache settings after you upgrade the hardware.

I think clients could handle such situations better if they are willing to pay monthly maintenance fees to enable consultants to monitor the server regularly and take quick action. There are some good money-making websites that refuse to do that!

-Babu
Drupal Projects showcase: http://paramprojects.com/website/drupal-servicesprojects
Promote Drupal with Tshirts/merchandise: http://paramprojects.com/drupalstore

Some More Thoughts

Mike Wacker's picture

Thanks for the feedback! I talked to a former Web Editor, who basically broke it down to this: "Apache simply cannot handle massive volumes of concurrent connections in a low memory environment such as the sun's VPS." He pointed us to some resources about either replacing apache with nginx (http://drupal.org/node/110224) or running it in front of apache (http://groups.drupal.org/node/50168#comments).

While I like ideas like nginx and Boost, my main concern is that if something does go wrong in setting them up, something I can't discount (the list of modules for newspapers does have an explicit warning about Boost), then that would affect the website 100% of the time. Also, for those who don't have the server expertise for their paper (not out of question, given the current financial state of journalism), they may want to find a slightly different route.

In terms of Boost, too, if the issue really does come down to the number of HTTP requests, then I don't know how much it helps to serve a static page if it includes lots of images and Javascript which will also have to be retrieved with additional HTTP requests. The box to print/email/share our content alone has 8 small icons, each of which requires an HTTP request to retrieve afte the page is loaded.

While I've heard Amazon's cloud computing solution, EC2, is quite expensive, and I don't know if we'd want to try that transition anyway, one interesting idea someone mentioned to me was to use their S3 storage service not as a solution for all our images, but for some common images (e.g.: the masthead, the print/email/share icons, etc.).

One idea I've had, which is targeted at the 1% of the time we get hits, and requires coding but not server expertise, is to create some special templates file for a light version of the node page in the theme, which generates something similar to the stripped-down static page you saw. There could then be a module which could then enable this light theme for a specific node. The way I would do it would be to have template.php use the lightweight template files if it detected a node for which the lightweight version was enabled. (Hope that explanation makes sense.)

But in any case, I feel like the only way to get a good feel for what will and will not work would be to do some stress testing on our dev server. If anyone has any good ideas on how to do that, feel free to comment.

Well, everything has its

choloepus's picture

Well, everything has its limit.
From the experience, I know that even large servers farms can struggle from the sudden traffic.

Although I agree that nginx is more lightweight, that Apache, I would make sure that apache is properly configured.

  • Do you have a short KeepAlive? 3 seconds is enough
  • Have you configured MaxClients setting correctly? If it is set too high, the server would come to its knees pretty fast.
  • Have you configured Expires headers/Etags (that would only matter for the regular users, not for the single time visitors)
  • BUT, if you headers are setup correctly you can start thinking about Varnish/Squid in front of the web server.

Boost & Server Tuning

mikeytown2's picture

the list of modules for newspapers does have an explicit warning about Boost

I'm curious about this, can I get more info?

You bring up a good point... I should create a Oh **** guide for getting boost up and running and the order in which to do it. Using a CDN will fix most of your other issues. Tuning Apache can get you far, but Nginx is the way to scale to thousands of hits per second. Tuning MySQL can take you to the moon, the default configuration for MySQL isn't good & you really need to add indexes to tables.

Short list of tables that can benefit from an index:
* All CCK fields that you use in a view. File Field: create an index on the fid; date: index on date; index on value; etc...
* access: type, mask, status
* comments: timestamp
* node_comment_statistics: comment_count
* menu_links: external, updated, customized, depth
* users: pass, status
* menu_custom: title
* date_format_types: title
* filter_formats: roles
* content_group: weight, type_name, group_name
* term_data: name
* system: name
* imagecache_preset: presetname
* blocks: module, delta
* system: status, type
* content_node_field: type, widget_type

There could be other modules that don't use indexes where they should; you can figure out what they are by doing this:
in /etc/my.cnf

# Debug
long_query_time = 1
log-slow-queries = /var/log/mysql/mysql-slow.log
log-queries-not-using-indexes

Restart mysql & let it run for a couple of days, or in a lab run lots of tests that mimic a user, admin & anonymous.

Next download http://www.willamowius.de/download/mysql_explain_slow_log (perl script) see: http://www.willamowius.de/mysql-tools.html
Run perl mysql_explain_slow_log.pl < /var/log/mysql/mysql-slow.log > out.txt
Look at out.txt for Queries causing table scans -------------------. Add indexes till all the ones that don't select the entire table (SELECT * from drupal.variable) go away.

Follow Up

mikeytown2's picture

Code to auto add in indexes
http://groups.drupal.org/node/57213

mysql_explain_slow_log

calebgilbert's picture

Just a note that it ended up being this to get the mysql_explain_slow_log to work for me:

perl mysql_explain_slow_log --host=localhost --user=user --password=pass < /path/to/mysql-slow.log > /path/to/out.txt

Can also use mysqldumpslow (which is different than mysql_explain_slow_log) by locating mysqldumpslow on you system (on Cent its in /usr/bin) and do:

mysqldumpslow -s at -a -t 300 /var/log/mysql/mysql-slow.log > /var/log/mysql/out_mysqldumpslow_time.txt
(with these options it would put the 300 queries which took the most amount of time to execute in out_mysqldumpslow_count.txt)

mysqldumpslow -s c -a -t 100 /var/log/mysql/mysql-slow.log > /var/log/mysql/out_mysqldumpslow_count.txt
(with these options it would put the top 100 most frequently repeated slow queries in out_mysqldumpslow_count.txt)

In terms of Boost, too, if

brianmercer's picture

In terms of Boost, too, if the issue really does come down to the number of HTTP requests, then I don't know how much it helps to serve a static page if it includes lots of images and Javascript which will also have to be retrieved with additional HTTP requests. The box to print/email/share our content alone has 8 small icons, each of which requires an HTTP request to retrieve after the page is loaded.

When we talk about requests we mean serving actual pages and not a theoretical limit of given hardware to handle TCP/IP requests. Static files be served hundreds or thousands of times faster than dynamic pages generated through Drupal's PHP code. Images and javascript are static files as well.

... one interesting idea someone mentioned to me was to use their S3 storage service not as a solution for all our images, but for some common images (e.g.: the masthead, the print/email/share icons, etc.).

This is what we mean when we talk generally about using a CDN, a content delivery network. We mean that we offload static resources like images, css, js that are rarely changed to another computer system that is optimized to serve static files. It can also include multiple copies at servers located around the globe with technology that ensures that the request is handled by the server closest to the client. The static full-page files generated by Boost may need to be changed often, so they are not offloaded to a CDN. There are many providers of this type of service and Amazon S3 is considered one of the slower ones.

One idea I've had, which is targeted at the 1% of the time we get hits, and requires coding but not server expertise, is to create some special templates file for a light version of the node page in the theme, which generates something similar to the stripped-down static page you saw. There could then be a module which could then enable this light theme for a specific node. The way I would do it would be to have template.php use the lightweight template files if it detected a node for which the lightweight version was enabled. (Hope that explanation makes sense.)

The usual bottleneck is the ability of Drupal php code to run through the bootstrap process, interpret PHP code (including theme files), process possibly inefficient contrib modules, transact with a mysql server, and programatically generate dynamic pages. A light theme doesn't solve those. Boost or Varnish or Squid does.

Your site does get a a 53 from Yslow but that's mostly due to using five image/flash/javascript heavy advertisers. You may wish to install Firefox/Firebug/Yslow and take a look at that. It's also spamming the console with some nasty error having to do with an advertiser and security.

If you don't have the expertise, or money to hire the expertise, to optimize your site and servers for high traffic then you should plan to spend a good amount of time on groups.drupal.org to learn. Everything you need is here. Welcome.

Boost, PHP and MySQL

yelvington's picture

Solutions like fronting the system with NGINX fix a small problem (NGINX is faster than Apache for serving static files) while ignoring the big problem (a dynamic page generatiion cycle for Drupal, PHP and MySQL is hundreds of times more expensive). You need to cache generated pages outside of Drupal. That's what Boost does.

The cited warning about Boost refers to our experience over a year ago with a 5.x version of Boost that did not maintain the cache directory well. That's no longer the case; in fact, the current 6.x version does a very good job of keeping track of what needs to be purged.

If you're concerned about it, you can set the TTL on cached pages to something low, like 5 minutes, and still be VERY well protected against crushing traffic spikes from a Drudge or Fark link.

Keep in mind that Boost pages are served ONLY to anonymous traffic.

Flattened HTML pages (such as Boost creates) are served by Apache without being parsed for PHP, and of course there is no connecting with the database, running queries, et cetera. Unless you've done an extraordinary job of tuning your system, there will be an immediate and possibly stunning performance improvement for casual visitors. That's a bonus on top of the safeguard against Slashdotting.

I use Boost on my personal site, but we do not use it for our newspaper sites. We have Squid configured as a caching reverse proxy, connecting through a load balancer to a farm of multiple app servers running Linux, Apache, MySQL, PHP, Drupal and Memcache. In this scenario, Squid plays the same role as Boost, maintaining pages in a cache and serving them to unauthenticated visitors. It's a nontrivial thing to set up and maintain, and you don't need it for the typical smaller site.

verify

SSzretter's picture

how can I verify that boost is working on a particular page?

If you View Source for the

brianmercer's picture

If you View Source for the page there should be a comment at the very bottom similar to:

<!-- Page cached by Boost @ 2010-04-23 01:19:04, expires @ 2010-04-23 02:19:04 -->

(unless you've turned that off in the options or unless that is the first time the page is viewed since a cache flush, in which case you can do a refresh while holding the shift button and that should get you the cached page.)

today Task

avanish12's picture

Hello Mike,
As per my thought you did lot's of mistake on site.
You never follow developer for the loading time.
Now either purchase new site from market with fair concept.
Or ask your developer to increase site performance (they can't do :).
We can help you if your requirement is clear .
We work if your market and business view clear.
Why you use lot's of views(module) on this site.

Regards
Avi (+91-9211-524-602)

Newspapers on Drupal

Group organizers

Group categories

Topics - Newspaper on Drupal

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: