Posts Tagged ‘apache’

Increasing Apache ServerLimit on Ubuntu

Tuesday, February 17th, 2009

I’ve been doing a fair amount of server tuning over the last few weeks and one of the issues I hit this morning was a ServerLimit directive that wasn’t being applied to the server upon a restart. Scouring Google I stumbled upon a post by Erik Ljungstrom that helped me fix my problem. You can see in my apache2.conf snippet, I’ve added a line to increase the ServerLimit to 384 and the MaxClients to 384.

<IfModule mpm_prefork_module>
    StartServers         50
    MinSpareServers      20
    MaxSpareServers      70
    MaxClients          384
    ServerLimit         384
    MaxRequestsPerChild   0
</IfModule>

When I would restart the server I would get the following message.

root@app:~# apache2ctl restart
WARNING: MaxClients of 384 exceeds ServerLimit value of 256 servers,
 lowering MaxClients to 256.  To increase, please see the ServerLimit
 directive.

Apache was running – but still capping out at 256 servers. Erik L. explains that to fully stop the server you need to run “apache2ctl graceful-stop”, wait for requests to complete and then run “apache2ctl start”. If you’re running mod_status.so (status module) you’ll be able to see the correct number of threads available to the server.

root@app:~# apache2ctl status
Apache Server Status for localhost
 
Server Version: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
Server Built: Jun 25 2008 13:54:43
 
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
Current Time: Tuesday, 17-Feb-2009 01:23:16 PST
Restart Time: Tuesday, 17-Feb-2009 01:21:45 PST
Parent Server Generation: 0
Server uptime: 1 minute 30 seconds
280 requests currently being processed, 64 idle workers
 
W__K_K_C_KWW_KWKWW__W_K_KKW_WK__KK_WKKKWWKKWK_KK_K_K_WKWWW_KKKKK
W_WWKK__KK_WK_K_W_W_WWWKW_WKKK___KWKKK_KWW_W_WK_KW__KK_K_K_K__W_
K__KWKKW_WKCKW_KWKWWKCW____WKK__KKKWKKWW__KKK_KK__KWWWKWWW_WWWWW
WKW__KWWWWW__KWWW_WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
KKWWWWWWWWWWWWKWWWWWWWWW........................................
 
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process

You’ll still get the error message, but as Grig Gheorghiu says, “know when to ignore warnings“. If anyone knows how to get rid of this error, please let me know.

PHP Memory Caching Performance

Wednesday, January 28th, 2009

Today I had the great pleasure to work with both APC and Memcached in a production environment. I’ve read that the performance of APC is roughly 3-5x faster than Memcache. So I decided to do my own test to see which performed better on my rig. If you want more numbers that may better mimic a production server environment, be sure to read Peter from the MySQL Performance Blog’s initial article which found APC to be roughly 3x faster. Although, I found that his results are spot on a little over 2 years later.

Being ultimately more concerned with the number of requests Apache serves back to my clients, I opted to use metrics similar to Jay Pipes method, leveraging ApacheBench to see determine the best way to push more content to the users faster. I created two test files which are nearly identical, accessing the cache layer using the simplest calls possible.

The tests were run against localhost after a pre-warmup to ensure the correct number of Apache workers were initiated and the cache had the correct content. This is important, because these numbers are a good comparison of read performance, but do not provide write throughput. The test was performed against a desktop system, so background processes may have varied slightly from test to test despite efforts to disable everything.

Apache bench was run over 10,000 requests with concurrency of 50. The values are the average of 3 consecutive runs. Standard deviation for connection time was consistent over each of the runs. APC proved significantly faster (30%) even with Memcached on the localhost. However, memcached scales out where as APC is tied to the local machine. That alone may be sufficient reason to use it over APC in your environment despite the performance benefit.

Some large scale applications benefit from multiple layers of caching. According to Matt Raible’s notes from OSCON 2008 Facebook uses $GLOBALS, APC and Memcached as their first lines of caching defense. This seems to further validate Peter’s findings.

Results:

APC Memcached
Requests/Second 2,088.43 1,611,.59 APC ~30% More
Time/Request (mean) 0.48ms 0.62ms APC ~23% Faster
99% of Requests Finished in 63ms 102ms APC ~39% Faster

Test Code:

The scripts are fairly straightforward. I didn’t want this to be a comparison of MySQL database accesses and so I manually created a simple object to cache.

<?php
 
	// APC Cache 
 
	$data = apc_fetch("test_object", &$success);
	if($success){
		print_r($data);
	} else {
		// store an object in the cache for the next call
		$test_object = array();
		$test_object['key1'] = 1;
		$test_object['key2'] = "hello world";
		$test_object['key3'] = array(1,2,3);
		$result = apc_store("test_object", $test_object, 3600);
		print_r($data);
	}
?>
 
<?php
 
	// Memcached Cache 
 
	$memcache = new Memcache();
	$memcache->addServer("127.0.0.1","11211");
	$data = $memcache->get("test_object");
	if($data){
		print_r($data);
	} else {
		// store an object in the cache for the next call
		$test_object = array();
		$test_object['key1'] = 1;
		$test_object['key2'] = "hello world";
		$test_object['key3'] = array(1,2,3);
		$memcache->set("test_object", $test_object, 3600);
		print_r($data);
	}
?>

System Configuration:

  • Mac OS 10.5.6
  • 2.16Ghz Intel Core Duo
  • 2 Gb RAM
  • PHP 5.2.6
  • APC 3.1.2
  • Memcached 1.1.12
  • Apache 2.2.9
  • ApacheBench 2.3

301 Redirects in Apache

Wednesday, November 12th, 2008

Taming the Beast has a nice primer on HTTP 301 redirects. I spent some time this morning cleaning up AF-Design’s internal issues after reading over the HubSpot Website Grader report. If you manage a website and haven’t already done so – consider running the free report. It takes only a few minutes to generate and read and most problems can be fixed in only a few additional minutes. You can get a handy dynamic badge too, which you can put on your internal monitoring tools to keep tabs on things.

Website Grader Score Badge Screenshot

Website Grader Score Badge Screenshot

The real takeaway on this article for me was swapping all references of www.af-design.com to just af-design.com. WordPress was already handling this for all blog entries, but the remaining sections of the site were still being referenced with the “www.” prefix. The additional lines for the .htaccess file are provided below for reference.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.af-design.com [NC]            
RewriteRule ^(.*)$ http://af-design.com/$1 [L,R=301]
© 1998-2008 AF-Design, All rights reserved.