Apache2 Outperforming lighttpd 1.5

Support this website by purchasing prints of my photographs! Check them out here.

Here's an output of top on my VPS running Ubuntu 10.04. The first output is while a server was running Apache2 (and lighttpd on a secondary port). The Apache2 instances were under heavy stress testing at the time, and their total CPU was 30.2%. In the second output, lighttpd had taken over as the main server instance (Apache2 was completely disabled). In this scenario, lighttpd was under no load and is using 46.2% CPU (those php-cgi processes are part of lighttpd). Memory usage is counted and doubled, since the VPS is telling the OS that it has twice the RAM available.

I must be doing my math wrong or something; Isn't lighttpd supposed to be the more efficient of the two servers?

top - 21:00:13 up 47 days, 21:08,  1 user,  load average: 0.33, 0.15, 0.05
Tasks:  30 total,   1 running,  29 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  0.2%sy,  0.0%ni, 98.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    946344k total,   505324k used,   441020k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
17925 www-data  15   0  195m  11m 5816 S    3  1.3   0:01.49 apache2
14217 www-data  15   0  195m  11m 5816 S    2  1.2   0:01.44 apache2
19854 www-data  15   0  195m  11m 5816 S    2  1.3   0:01.39 apache2
30485 www-data  15   0  195m  12m 6704 S    2  1.4   0:01.68 apache2
30540 www-data  15   0  195m  11m 6064 S    2  1.3   0:01.69 apache2
14215 www-data  15   0  195m  11m 5816 S    1  1.3   0:01.40 apache2
19855 www-data  15   0  195m  11m 5972 S    1  1.3   0:01.36 apache2
30515 www-data  15   0  195m  11m 5864 S    1  1.3   0:01.68 apache2
30495 www-data  15   0  195m  11m 5852 S    1  1.3   0:01.67 apache2
30532 www-data  15   0  195m  11m 5824 S    1  1.3   0:01.82 apache2
12190 www-data  15   0  195m  11m 5812 S    1  1.2   0:01.69 apache2
 9641 mysql     18   0  307m  32m 7816 S    0  3.5   1:40.80 mysqld
 9787 nobody    18   0  149m  13m  916 S    0  1.5   0:12.37 memcached
 1 root      15   0 23308 1560 1264 S    0  0.2   0:03.15 init
 3982 root      15   0 18008 2120 1492 S    0  0.2   0:00.29 bash
 9678 root      15   0 21072 1012  776 S    0  0.1   0:11.93 cron
 9752 root      15   0 70608 3212 2484 S    0  0.3   0:00.05 sshd
 9771 syslog    15   0 12444  796  604 S    0  0.1   0:10.71 syslogd
 9829 root      18   0 49256 1084  540 S    0  0.1   1:37.00 sshd
 9873 root      15   0 69512 2452  780 S    0  0.3   0:11.83 sendmail-mta
 9958 www-data  25   0  122m 7396 4480 S    0  0.8   0:00.01 php-cgi
 9977 www-data  15   0  123m  10m 6060 S    0  1.1   0:06.17 php-cgi
 9981 www-data  15   0  125m  18m  11m S    0  2.0   0:06.65 php-cgi
 9982 www-data  15   0  124m  12m 8520 S    0  1.4   0:06.30 php-cgi
 9984 www-data  15   0  124m  14m  10m S    0  1.6   0:06.26 php-cgi
23562 root      15   0 19084 1328 1060 R    0  0.1   0:00.04 top
25949 tlhunter  15   0 70608 1796 1032 S    0  0.2   0:01.12 sshd
26144 tlhunter  18   0 17856 1920 1444 S    0  0.2   0:00.00 bash
30255 root      16   0 35580 1272  972 S    0  0.1   0:00.02 su
30406 root      18   0  193m 8508 3980 S    0  0.9   0:00.07 apache2

30.2% belongs to apache (doubled since the VPS doubles our reported max RAM)

top - 22:47:45 up 2 days, 9 min,  1 user,  load average: 0.06, 0.01, 0.00
Tasks:  24 total,   1 running,  23 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    946344k total,   415264k used,   531080k free,        0k buffers
Swap:        0k total,        0k used,        0k free,        0k cached

 PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1 root      15   0 23308 1552 1260 S    0  0.2   0:00.37 init
 7182 tlhunter  18   0 70608 1668  944 S    0  0.2   0:00.00 sshd
 7302 tlhunter  16   0 17856 1920 1444 S    0  0.2   0:00.00 bash
11438 root      16   0 35580 1268  972 S    0  0.1   0:00.01 su
13622 www-data  18   0 91568 2992  908 S    0  0.3   0:01.07 lighttpd
13625 www-data  23   0  137m 7240 4364 S    0  0.8   0:00.02 php-cgi
13646 www-data  15   0  143m  18m  12m S    0  2.0   0:00.15 php-cgi
13647 www-data  15   0  144m  21m  14m S    0  2.3   0:00.38 php-cgi
13648 www-data  15   0  143m  25m  19m S    0  2.8   0:00.32 php-cgi
13649 www-data  15   0  143m  18m  12m S    0  2.0   0:00.15 php-cgi
13700 www-data  20   0  137m 7236 4364 S    0  0.8   0:00.02 php-cgi
13730 www-data  15   0  144m  26m  19m S    0  2.8   0:04.91 php-cgi
13731 www-data  15   0  144m  28m  21m S    0  3.1   0:05.11 php-cgi
13732 www-data  15   0  144m  28m  21m S    0  3.1   0:04.92 php-cgi
13736 www-data  15   0  144m  29m  23m S    0  3.2   0:04.97 php-cgi
17557 root      18   0 18004 2052 1428 S    0  0.2   0:00.00 bash
20168 root      16   0 70608 3204 2484 S    0  0.3   0:00.03 sshd
22281 root      18   0 19084 1320 1064 R    0  0.1   0:00.00 top
28592 mysql     17   0  177m  30m 7572 S    0  3.3   0:04.26 mysqld
29985 root      18   0 21072 1012  772 S    0  0.1   0:00.50 cron
30127 root      15   0 49256 1084  540 S    0  0.1   0:00.01 sshd
30362 syslog    15   0 12444  796  604 S    0  0.1   0:00.11 syslogd
30469 nobody    18   0 81428 9644  872 S    0  1.0   0:00.43 memcached
32607 root      18   0 69512 2412  744 S    0  0.3   0:00.71 sendmail-mta

46.4% belongs to lighttpd (doubled since the VPS doubles our reported max RAM)
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.