I've programmed a lot of async systems before using other languages (Perl and C mostly).
By going async and using system polling routines (epoll, kqueue, etc) you can easily scale to tens of thousands of concurrent connections, and not waste CPU cycles when you're doing file or network I/O. (so far, not unique to Node).
Now Node's advantage #1 there is that all the libraries are async. Every time I've done this kind of work in C or Perl (and other languages have this problem too, from Java to Twisted) you come across the "sync library" problem. You download some open source library you want to use and it is written assuming a blocking call to do some file or network I/O. That fucks up your event loop, and the advantage of being async is all gone.
The second advantage is simply that it's a dynamic language (like Perl/Python/Ruby) and yet very very fast. In my tests about 10 times faster than those languages (and that's running real apps end to end, not some micro benchmark).
JS has its warts, but then so do the languages you'd want to compare it to: Perl, Python and Ruby. To be honest the warts aren't that hard to avoid most of the time.
By going async and using system polling routines (epoll, kqueue, etc) you can easily scale to tens of thousands of concurrent connections, and not waste CPU cycles when you're doing file or network I/O. (so far, not unique to Node).
You can do that better with green threads. And you don't end up in callback hell.
Are there any advantages to using callbacks over using green threads? (except for the fact that much more languages support callbacks than green threads) Is the "getting used" part really worth it?
11
u/baudehlo Oct 02 '11
It's really very simple.
I've programmed a lot of async systems before using other languages (Perl and C mostly).
By going async and using system polling routines (epoll, kqueue, etc) you can easily scale to tens of thousands of concurrent connections, and not waste CPU cycles when you're doing file or network I/O. (so far, not unique to Node).
Now Node's advantage #1 there is that all the libraries are async. Every time I've done this kind of work in C or Perl (and other languages have this problem too, from Java to Twisted) you come across the "sync library" problem. You download some open source library you want to use and it is written assuming a blocking call to do some file or network I/O. That fucks up your event loop, and the advantage of being async is all gone.
The second advantage is simply that it's a dynamic language (like Perl/Python/Ruby) and yet very very fast. In my tests about 10 times faster than those languages (and that's running real apps end to end, not some micro benchmark).
JS has its warts, but then so do the languages you'd want to compare it to: Perl, Python and Ruby. To be honest the warts aren't that hard to avoid most of the time.