Node.js misconceptions?

On node.js page

Almost no function in Node directly performs I / O, so the process never executes blocks. Since nothing is blocking, programmers with fewer experts can develop fast systems.

therefore, if less than a programmer-programmer does something like starting an infinite loop in a callback, does he not kill the system (in the end)?

or, more realistically, someone does something inefficiently, and it takes a lot of time to process requests (say, half a second or something else). It seems that the requirement “block nothing” → “fast systems” is fundamentally wrong.

Can someone explain how in this situation the system will not suffer from performance problems? Looks like it will be ...

+4
source share
2 answers

Basically, your processor is fast. This is insanely fast.

Your memory is crazy too.

Your hard drive is not crazy fast.

Internet is terribly slow (REST, RPC, etc.).

node.js aims for you to constantly load your processor by doing slow events. That is, instead of

var html = download_file_from_slow_internet(url); /* do what-ever-what-ever to that poor HTML */ 

would you do something like

 download_file_from_slow_internet_with_an_awesome_callback(url, function(html) { /* do what-ever-what-ever to that poor HTML */ }); 

Pro-something-something is most likely related to the CPU in terms of what you want to do. Anyone who made the download_file_from_slow_internet_with_an_awesome_callback function has a burden to make sure that it calls your callback at one time.

In your example, an infinite loop is a pure processor. With node.js, it will stop the whole server, which is very bad. So do not write endless loops.

Keep in mind that “less than expert programmer” is relative. An expert programmer knows and understands threads, blocking, conditions, mutex, race conditions. If you do not use multiple threads, you avoid all problems. Well, why were the topics introduced first?

They were introduced in this way because the processors became viciously fast and people noticed that it makes no sense to wait for the IO. That is, you can simultaneously upload your data and process it. Of course, this caused a lot of problems. Most socket libraries have introduced non-blocking IOs to solve this problem for networks, but this has introduced a fundamentally different approach to programming.

You had to use state cars, and state cars were unpleasant and extremely wrong in the hands of lay people. If you've ever worked with low-level socket state systems in C, you know what I'm talking about.

Here node.js comes on a white horse. When using node.js, the state machine is implicitly using closures for callbacks. It is also called continuing transmission.

The idea is that I talk about it and then pass in a function that says: "When you're done, call it." Because JavaScript supports closure, you can pass state and build a state machine implicitly using the language.

node.js, as it stands now, is a great platform for building custom servers and building robust web applications. A good place to create a service between PHP or Ruby and C.

I recommend using it for server prototypes, and if you are worried about JavaScript performance, you can help me with node.ocaml which is far from complete, but makes node.js slow.

+7
source

Just because something written does not mean that it is correct. You must use common sense.

+3
source

All Articles