Multi-core HTTP Server with Node.js
developer.yahoo.net
developer.yahoo.net
Every article on this sort of thing seems to just gloss over this part. Why isn't one CPU enough? What is using it? Serving static files certainly won't. Doing simple things won't...
Does anyone have any use cases / experience for when this was the case? :/
edit: Fine downmodding fanboys. I get it. Use whatever you like. Meh
The article mentions that using NodeJS as a simple HTTP proxy with no application logic can sustain only 2100 reqs/s before a 2.5GHz Xeon is maxed out. NodeJS uses CPU more efficiently than other HTTP stacks, but its I/O engine is not infinitely scalable.
That sounds fairly lame to me. Proxying network traffic isn't a CPU heavy operation. Worst case you have to move a few bits of memory around.
That said Node is a programming environment so the question is, when on a multi-core machine (which all DC machines are) how can we scale to use all the cores so we can do much harder stuff.
What about a node system to deal with 100k concurrent long-poll connections? When some of those are active they could be really active, requiring all the cores, etc. There are lots of scenarios in which more compute power is useful.
Networking IO isn't CPU heavy. There's no reason to increase complexity and slow throughput in the hope that more CPUs will help...
Not saying I agree with the design choices (I'm more of a multiple language / "hard and soft layers" person, and I don't care for Javascript), but I think that's the reason.
Racing (ie thread-safe) accept() is a really good way to improve server throughput. Epoll is also awesome for being thread-safe.
This entirely depends on the use cases you have.
Also, the tabs in a browser running many sites are much closer to traditional use of processes. Web application servers running the same codebase on each request seem like a better fit for threads. For one thing, the security model for the two uses of JS are very different.
As for robustness, if doing X will cause a crash and your code does X, then you will just have a bunch of crashing processes rather than just one. How is that better? Wouldn't the real solution be to either stop doing X or fix X so that it doesn't cause a crash?
Sure, but bug-free code doesn't exist and not all crashes happen 100% of the time. If you have a difficult to track down crash bug that happens for some mysterious reason once every 100,000 requests... Would you rather have that resulting in the entire server blowing up or one request-session blowing up?
If you were to do this on Nginx you'd have to write the module in C.
You can't do it on Apache because of Apache's multi-process/thread model.
The fact that you can write a web server in a few lines of easy to understand and maintain Javascript that can handle over 10,000 concurrent connections without breaking a sweat is a breakthrough.
Node.js may do for server applications what Perl did for the Web in the 90's.
I think it's a big mistake to judge based on "number of lines taken to write 'hello world'". It's what happens when you have 20k LOC to maintain and a heap of complexity that matters.
I'm curious how suitable node's callback-centric model is for larger codebases - it's workable for smaller stuff, but can turn into spaghetti code quickly, like CPS code or giving someone elaborate instructions in passive voice. (Of course, relatively autonomous chunks of the system can be moved into their own processes.)
Off and on, I've been working on a similar event loop/async server framework in Lua, and I think Lua's coroutines make the resulting code easier to manage. (No time frame on that yet, btw.)
> If you were to do this on nginx you'd have to write the
> module in C.
You can write a module to glue nginx and V8. Many people've done it. It takes less than 400 lines of code and a lot of it is nginx typical module code. (The problem is more about the lack of nginx online help, perhaps.) > The fact that you can write a web server in a few lines of easy to
> understand and maintain Javascript that can handle over 10,000
> concurrent connections without breaking a sweat is a
> breakthrough.
Yes. But the big performance issue still is hitting the database and disks. There's no point in having a super fast web server if the DB is dog slow like the vast majority of databases out there. Including the NoSQL bunch. They are not fixing the issue of latency vs. scalability vs. reliability. For that they need to address many uncomfortable problems of current hardware architectures. This is the elephant in the room.If your DB is dog slow, you can still handle wildly high concurrency with node. It's just that the user will feel the slowness, and your DB will struggle. But at least your server won't be unable to serve requests while it's waiting for IO.
Of course it's still on the developer to architect their system for success. Node just takes one unnecessary bottleneck out of the equation.
It is so inadequate to use things like JVM or V8 to serve static content.
Btw, is there any cool-web-server project for Flash - yet another artificial blob (or to be more correct - tumour) in an OS? ^_^
And of course there should be some dynamic web server written on PHP! (yes, you can run it standalone)