News for hackers. Stuff that matters.
Re:JavaScript is Eating the World by randiantech on Thursday August 24, 2017 @09:26AM (#15089871)
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.
Re:JavaScript is Eating the World by johannes1234321 on Thursday August 24, 2017 @09:34AM (#15089945)
In 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.

Re:JavaScript is Eating the World by alayek on Thursday August 24, 2017 @09:38AM (#15089985)
You'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)

Re:JavaScript is Eating the World by TrickyRick on Thursday August 24, 2017 @09:47AM (#15090055)
What 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.
Re:JavaScript is Eating the World by falcolas on Thursday August 24, 2017 @09:57AM (#15090129)
Compression, 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.

Re:JavaScript is Eating the World by jdc0589 on Thursday August 24, 2017 @10:53AM (#15090557)
deserializing 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.
Re:JavaScript is Eating the World by flavio81 on Thursday August 24, 2017 @10:56AM (#15090589)
> 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.

Re:JavaScript is Eating the World by tisdy on Friday August 25, 2017 @12:08AM (#15096050)
Honest 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.

Re:JavaScript is Eating the World by hyeomans on Thursday August 24, 2017 @12:00PM (#15091199)
I had this same idea until I found about: http://openresty.org/en/ https://github.com/Mashape/kong/

Making a full API on nginx via lua sounds crazy but it appears that people do it.

Re:JavaScript is Eating the World by thehardsphere on Thursday August 24, 2017 @02:54PM (#15092911)
PHP 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.
Re:JavaScript is Eating the World by mattmanser on Thursday August 24, 2017 @11:54AM (#15091140)
I 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.