4 ms·
Javascript as a language and ecosystem has evolved quite dramatically during the last years. Its not perfect though: it lacks features and ecosystem is still no
by randiantech 9y ago
Javascript as a language and ecosystem has evolved quite dramatically during the last years. Its not perfect though: it lacks features and ecosystem is still not in the level of maturity of other platforms, but is definitely going in the right direction. Regarding the single threaded server, its an architecture used before JS exists, and used by many other platforms/systems. Just to give you an example, Nginx workers are single threaded.
- johannes1234321 9y agoIn Nginx you're not doing computation, just passing IO thru between file system, external processes (i.e. PHP via fpm) and the network. If Nginx ever is CPU bound there's something bad happening. As I mentioned PHP: In PHP each worker is single threaded, too, but you can scale by having more workers in isolation.
- alayek 9y agoYou've hit the bull's eye! Yes, and you're also not supposed to do much computation in Node JS code. Some addition, subtraction is fine. But Array iteration, JSON encoding-decoding and similar CPU bound tasks could block the event loop. You can perform them asynchronously, or forward the request to some remote service that's better at doing these computations for you and return results (maybe some service written in Python or a database)
- TrickyRick 9y agoWhat computations do you do in a webserver which hosts a REST API? Most of it is simple CRUD connected to a database, possibly with an auth layer on top, which is pretty much what you describe, passing IO through to a database and back.
- falcolas 9y agoCompression, hash computation, regular expression routing lookups, parsing text, building and serializing datastructures, reading and writing caches; I could go on. Sure, JavaScript (and Ruby and Python) are usually fast enough with modern hardware - but we can't pretend there's no cost.
- jdc0589 9y agodeserializing data structures is a great example. JSON.parse is SLOW. all it takes is a bit of bad code that doesn't do any checking of input size/etc... and if an authoritative source starts sending larger payloads than usual, your node process is horked. Granted, that's not a problem remotely specific to node, it just has a bigger effect in a node env.
- flavio81 9y ago> Most of it is simple CRUD connected to a database If my apps were that way, i could have replaced my team with 20 well-fed monkeys.
- tisdy 9y agoHonest related question: Does HN think putting 2-15KB JSON blobs in a Postgres DB running on Docker on a router is a good idea? Oh, and the table stores log data, so there's about 2 million rows after 5 days uptime. What do you think? EDIT: This was not entirely related but it goes to the notion that it seems like a lot of myopic decision-making has somehow become even more acceptable and I would say this leads to dumb situations as above, and Node.
- hyeomans 9y agoI had this same idea until I found about: http://openresty.org/en/ http://openresty.org/en/ https://github.com/Mashape/kong/ https://github.com/Mashape/kong/ Making a full API on nginx via lua sounds crazy but it appears that people do it.
- thehardsphere 9y agoPHP isn't exactly the best alternative to compare node to; it was pretty much designed specifically to live in an Apache request-response cycle. It's not hard for most things to beat it in contexts outside the one it was intended for.
- mattmanser 9y agoI don't think it actually is going in the right direction, they've screwed up loads of things. Things like getter/setters and object initializers. And don't even get me started on Web Workers, which basically seem to be dead on arrival. The Web Workers design is so shockingly bad and not fit for purpose that I don't understand how anyone signed off on it. Some bits of the new js are in the right direction, and those are the things that people talk about and are getting used, but lots of things were definitely not.