Well, I read your article about fcgid.
Let's talk about architecture of apache + fcgid and nginx + php-fpm.
fcgid and php-fpm look similar in the way they spawning processes.
Both use preforked processes of php and respawn about 1000 times of running script.
Apache and nginx both use fastcgi to call php from itself.
Hence, the difference is between apache and nginx.
As i know, apache run by default 4 preforked processes and pass request to one of its workers.
fork is the only stable model of apache in linux. http://httpd.apache.org/docs/2.2/mod/event.html - experimental
fork was invited long time ago.
nginx use the method epoll to process request.
Epoll was introduced in 2001 as patch for the kernel.
Now you can use it via libevent.
look at http://kegel.com/c10k.html - well known C10K problem. epoll can solve this problem. fork don't.
Take a look at graph comparing epoll and fork model and you will get your answer.
http://blog.webfaction.com/a-little-holiday-present
We just moving to drupal. Our sites don't have high load, and performance of drupal is acceptable. It's easy to maintain 5-10 sites all installed drupal, than use framework.
So, I can't report benchmark of apache and nginx for drupal.
But I tested both with apache-tools ab.
For static content nginx was 20 times faster than apache. There is no need for memcache and other optimisation for that testcase - when static is less than cache size of hard drive - web server reads files from disk cache.
Apache has only one solution - if you have high load, use one more apache, scale. that's it.
Also, I have tested php - just one script like <? echo "hi"?>.
As i described, both use fastcgi and php, they work similar - there is no optimisation difference. Both can use eaccelerator,memcache,apc etc.
And nginx was faster in that case.
As solution for people that can't live without apache, nginx can work as frontend that process all static and bypass php to backend - apache.
I have read your way to process static content - squid.
This way nginx will run as fast as squid does.
Now take a look at squid. It has great disadvantage. When programs comuunicate each other, they use tcp/ip protocol, squid uses port. This is not effective solution.
IPC work MUCH faster via socket.
I have compared both - socket and port, again, for static content.
socket faster in times (1x-2x-3x?) than port.
Why use port?
Communication between nginx and php-fpm made via socket, so even if static content comparable with squid, php run faster just because of socket.
This is true in the case you have 1 server.
Q: Why nginx is better for static than apache?
A: apache uses prefork, nginx FSM with epoll, nginx uses sendfile() for reply, it's optimized great (compare strace nginx and thttpd - thttpd use more system calls, more calls - more switch context)
Q: Why you need front-end, back-end model?
A: Suppose you have 1000 slow clients. In apache case you have 1000 httpd processes and lot of switch context. Every process eats memory for php. And every process take 0.1 sec to process, 10 sec to reply client.
When you have nginx as front-end it reads continuosly client request, than immediately pass it to apache, it run 0.1 sec and reply to nginx. So you will have only 10 processes of httpd.
Q: why nginx is better than squid?
A: 1. nginx is not just proxy, it reply itself for static content. Also uri can be configured via regexp.
2. nginx is more configurable as it is web-server.
3. nginx uses effective FSM (final state machine) and well optimized for system calls.
nginx is written by 1 !!! person - Igor Sysoev - http://sysoev.ru/nginx/ and it works well.
http://news.netcraft.com/archives/web_server_survey.html
- Apache
- Microsoft
- qq.com - hosting like thttpd
- nginx
Comments
Misunderstanding of Apache
It always bums me out to see comparisons of apache+prefork vs. [insert_webserver_here]. Apache has supported pluggable processing modules since 2000!
When apache 2.0 came out, MPM's other than prefork were not compatible with modules that weren't thread safe, such as mod_perl, mod_php and others. Since many sites were using these modules, they were advised not to use anything other than the Prefork MPM.
The solution to the prefork + mod_php problem is to stop using mod_php, use CGI through fastCGI, and then enable the MPM of your choice. This solution has been available for as long as apache has been available. We've been using apache + event/worker MPMs + fcgid for years without issue.
Sadly, the solution wasn't well understood or heavily utilized by new admins, because they heard that "CGI is slow". As a result, their impression is that "Apache 2 is incompatible with PHP". So everyone starts casting around for an alternative.
The alternative they find? Decoupling static web requests from PHP processes and using CGI. This is the SAME solution addressed by apache 2.0!
Long story short, you're comparing apples to oranges. But Apache also makes apples available, so this is not a fair or informed comparison unless you're comparing nginx to Apache's event MPM. You would also have to disable all of the modules in apache that provide features not supported by nginx (e.g. htaccess support, multiviews, and all of the other LoadModule lines that don't correspond to nginx features)
I would be interested in seeing such results! I wouldn't be surprised if apache was still a little slower, but I doubt it's on the order of 20:1
OK. Let's test it.
It will be not productive host just for develop - AMD X2 5600+ 4G RAM
I will compile on gentoo-2.6.28-r4 amd64 with following modules:
www-servers/apache-2.2.10
USE=""
APACHE2_MPMS="event"
APACHE2_MODULES="actions alias cache deflate dir disk_cache env expires ext_filter file_cache filter headers log_config logio mem_cache mime mime_magic negotiation rewrite vhost_alias"
So, you can see there is no ssl (event doesn't support it) and i skipped auth at all (nginx support it).
Also, www-apache/mod_fcgid-2.2
Is www-apache/mod_fastcgi required for FastCGI?
php would be compiled as
dev-lang/php-5.2.8-r2
USE=""apache2 bzip2 cgi cli crypt ctype curl doc force-cgi-redirect ftp gd-external gdbm iconv imap json mysql mysqli nls pcre postgres readline reflection session soap spell spl truetype unicode xml zlib"
www-servers/nginx-0.6.32
USE="fastcgi pcre perl ssl zlib"
php-fpm patch would ba added and php compiled with the same USE flags except "apache2"
Testcase is the index.php of fresh install drupal 6.10 with no modules for dynamic pages - php.
No optimisation and configuring. Just install and run.
And index.html "It works" for static. Also I will test image file about 60Kb.
php.ini will be default.
Could you help me with configuration files related to apache + fcgid? (worker_processes=2 and worker_connections=8192 for nginx)
I will produce similar to nginx and php-fpm.
I can test in saturday/sunday and 6.04.2009 (monday) report results.
I will use ab with options 1,10,100 of concurrent connections and keep-alive turned on.
10 cases by 100 000 times.
Also I can switch off logging for apache and keep turned on nginx.
No cache, no eaccelerator, no optimisation. MySQL config would be the same for both cases.
Is that clear benchmark?
Is APACHE2_MPMS="event" right? I can test worker - which one would be faster?
And should be "threads" enabled in apache, php?
I have tested nginx with static it produce 20 000+ requests per second for static with small optimization for tcp/ip in sysctl
and increasing number of open files and processes in limits. C10K is easy solved.
Consider any social network with instant messaging. If you have 100 000 users logged in and check new message every minute you will get 100 000 / 60 = 1 600 requests per second.
And 1m in day page views for news site if you have peak in 8 work hours would be 1m/8/60/60 = 35 requests per second.
Even AJAX help in search form would produce more. Google can do this. You can't.
Test from wordpress.com
http://wiki.nginx.org//NginxWhyUseIt
lighttpd vs nginx?
I like lighttpd... though nginx seems more popular. What does nginx have that lighttpd doesn't?
http://httpremix.com
Benchmark for nginx
Jonah!
I don't know what have nginx that lighttpd doesn't.
I'm just heard lighttpd have problem with memory leaks and a little bit slower than nginx.
If you use lighttpd and it works stable I think there is no difference for drupal. May be in other cases, there is some difference.
I have used evhttp simple server from libevent.
It's just replied on every request "Hi there!". Nothing can be faster than that.
And it's works as fast as nginx! Nginx in that case read file from disk "Hi there". I think eventually it reads from disk cache when i performed the test.
When i switched to proxy from nginx to simple evhttp server via tcp/ip port I've got 1600 req/sec instead of 20000. Thus, I don't trust proxy and use sockets when I can. I don't know how to turn on Apache listen on socket. And I don't need front-end back-end model just because of php. php-fpm listen on socket for nginx. That's enough for me.
I have tested nginx with following options:
worker_processes 2;events {
worker_connections 8192;
use epoll;
}
dev box is Gentoo AMD64 X2 5600+, 4G RAM, SATA.
4 cases:
APC - on/off (APC)
Aggressive caching drupal optimization - on/off (AGG)
with benchmark:
ab -c 100 -n 10000 -k http://example.com/ - for Aggressive on
ab -c 100 -n 1000 -k http://example.com/ - for Aggressive off
Here is the results:
as you can see "Aggressive caching" is the most important. I did not tested normal caching as it shows "your modules support that"
And APC with 128M provide 2X boost.
So, 571.77 Requests per second for main page fresh install of drupal-6.10. Ah, I have installed contributed modules, but did not changed main page.
Then I tried to use boost.
I turned on rewrite rules in nginx to support boost and launched
ab -c 100 -n 100000 -k http://example.com/
The result was
Requests per second: 16072.09 [#/sec] (mean)Time per request: 6.222 [ms] (mean)
Time per request: 0.062 [ms] (mean, across all concurrent requests)
Transfer rate: 114654.92 [Kbytes/sec] received
I have tested from the same localhost, so transfer rate has almost reached 1Gbit/sec!
16K requests per second is a great deal!
Then I have tried benchmark for registered user:
ab -c 100 -n 1000 -k -C DRUPAL_UID=1 http://example.com/
And got:
Requests per second: 26.41 [#/sec] (mean)Time per request: 3787.008 [ms] (mean)
Time per request: 37.870 [ms] (mean, across all concurrent requests)
Transfer rate: 192.81 [Kbytes/sec] received
The same as APC turned on, Aggressive cache turned off.
I would like to enable input like comments from anonymous users. Cache for boost is my headache and i don't see any strategies to enable it on news site.
Then I have discovered approach in this forum to do manually wget some pages and make the same rewrite rules.
If I have load about 10-20% for main page, so 3-5 minutes age of main page for anonymous users would be great loadoff.
So I will find those pages, that have load and will wget just these pages to cache. Then cron. The rest of pages, and all site for registered users would have 500+ req/sec instead of 27 when boost is turned on.
I didn't test apache, but if somebody provide me similar config files for fcgid and MPM I can test it.
Also I didn't get the goal of Cacherouter. In my case, if I have 1 server (no cluster) and enabled APC in php, do I need this module?
I can use memcached builtin nginx for static files if I will have I/O problem with SATA. At this time I want to figure out cache-related issues with drupal itself.
Could somebody guide me a reference what is cacherouter for. Or not.
If this module can save "Aggresive cache" of drupal in memory, I think it would be the same as APC on or off - 2X boost!
So, finally it would be 1K+ requests per seconds.
And it sounds great.
Updated:
cachecache_block
cache_content
cache_filter
cache_form
cache_menu
cache_page
cache_update
cache_views
I will try to cache this tables and may be url_alias in memcached and APC.
And report back benchmarks.
Thanks for these benchmarks.
Thanks for these benchmarks.
Cache Router (and Authcache)
Drupal core uses database tables for caching pages, blocks, menus, views, etc. Cache Router allows you to pick another storage mechanism to replace these database tables, like APC or memcached, giving a performance increase and taking the load off MySQL. I'd recommend trying it out.
I recently released a module called Authcache that is built on top of Cache Router and takes advantage of fast page caching (this means the page is retrieved without establishing a database connection). Authcache can cache pages for anonymous and authenticated users, including comment forms. Authcache doesn't do static file caching like Boost, though. For a heavily updated websites, I don't know if it's better to read/write from memory (using APC/memcached) instead of continuously deleting/creating files on the file system using Boost.
I'd be interested in any benchmarks you do with Cache Router or Authcache. I know Boost will beat them out, since serving static files is faster than going through PHP/FastCGI, but it would be interesting to see how it performs against Drupal core.
http://httpremix.com
Thank you for reply Jonah! I
Thank you for reply Jonah!
I will test Cache Router to understand how it works.
Then I will try your module.
I think all further testing should be made with cookie turned on and off - anonymous/registered.
First impressions
Authcache sounds very promising.
How stable this module?
First, I thought about cache size for every user, then i got your info about roles.
If I make admin/editors/moderators and user roles, enable cache just for user it will be great.
And what info in blocks is sent to user from cache? Is it empty or from any user?
Do I have to still manually remove cache to update page?
Your debug on site shows
Authcache.infopage_render: "289.67 ms"page_queries: "74 queries @ 217.09 ms (75%)"
cache_render: "0.64 ms (45,161% increase)"
cache_uid: 0
cache_time: 1238662403
node_author: "guslutharak"
(page_age): "202167 seconds"
HTML/JavaScript time: 157 ms
Authcache.ajaxRequest (sent)q: "node/51"
statistics: 1
Authcache.ajaxRequest (received)db_queries: "5 queries @ 1.23 ms"
HTML/JavaScript time: 395 ms
Is that means 0.64ms+1.23ms on server, and 395ms on client side, instead of 289.67ms on server?
When i posted comment about difference between lighttpd and nginx i remember the case when nginx works fast.
Initially it was developed for rambler.ru one of market-leaders in Russia. And there were written embedded language to combine all data from several servers (news, mail, fun, media etc.) in one page - front-end worked just like Constructor of content.
First were loaded page in that language to server, then made simultaneously subsequent requests to back-end servers for different content, then all merged in one reply to end user. This model works extremely fast.
This is not my case, but this is another approach for your module. If you could split page on common data and user-specific, using something like server-side includes for dynamic pages it will work faster and more stable.
However, I will try your module.
Authcache seems fairly
Authcache seems fairly stable, especially for anonymous users. I've tested it pretty thoroughly on a basic Drupal install. If you use a lot of contributed modules or user-specific blocks, authenticated user caching might get tricky. You'll probably have to add some custom code then.
The "cache_render" is the time it took PHP to retrieve the page from the cache (the only remaining step is sending to the user, afterwards the script ends). Then on the client side, an Ajax request may be performed. This is more resource intensive on the server since the db connection is made and other code is executed. Probably more like 30-50ms. In the case above, the statistics module is enabled, so this step is required, otherwise the anonymous request would only be ~0.64ms total.
The HTML/JavaScript time is just client-side HTML rendering and JavaScript/Ajax execution time. It's not related to what the server would normally do.
If you run into any difficulties with Authcache, please feel free to open an issue on the project page! =)
http://httpremix.com
Here is the stats for
Here is the stats for CacheRouter:
I turned on caching of everything i.e. default engine = APC.
And get results:
ab -c 100 -n 100000 -k -C DRUPAL_UID=1 http://example.com/
Requests per second: 1449.99 [#/sec] (mean)Time per request: 68.966 [ms] (mean)
Time per request: 0.690 [ms] (mean, across all concurrent requests)
Transfer rate: 10359.49 [Kbytes/sec] received
At this time 1450 requests/second is more then enough for my instance.
For REAL test i need more nodes and test several pages with Views, CCK etc.
Count the size of Cache tables and decide which one worth to be in memory.
I think there is no great difference between APC and memcache, +/- 10% is OK.
Although I've got fragmentation 2% when used APC for system and user cache.
We are local news agency and moving to drupal.
When i finish import of 150 000 articles and 36 000 photos to drupal, I will come back and report REAL stats.
Now if I have 1500+ req/sec on production server for page and possibility to loadoff several pages by wget and rewrite rules for anonymous users with transfer speed 15 000+ req/sec there is nothing I should worry about.
cacherouter apc сaveats
Don't forget about lock-problem in cacherouter so dont put all cache tables to one backend til it fixed
More preferable to have 1 memcache instance (not shared) per cache-table http://drupal.org/node/245341
Biggest difference
nginx is written by 1 !!! person - Igor Sysoev - http://sysoev.ru/nginx/ and it works well.
I've had some good experiences w/nginex, but the above is the single biggest reason why I don't recommend it for high-availability deployments. Igor is obviously a gifted engineer, and his very responsive to requests and bug reports from what I can see. However, if he gets hit by a bus...
http://www.chapterthree.com | http://www.outlandishjosh.com
https://pantheon.io | http://www.chapterthree.com | https://www.outlandishjosh.com
Yes - nginx is writen by 1
Yes - nginx is writen by 1 person but please don`t forget - we are russians :)
Good luck with a bus :)
If the bus happens, you can
If the bus happens, you can always fork the code. http://tengine.taobao.org/