News for hackers. Stuff that matters.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by austincheney on Sunday March 03, 2019 @11:17AM (#19295165)
> This entire article is a pretty damning report on JavaScript in general

How so?

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @11:24AM (#19295194)
A team that likely has lots of JavaScript expertise basically stated that JavaScript is unsuitable for their task.

And that the operational improvement once written in Rust was notable enough to write a paper.

Imagine the K8S team porting from Go to some other language for similar reasons.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by derefr on Sunday March 03, 2019 @11:54AM (#19295375)
Does every language have to be suitable for every task? “Operating a business-logic-embedding CDN at scale” isn’t ever something Node claimed to be capable of. I wouldn’t expect any other dynamic runtime-garbage-collected language, e.g. Ruby or Python or PHP, to be suited to that use-case either.

Use the right tool for the job. The PHP website is running PHP, but it isn’t running a web server written in PHP. Web servers are system software; PHP isn’t for writing system software. Same thing applies here. Node does fine with business logic, but isn’t really architecturally suited to serving the “data layer” when you have control/data separation.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by kbenson on Sunday March 03, 2019 @05:14PM (#19297271)
> The PHP website is running PHP, but it isn’t running a web server written in PHP.

Are you sure? I'm not familiar with the PHP.net architecture, and there may be less gains from how PHP has traditionally tied itself as a module to web servers in the past, but Rails (and any number of other dynamic language frameworks) are actually web servers implemented in that language, with an optional separate web server such as NGINX or Apache you can run in front to handle the stuff they aren't as good at (static file serving, etc).

Now, that is a framework, and not the language proper, but I wouldn't be all that surprised to find python.org running on top of a Python framework.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @06:11PM (#19297522)
Their mirroring page suggests they most likely use Apache.

"NOTE: Some of our maintainers prefer to use web servers other than Apache, such as Nginx. While this is permitted (as long as everything ultimately works as directed), we do not officially support these setups at this time"

http://php.net/mirroring.php

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by cferr on Tuesday March 05, 2019 @05:24PM (#19314833)
Seems Python.org runs on the Django framework.

https://github.com/python/pythondotorg/network/dependencies

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @12:07PM (#19295459)
From the paper it appears to be an authorization service that decides what rights a particular user has. Not a webserver or CDN. It mentions it being CPU bound, though it isn't clear to me why it would be, or why JS wouldn't work well enough for that.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Quenty on Sunday March 03, 2019 @12:26PM (#19295578)
The paper makes it clear they were evaluating languages based upon efficiency.

The rust implementation was more efficient than the JS one. A CPU bound service of course is bottlenecked at the CPU, and this benefits from efficiency.

At scale, it makes sense to replace this with Rust. Javascript did the job, but did not provide the same efficiency as Rust.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @12:41PM (#19295654)
I'm not clear on why this is particularly CPU heavy, though: "the authorization service that determines whether a user is allowed to, say, publish a particular package"
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Filligree on Sunday March 03, 2019 @01:26PM (#19295916)
Lots of users. Anything will be CPU-heavy if you give it enough work.

Except the things that end up being memory-bound instead, but the NPM database isn't large enough for that.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Dylan16807 on Sunday March 03, 2019 @02:29PM (#19296300)
> Anything will be CPU-heavy if you give it enough work.

Not in a relative sense. If authorization is 5% of the work, scaling it leaves it at 5% of the work, and it's never a bottleneck. Authorization was being a significant bottleneck, not a tiny percent, and that is somewhat surprising.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by andy_ppp on Sunday March 03, 2019 @03:10PM (#19296524)
Obviously authorisation will be a huge overhead compared to sendfile + nginx right? Am I misunderstanding what npm does?
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Dylan16807 on Sunday March 03, 2019 @05:34PM (#19297378)
I mean, to use sendfile you need to open the file, and that does a permission check too...
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by andy_ppp on Sunday March 03, 2019 @09:54PM (#19298444)
No I'm talking about private NPM right. The perms on the file system are not equal to (or as costly as) the auth I need to have to access my private NPM repo.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by yawaramin on Sunday March 03, 2019 @03:39PM (#19296701)
Couldn't you implement the authorization logic in, say, Redis? Then the npm service is I/O-bound again, and everyone is doing the job they're optimized for.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Filligree on Monday March 04, 2019 @09:10AM (#19301319)
Authorization checks aren't that expensive. The overhead of using an external service might well make it take up more hardware overall.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Thaxll on Sunday March 03, 2019 @01:59PM (#19296112)
It's not clear either, it makes sens to use Rust for CPU heavy task, but a CRUD service that do authentication would be fine in Nodejs since every low level crypto are using C. So I'm not sure exatly what they mean, tbh the paper is very light on details.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by nwlieb on Sunday March 03, 2019 @02:50PM (#19296407)
Some CPU heavy operations like crypto are not put in a threadpool. While it may be running C code, it will block the main thread while executing. See https://github.com/nodejs/node/issues/678

Perhaps the new worker threads may alleviate this, but I'm not sure (it's still an experimental API).

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by throwaway66666 on Sunday March 03, 2019 @05:18PM (#19297296)
My gut feeling is that the user keys are not random generated, but actually encrypted strings that contain the permission values. Decrypting them with modern encryption algorithms (like ChaCha) is pretty CPU intensive.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by 0815test on Sunday March 03, 2019 @12:43PM (#19295666)
"Javascript did the job", but not very well apparently. They specifically say that they "were able to forget about the Rust service because it caused so few operational issues". Add to that the increased CPU- and RAM-efficiency that generally comes with a rust implementation, and that rust rewrite looks like a no-brainer.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Outpox on Sunday March 03, 2019 @12:24PM (#19295565)
Well I'd say that if it's an authorization service there will be cryptographic calculation which is "heavy" on the CPU.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @12:39PM (#19295644)
I don't think that's what it does. "the authorization service that determines whether a user is allowed to, say, publish a particular package"

Also, I would assume any crypto in v8 is already written in C, with JS calling into it.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by throwaway66666 on Sunday March 03, 2019 @10:54PM (#19298643)
Users who suggest cryptography are getting downvoted (myself included). I am curious as to why. Is it perceived as spam or an attack on nodejs? Encrypted cookies and JWT (json web tokens) rely on a similar strategy so this is pretty standard. It would be pretty secure as long as the encryption key is not unique, so definitely not criticism on the NPM team but mere theories as to why a (what one would assume is a) database or memory bottle-neck is being presented as a CPU bottleneck in this scenario.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by austincheney on Sunday March 03, 2019 @11:32AM (#19295237)
I guess I just don't see it. NPM is a massive infrastructure where one little piece was rewritten in Rust and then the Rust team wrote a promotional paper about it. The paper isn't bad, but it also isn't a technical white paper.

I don't see how any of this is critical of JavaScript, which isn't even really discussed in the paper and still runs the rest of the infrastructure. If anything the paper is more damning of C, C++, and Java but I still think damning is far too extreme to describe what the paper said.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by johannes1234321 on Sunday March 03, 2019 @12:06PM (#19295449)
> If anything the paper is more damning of C, C++

I don't see it as damning on either of these. On C++ it says "we didn't want to learn it." Which is fine. Maybe after learning they would have decided different, or not. On Java they said "we didn't want to learn how to operate it" as they feared the complexity of an Java application server for a single small service, which they can create in a way which hooks into their monitoring infrastructure. No damning their either.

However their company's purpose is to push Javascript and they are saying "operating JavaScript is hard, doing this in Rust is easy" which directly goes against their business.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by austincheney on Sunday March 03, 2019 @12:41PM (#19295655)
I think you and I read completely different papers. I didn’t see anything about not wanting to learn or motivations of easy.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by IsaacSchlueter on Sunday March 03, 2019 @02:40PM (#19296346)
I mean, we still write the overwhelming majority of our code in JavaScript. We port to Rust when CPU-heavy task becomes a bottleneck to the rest of the system. It's not as if this paper is saying (nor is it the case) that we've ported the whole registry to Rust. JS has lots of advantages we appreciate.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @05:04PM (#19297220)
I'm curious why this authorization service is CPU intensive. The article says it's basically deciding if you're authorized to publish a package. It sounds like the sort of thing that would talk to a database, or a cache like redis, and therefore mostly be IO bound itself.

Is this maybe parsing data structures itself?

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by IsaacSchlueter on Sunday March 03, 2019 @07:36PM (#19297936)
It's been a few years since I was directly involved in engineering, but my fairly educated understanding is that it's more around reading of possibly-private packages than publishing.

Publishing is a relatively rare event compared with reading, but in a world of private packages, orgs, and teams, the "can {user} read {object}" gets more complicated. It probably wouldn't be CPU bound if not for the sheer scale we're dealing with, but once all the IO bottlenecks are resolved, you still have to check to make sure that a login token is valid, then get the user associated with it, then check the teams/orgs/users with access to a thing (which might be public, in which case, the problem is a lot simpler, but you still have to get that info and check it), and then whether the user is in any of those groups. So there's a straightforward but relevant bit of CPU work to be done, and that's where Rust shines.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by CamouflagedKiwi on Sunday March 03, 2019 @12:09PM (#19295476)
> Imagine the K8S team porting from Go to some other language for similar reasons.

k8s was originally written in Java, so they have already done this once.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @12:23PM (#19295555)
I didn't know that, but it makes it a more interesting comparison. I imagine at least part of rewriting it in Go was to "eat your own dogfood".
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by pjmlp on Sunday March 03, 2019 @12:42PM (#19295660)
Actually it was more like "new team got in charge" actually.

There is a FOSDEM 2019 talk about it.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @12:53PM (#19295711)
Thanks! The talk:

"The clusterfuck hidden in the Kubernetes code base" https://fosdem.org/2019/schedule/event/kubernetesclusterfuck...

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by patrec on Sunday March 03, 2019 @01:55PM (#19296086)
One wonders if there'll be a similar talk in a year...

> The audience walks away feeling empathetic that they aren’t alone in their journey to writing idiomatic Go and is now equipped with strong refactoring techniques developed by some of the world’s top engineers for the Kuberentes project.

As an occasional user of kubernetes, minikube etc. it's not something I would have guessed to have been developed by the word's top engineers.

I mean kubernetes tries to, and probably manages to provide an useful abstraction, but at a few million LOC and a few man-month of full time senior engineering effort to run anything in production it's not exactly a epitome of elegant and efficient engineering.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by pjmlp on Sunday March 03, 2019 @02:35PM (#19296320)
You would be surprised at the quality of Android tooling stable releases, to the point that now there is Project Marble in place to try to improve its image.

https://adtmag.com/articles/2019/01/17/project-marble.aspx

If you want to have some reading fun, check /r/androiddev/ every time there is a "stable" release.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by patrec on Sunday March 03, 2019 @03:21PM (#19296591)
Even people working for Google on Android tell me the tooling is pretty garbage, so I'm less surprised than you might think ;)

The interesting thing with Kubernetes is that it's basically a re-imagining of Borg, which one assumes was not a few million lines of code when it was already running all of Googles infra more than a decade ago. It's obviously not solving the exactly same problem (e.g. Google correctly recognized that DNS isn't so hot and wrote their own replacement protocol, BNS which wouldn't fly for external adoption etc.). But I'd be curious to know how Borg's code quality and size back when it became the standard way to run stuff at Google maybe 12 years ago compares to Kubernetes today.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @02:38PM (#19296332)
I bet k8s would look different if it were written by developers used to a more limited set of cpu, io, and memory resources.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by pjmlp on Sunday March 03, 2019 @02:49PM (#19296397)
Well, given the hops one has to go through for the privilege to work at Google, another level of code quality is to be expected.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tannhaeuser on Sunday March 03, 2019 @01:46PM (#19296030)
Wow. Didn't realize it was that bad:

> We look at what it would take to begin undoing the spaghetti code that is the various Kubernetes binaries

Well at least the developers are being frank about it I guess.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by CamouflagedKiwi on Sunday March 03, 2019 @02:43PM (#19296366)
My guess would be more on the side of native binaries (i.e. no runtime JVM dep) and lower memory use, but could be that too.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by zinclozenge on Sunday March 03, 2019 @01:11PM (#19295830)
The k8s team probably should, judging from the state of their codebase.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by steveklabnik on Sunday March 03, 2019 @01:13PM (#19295846)
I’m interested to see what becomes of https://www.cloudatomiclab.com/rustyk8s/
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by zinclozenge on Monday March 04, 2019 @11:18AM (#19302347)
I'd kill for a rust client with feature parity. Writing k8s operators in rust would be so much better.
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by tyingq on Sunday March 03, 2019 @01:19PM (#19295876)
If you feel that way, this is pretty funny then: https://news.ycombinator.com/item?id=19295841
Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by Thaxll on Sunday March 03, 2019 @02:06PM (#19296163)
Easy to criticize a projects that has x millions line of codes.

Every projects of that scale are going to have issues.

Re:Case Study: Npm uses Rust for its CPU-bound bottlenecks [... by zinclozenge on Monday March 04, 2019 @11:14AM (#19302315)
There's a lot of circumstantial evidence suggesting that efforts to refactor the codebase were torpedoed because of developer elitism.