Re:Running Apache On A Memory-Constrained VPS
by ay on Saturday June 19, 2010 @03:21PM
(#1445185)
To give some factual support to the parent's argument: I run lighttpd+fcgi-lua+redis comfortably on a 128M VPS, which according to my benchmarks is capable of serving between 200 and 400 requests per second on the dynamic page. With about half of the RAM free, still.
Re:Running Apache On A Memory-Constrained VPS
by patio11 on Saturday June 19, 2010 @02:21PM
(#1445082)
A couple of years ago, I would have said "That's wonderful advice because Nginx excels at serving static files and Apache is needed for the dynamic requests", but today only one of these is still true. The technique will certainly still work, though.
If I ever get a few hours to install Nginx and write config files for a few dozen PHP sites (blarg), I'm going to get rid of Apache altogether.
Re:Running Apache On A Memory-Constrained VPS
by bradleyland on Saturday June 19, 2010 @02:58PM
(#1445152)
Core difference: the request processing model. Nginx uses the "hot new" event-loop model. It's a good model, but I find that most people overstate the performance difference and resource usage.
The bigger problem is that Apache comes configured "out of the box" on most distros with a whole slew of options that you probably don't need. Even having said that, most people think that Apache is using more resources than it is. They see all these processes floating around in `top` and they freak out. See my post in the other thread (linked in parent) for more info on that.
Most of the concern is driven by ignorance rather than deep understanding. I can feel the searing burn of Nginx fans' glare, so let me qualify that. YES, Nginx is a fantastic web server. YES, pound-for-pound, it is more resource efficient than Apache. The catch is, if you trim Apache down to do only what you need, the margin between it and Nginx becomes much smaller. If you really know Apache well, then you don't necessarily need to switch to Nginx, just because it's hot and new.
If you don't know Apache well enough to scale it, or if you're really, really tight on resources (you can't afford a 10% bump in VPS RAM), then you should probably learn Nginx straight away, because it's a fantastic web server. Hell, every Apache admin ought to learn Nginx, because you will no doubt learn something in the process.
Re:Running Apache On A Memory-Constrained VPS
by andrewvc on Saturday June 19, 2010 @03:08PM
(#1445164)
The catch is, if you trim Apache down to do only what you need, the margin between it and Nginx becomes much smaller.
While this may possibly be true (and I'm not sure it is for high levels of concurrency), there's a reason why I don't build my own kernels from source anymore, don't run gentoo anymore, and use nginx everywhere I can. It saves valuable time.
Re:Running Apache On A Memory-Constrained VPS
by bradleyland on Saturday June 19, 2010 @03:16PM
(#1445180)
On Debian distros, trimming Apache down amounts to removing everything in mods-enabled and putting back in only what you need. Not exactly rocket science.
Again, I'm not advocating against Nginx. I'm defending the (apparently) commonly held view that Apache is some kind of resource monster that doesn't hold up under load.
Re:Running Apache On A Memory-Constrained VPS
by sirn on Saturday June 19, 2010 @04:07PM
(#1445254)
> The catch is, if you trim Apache down to do only what you need, the margin between it and Nginx becomes much smaller. If you really know Apache well, then you don't necessarily need to switch to Nginx, just because it's hot and new.
Care to elaborate? I used to do that few years ago for static serving, from tuning Min/MaxSpareServers, measuring resource usage and speed of worker/prefork MPMs to strip out all modules to bare minimum and I still can't get the margin between Nginx and Apache to be any close.
Re:Running Apache On A Memory-Constrained VPS
by sirn on Saturday June 19, 2010 @06:01PM
(#1445387)
> The margin by what metric? My Apache processes are less than 500KB each.
Resource usage in high active connections situation. I remembered I got it that low back then, but isn't the number raise by each active connection? 1000*500KB is 500MB. Nginx stays at 3MB.
Re:Running Apache On A Memory-Constrained VPS
by bradleyland on Saturday June 19, 2010 @10:30PM
(#1445747)
Sorry, I deleted the parent because I replied at the wrong tier, but at any rate. Yes, with pre-fork MPM each connection gets its own process [1]. You don't need a 1:1 ratio of process to concurrency though. That's just silly.
Yes, Nginx is more resource frugal (especially RAM), but you can serve a whole lot of visitors with Apache using 30-50 MB of RAM, which isn't prohibitive, depending upon your needs.
To re-state it: I am not claiming that Apache is a better web server than Nginx, and I do think that every Apache admin should look at and understand Nginx, because it's a different beast, and it just might fit your needs better. But I talk to a lot of really ill-informed people who look at the output of `top` and think that each Apache process is consuming something crazy like 17 MB of RAM a piece. This is generating the perception that default answer is to move away from Apache to something else entirely. That's a wrong-headed way of looking at the problem.
1 - The author's suggestion to turn off keep-alive is a good one in memory restricted environments, btw. This prevents long-running connections that tie up memory.
Re:Running Apache On A Memory-Constrained VPS
by Daniel_Newby on Saturday June 19, 2010 @06:15PM
(#1445401)
How are you measuring resource consumption? Memory consumption often includes a lot of shared virtual memory, where multiple Apache threads/processes simultaneously use the same physical memory.
Re:Running Apache On A Memory-Constrained VPS
by jeb on Saturday June 19, 2010 @03:24PM
(#1445193)
I use linode, with Apache installed, since it's the default stack. Would it be a better idea to spend a day or two installing nginx? At the moment, Apache runs okay, is there an advantage to my installing nginx now?
Re:Running Apache On A Memory-Constrained VPS
by uggedal on Saturday June 19, 2010 @02:51PM
(#1445143)
Nginx is single threaded, handeling incoming requests asynchronous. This architecture can scale to several thousand simultaneous requests. Apache on the other hand uses multiple os threads to handle simultaneous requests.
"20 * 60 * 5 = 60k satisfied clients a minute"
Hmm, that's a lot closer to 6k in my mind :-)
Also:
"The throughput of the server went from about 60k requests per second to about 380 requests per second"
The original (incorrect) calculation supposedly took place at 60k per minute, not per second.
Not trying to be a stickler for accuracy, but I feel like it matters when dealing with benchmarks.
http://news.ycombinator.com/item?id=1413446
Different source but same concepts, I'll repeat what I said then.
Takes more than 5 minutes but worth the effort: replace Apache.
Nginx, Lighttpd, Cherokee, Zeus, LiteSpeed, etc. All use far fewer resources.
http://aruljohn.com/info/nginx/
If I ever get a few hours to install Nginx and write config files for a few dozen PHP sites (blarg), I'm going to get rid of Apache altogether.
The bigger problem is that Apache comes configured "out of the box" on most distros with a whole slew of options that you probably don't need. Even having said that, most people think that Apache is using more resources than it is. They see all these processes floating around in `top` and they freak out. See my post in the other thread (linked in parent) for more info on that.
Most of the concern is driven by ignorance rather than deep understanding. I can feel the searing burn of Nginx fans' glare, so let me qualify that. YES, Nginx is a fantastic web server. YES, pound-for-pound, it is more resource efficient than Apache. The catch is, if you trim Apache down to do only what you need, the margin between it and Nginx becomes much smaller. If you really know Apache well, then you don't necessarily need to switch to Nginx, just because it's hot and new.
If you don't know Apache well enough to scale it, or if you're really, really tight on resources (you can't afford a 10% bump in VPS RAM), then you should probably learn Nginx straight away, because it's a fantastic web server. Hell, every Apache admin ought to learn Nginx, because you will no doubt learn something in the process.
While this may possibly be true (and I'm not sure it is for high levels of concurrency), there's a reason why I don't build my own kernels from source anymore, don't run gentoo anymore, and use nginx everywhere I can. It saves valuable time.
Again, I'm not advocating against Nginx. I'm defending the (apparently) commonly held view that Apache is some kind of resource monster that doesn't hold up under load.
Care to elaborate? I used to do that few years ago for static serving, from tuning Min/MaxSpareServers, measuring resource usage and speed of worker/prefork MPMs to strip out all modules to bare minimum and I still can't get the margin between Nginx and Apache to be any close.
Resource usage in high active connections situation. I remembered I got it that low back then, but isn't the number raise by each active connection? 1000*500KB is 500MB. Nginx stays at 3MB.
Yes, Nginx is more resource frugal (especially RAM), but you can serve a whole lot of visitors with Apache using 30-50 MB of RAM, which isn't prohibitive, depending upon your needs.
To re-state it: I am not claiming that Apache is a better web server than Nginx, and I do think that every Apache admin should look at and understand Nginx, because it's a different beast, and it just might fit your needs better. But I talk to a lot of really ill-informed people who look at the output of `top` and think that each Apache process is consuming something crazy like 17 MB of RAM a piece. This is generating the perception that default answer is to move away from Apache to something else entirely. That's a wrong-headed way of looking at the problem.
1 - The author's suggestion to turn off keep-alive is a good one in memory restricted environments, btw. This prevents long-running connections that tie up memory.
What services are you running?
Are you using any Apache specific functionality?
Are you using an Apache module like mod_php, mod_python, etc, to host a webapp?
Do you need to serve more than one type of language through a single httpd server. E.g., a PHP app and a Rails app?
There is no one-size-fits-all web server. It's all dependent upon your specific needs.