Posts Tagged ‘apache’
PHP Apps: Apache vs Nginx
I’ve always read (and witnessed) that nginx is a far more efficient web server than Apache. In fact, people are noticing in vast numbers as evidenced by the latest numbers from Netcraft on web server market share. nginx market share has exploded out of nothing in the past couple of years (it’s only been around since 2005). nginx uses less memory and it much lighter than Apache, so for obvious reasons, it has become very popular. It is incredibly fast and powerful as an http and mail proxy, but just how does it do as a stand-alone PHP application server?
For myself, I wanted to know if Wordpress would run faster on an nginx or Apache server. There are plenty of how-tos out there on setting up nginx to use fastcgi for PHP applications, so I won’t go into that, but I happened to use this one.
For my little test, I used Apache Bench (ab) on a separate machine attached to the same switch. I took four tests and averaged the total time to complete the requests given by the output of Apache Bench. Below is a test of 100 requests one at a time (total time in seconds, lower is better):

That wasn’t at all what I was expecting. It wasn’t any different at all, really. The numbers were: 40.00 seconds for nginx and 40.04 for Apache. Add a little roundoff error in there and we really can’t say much about the results.
The numbers get a little more interesting when I start adding a little concurrency:



Definitely a trend, but even at 40 concurrent connections it’s not really anything worth writing home about. With a little tweaking I’m sure the concurrency issue can be throw into a whole ‘nother direction, but I just took what came out of the “box”.
Another interesting thing that I noticed was the memory usage between the two. With Apache, the web server used 23400K of memory. nginx used significantly less memory than that weighing in at a measly 4356K. However, since it can’t interpret PHP on its own and uses fastcgi, we have to add that in as well. That adds 19228K of memory, totaling 23584K, slightly more than Apache!
Apache and nginx seem to be almost the same when being used to run straight PHP applications. If you’re looking for a lighter-weight straight application server for PHP, I probably wouldn’t look any further than the LAMP stack since it has been made extremely easy to install and configure on popular Linux distros. Start adding load balancing, web proxies, mail proxies, and fault tolerance and then I’d start looking at nginx. Otherwise, I’ll be sticking with Apache for my PHP apps for now.
Tags: apache, nginx
Filed under Uncategorized :
Comments (0) :
Aug 21st, 2009
Slow Apache Starts on Ubuntu
An Apache server that I was working with was having an issue starting in a reasonable amount of time. This particular server was running on Ubuntu 8.04 on top of VMware ESX 3.5. The service would start eventually, but would hang for a fairly significant amount of time. In the Apache error logs it would show the following line:
[notice] Digest: generating secret for digest authentication ...
Eventually, the digest generation would finish and my websites would come back. Sometimes it would take just a few seconds and other times it would take about 30 seconds. After doing a little digging, I found that a number of people were having this issue, with very few answers.
The root problem, as I found out, was that the OS was running out of entropy. One can see how much entropy is available with the following command:
sudo cat /proc/sys/kernel/random/entropy_avail
My system was returning a value somewhere around 150-200 and went down to nothing while Apache was generating its digtest. When I looked at the same file on other systems, they were all 2000+, an obvious problem.
According to a couple of blog posts, installing rng-tools and running the rngd daemon seemed to be the answer.
I did a quick install of rng-tools:
sudo apt-get install rng-tools
However, rngd failed to start, reporting that it couldn’t find the hardware generator:
/etc/init.d/rng-tools: Cannot find a hardware RNG device to use.
invoke-rc.d: initscript rng-tools, action "start" failed.
After a little more searching, I found out that you simply have to change the source for the generation to /dev/urandom:
sudo vim /etc/default/rng-tools
And changed the line:
#HRNGDEVICE=/dev/hwrng
To:
HRNGDEVICE=/dev/urandom
Save the changes and start rngd:
sudo /etc/init.d/rngd start
Now, ‘catting’ my entropy_avail file displayed over 2000 like my other systems and Apache starts right up on a restart.
Tags: apache, linux, ubuntu
Filed under How-Tos / Tips :
Comments (1) :
Mar 17th, 2009
