Preventing Server Overload with Drupal Cache Settings

kentbye's picture
| | |

One of the concerns that I have with a Drupal site is getting overwhelmed with traffic without the proper configuration. A link from Slashdot.com -- a tech discussion community website & "News for nerds" -- can bring a site down from so much traffic.

OurMedia.org got slashdotted on the same day it launched back on March 21, 2005.

It didn't take long for Ourmedia to be slashdotted.

Just what we needed with our servers already getting slammed.

The OurMedia servers got so slammed that it brought the site to its knees.

I was concerned and asked Moshe about it:

KENT: When I told my Web Host about my project he told me:
"one thing to watch though is not to have a program that accesses mysql for every page hit. I'm getting overloaded with that."

MOSHE: well, cached pages have 2 database calls, as opposed to 50+ for a regular page. a cached page is very light weight. cached pages are served to anonymous users, which is the vast majority, especially in a slashdot situation. drupal routinely survives a slashdot when configured properly.

KENT: I just want to be prepared for the worst case scenario of overloading my web host and having a fat bill to pay for bandwidth issues.

MOSHE: caching doesn't really help with bandwidth bill. it helps with making sure all users actually get what they request. the best way to reduce bandwidth is to minimize the number of images in your theme. the images you do show should be small in dimension and compressed in size.

It was in this context that I tried to alter the Cache Settings on the Admin -> Settings Page from Disabled (low-traffic sites) to Strict (medium-traffic sites)

[inline:cachesettings.jpg=Page Cache Settings]

After a full day of being set like this, I saw an error and took a screen shot of it.
[inline:cachebootstrap.jpg=Cache Errors]

I didn't see the error again. But then I started seeing the same error pop up in my log files:
[inline:headerlog.jpg=Log tracking the Bootstrap/Page Caching/Header Errors]

It started happening after Moshe logged in to my site, but then it appeared to only be happening with Anonymous users.

I logged out and looked at my site as an Anonymous user, I started seeing the same type of error:

Notice: Undefined index: HTTPS in /www/echochamberproject/sites/echochamberproject.com/settings.php on line 90

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/session.inc on line 10

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/bootstrap.inc on line 527

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/bootstrap.inc on line 528

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/bootstrap.inc on line 529

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/bootstrap.inc on line 530

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/bootstrap.inc on line 531

warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/sites/echochamberproject.com/settings.php:90) in /www/echochamberproject/includes/common.inc on line 99.

I then went to the homepage and saw an absolute meltdown:
[inline:meltdown.jpg=Cache Meltdown]

Here was some of the error:

Notice: Undefined index: module in /www/echochamberproject/includes/bootstrap.inc on line 90

Notice: Undefined index: module in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: filter in /www/echochamberproject/includes/bootstrap.inc on line 97

Notice: Undefined index: statistics in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: system in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: system in /www/echochamberproject/includes/bootstrap.inc on line 97

Notice: Undefined index: throttle in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: user in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: user in /www/echochamberproject/includes/bootstrap.inc on line 97

Notice: Undefined index: watchdog in /www/echochamberproject/includes/bootstrap.inc on line 389

Notice: Undefined index: watchdog in /www/echochamberproject/includes/bootstrap.inc on line 97

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/includes/bootstrap.inc:90) in /www/echochamberproject/includes/bootstrap.inc on line 502

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/includes/bootstrap.inc:90) in /www/echochamberproject/includes/bootstrap.inc on line 503

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/includes/bootstrap.inc:90) in /www/echochamberproject/includes/bootstrap.inc on line 511

Warning: Cannot modify header information - headers already sent by (output started at /www/echochamberproject/includes/bootstrap.inc:90) in /www/echochamberproject/includes/bootstrap.inc on line 519

I saw caching in the error message and so I switched the Page Cache Settings from Strict (medium-traffic sites) back to the default setting of Disabled (low-traffic sites).
[inline:cachesettings.jpg=Page Cache Settings]

This switch back to the default setting appears to have solved the Anonymous page cache error problem for now.

But it's the "(low-traffic sites)" of the Disabled Page Cache setting that worries me, and makes me think that my site is pretty inadequately prepared to handle being slashdotted.

Here's a Drupal page with more information about throttle control -- I'd like to figure out how to properly throttle my site can withstand being slammed with traffic.

warning level

when you see Notice: at the beginning of an error, you can ignore it. PHP is just informing you of a minor non-issue. I just changed your settings.php to not report these to screen. The Warning: messages happen as a result of printing Notices to screen. You are set now. I set cache to 'strict'.

if you anticipate high traffic, you might also set your throttle settings at http://www.echochamberproject.com/admin/settings/throttle and on http://www.echochamberproject.com/admin/modules. I don't have defintive experience with these settings. better to ask in IRC or forums.

kentbye's picture

Thanks Moshe!

Thanks for clearing that up Moshe.

So I guess you're saying that the "Notice" messages were causing the warning messages, and you changed the settings.php to stop this from happening again.

It seemed to happen with anonymous users, so I'll keep an eye on my admin log to see if I start seeing any similar errors.

I'll tagged this throttle page to look into more.

I'll read through it for more details and ask on the #Drupal-Support IRC channel to clarify my settings.

Thanks again Moshe!
-Kent.