tag:blogger.com,1999:blog-1610041778732887994.post1004179434301193019..comments2023-07-21T09:16:48.778-07:00Comments on Levent Serinol's Blog: speeding up your nginx server with memcachedAnonymoushttp://www.blogger.com/profile/06161379979453710759noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-1610041778732887994.post-62932642412314655542010-12-01T20:31:11.350-08:002010-12-01T20:31:11.350-08:00@Adam
How do you test?
"9000 requests a se...@Adam <br /><br />How do you test?<br /><br />"9000 requests a second from the static image file."<br />Is the 9000 requests for the same file?<br />If so, nginx should cache everything in memory, thus it's very fast.<br /><br />However, the real world scenario is very different.<br /><br />Try benchmark a large number(more than 10K) of img path, you should have a different result.Wuvisthttps://www.blogger.com/profile/14060598574587767368noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-30450565565719011362010-10-14T23:10:36.307-07:002010-10-14T23:10:36.307-07:00What about Last-Modified header? In the example yo...What about Last-Modified header? In the example you have a hard-coded value for Last-Modified. How do we configure this to be set dynamically?<br /><br />nginx sets the Last-Modified header automatically when it handles the request itself but when the request is passed to memcached, this header is not included in the HTTP response.Sid Ahujanoreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-89828102729495621592010-10-10T09:41:04.609-07:002010-10-10T09:41:04.609-07:00nginx + fastcgi definitely isn't "slower&...nginx + fastcgi definitely isn't "slower" than apache + mod_php, or even apache + fastcgi.<br /><br />Performance can be gauged in so many ways too, e.g. execution time, resource usage per request, concurrent requests and so on.<br /><br />I use the Symfony framework. Every request that goes via ANY framework has a very large overhead (due to the sheer number of classes and files involved in the request), and in my experience, execution times are quicker (albeit marginally) with nginx + fastcgi when compared to Apache. The big benefit you get with nginx + fastcgi is concurrency. In my experience, the nginx+fastcgi combo is capable of handling so many more concurrent requests with a lower overhead than even the most tuned Apache server.Ben Lancasterhttps://www.blogger.com/profile/00978574653361626925noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-18420570611298481062010-03-24T18:26:19.422-07:002010-03-24T18:26:19.422-07:00Hi!
Do you think using memcache for storing nginx...Hi!<br /><br />Do you think using memcache for storing nginx cache is better somehow than having nginx cache dir in tmpfs volume?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-64880122368925042542009-09-08T21:16:38.961-07:002009-09-08T21:16:38.961-07:00Levent, Great article.
I am setting up a nginx f...Levent, Great article. <br /><br />I am setting up a nginx frontend to multiple apache backends to have a high available setup. I used your howto and it is working great.<br /><br />Yet to test things with, I tried to use the php script to query images into memcached, but its not returning anything in cache. I am able to test memcache with simple scripts and it is returning, but not yours. It runs fine, or seems to. Can you give me any insight on what it could be?<br />MichaelAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-47790725157078672972009-09-08T11:50:40.906-07:002009-09-08T11:50:40.906-07:00Thank you for this article, with a minor tweak thi...Thank you for this article, with a minor tweak this has worked really quite well. It certainly makes a difference on marginal hardware or network based storage. Tests are showing a real improvement in load times.Unknownhttps://www.blogger.com/profile/03035992784948210861noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-68646330751469967022009-08-11T22:52:43.707-07:002009-08-11T22:52:43.707-07:00I could serve about 9000 requests a second from th...I could serve about 9000 requests a second from the static image file. Now that it is in memcached, I can only serve 2500 a second. Should work great for content, but not for static files I don't think.Adamhttps://www.blogger.com/profile/15910564501246265686noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-85145723993385413602009-07-27T13:17:43.285-07:002009-07-27T13:17:43.285-07:00memcache_pass is part of, but not the complete pic...memcache_pass is part of, but not the complete picture.<br /><br />memcache_next_upstream is the option you are looking for, I think. I our environment, we use a valid upstream name in the memcache_pass directive, and defined what to do if the data is not found. <br />ex. of conf<br />upstream memcache {<br /> server x.x.x.x:11211;<br /> server x.x.x.x:11211;<br /> server x.x.x.x:11211;<br />}<br />(normal config options)<br />memcached_next_upstream not_found;<br />memcached_pass www3.memcache;<br /><br />With this config, if nginx gets a 'not_found' response from memcache, it will try the next server in the upstream config, and continue until found or out of upstreams, at which point we hand it back to apache, which handles the rest of the communication with the customer.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-61896852381278985092009-06-08T08:39:13.460-07:002009-06-08T08:39:13.460-07:00Hi Levent,
Thank you for this great explanation.
...Hi Levent,<br />Thank you for this great explanation.<br /><br />As Rense,I want to know if it's possible to configure nginx with a memcached cluster (memcached or nginx memcache)?<br /><br />Configuring nginx 'memcached_pass' with several memcached IP is not the solution because memcache pairs (key/value) are not distributed between all memcache daemons. It seems they act as a backup if the first daemon failed.<br /><br />Am i right ?<br /><br />Thank you for your help.<br />MyxansAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-46406653975490765252009-06-05T10:26:26.559-07:002009-06-05T10:26:26.559-07:00Hi,
I want to try out this configuration because ...Hi,<br /><br />I want to try out this configuration because I manage a high volume dynamic site with a lot of PHP in it. <br /><br />I have a couple of questions though: <br /><br />- I probably need more then 1 nginx memcache, is this possible and if so, how does this affect the configuration scripts? Can I just let my loadbalancer do layer-4 leased connections loadbalancing over the NGINX instances?<br /><br />- What is the ration of NGINX to Apache?<br /><br />- Most of my traffic is SSL, where does that fit in? Do I need to terminate that in NGINX first before I can pass anything to the backend? (and how will it return?).<br /><br />Thanks a lot, great article btw :)<br /><br />RensUnknownhttps://www.blogger.com/profile/09303500528719703346noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-66449253237745901732009-05-05T23:54:00.000-07:002009-05-05T23:54:00.000-07:00Try your test with a huge php application and comp...Try your test with a huge php application and compare nginx+fcgi+php with apache+mod_php by sending many concurrent connections. When you reach you're pre defined fast-cgi's max process limit , nginx will begin to slow down.This is not a problem of nginx, it's the problem of fcgi implementation. Of course, nginx is faster than apache and lightweight on resources. But fast-cgi is a bottleneck for nginx.Anonymoushttps://www.blogger.com/profile/06161379979453710759noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-59502170439515969902009-05-05T15:47:00.000-07:002009-05-05T15:47:00.000-07:00I would like to see some results on the claim that...I would like to see some results on the claim that nginx+fastcgi is slower then apache+mod*. <br /><br />In my benchmarks, I've used a small ec2 instance and ran nginx+fastcgi and apache+fastcgi and apache+modperl. The application code functionality was. <br /><br />nginx+fastcgi: 91 reqs/s<br />apache+fastcgi: 90 reqs/s<br />apache+modperl: 84 reqs/s<br /><br />Plus the main benefit of not embedding your application code in the apache process (mod_perl/mod_php/mod_python) is that you create a tiered architecture. This allows you to accept/route connections without having to tie up the application and its large memory footprint. <br /><br />For instance in mod_* if a slow connection makes a request the apache thread (big memory footprint) is tied up for the entire length of the connection. In fastcgi land a slow connection will first hit nginx which proxies the request to fascgi which will process the request (fast) and send the result back to nginx which will being to stream the data back to the requester. While nginx is doing that the fastcgi process is able to handle other requests.Jasonhttps://www.blogger.com/profile/17224484272547860441noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-46270292096795188752009-04-20T23:58:00.000-07:002009-04-20T23:58:00.000-07:00Nginx is using fcgi method which is slow. You can ...Nginx is using fcgi method which is slow. You can see the difference by testing Apache and Nginx with big php codes and high concurrency. For better performance on nginx, it looks like many pre-forked php-cgi's needed.If you're serving php static content or have a chance to cache your php files html output for a certain time then you can run nginx server as front end server with proxy module and apache with mod_php as backend server. So, you can cache html output of your php files.On static content like image and html, Nginx is superior to Apache. Nginx is lightweight, faster and more resource friendly than Apache.Anonymoushttps://www.blogger.com/profile/06161379979453710759noreply@blogger.comtag:blogger.com,1999:blog-1610041778732887994.post-34945675301241268292009-04-20T07:39:00.000-07:002009-04-20T07:39:00.000-07:00You make it sound in the beginning of your post th...You make it sound in the beginning of your post that serving plain PHP over NGINX is slower than serving plain PHP over APACHE ... is that correct? <br /><br />If so, why?Anonymousnoreply@blogger.com