Fast Vue SSR with Rust and QuickJS
github.com
github.com
The appeal is that it supports most of ES2019 while being a easy to build, light weight dependency that can be embedded into Rust applications. [1]
Would I use something like this for a production service with a high traffic volume? It would be nice to see benchmarks, but most likely not.
But if you have a Rust backend and want a simple way to do SSR without having to operate a separate Node service or linking v8, this might be a neat approach.
ps: It would be nice to run QuickJS in a WASM runtime, while still offering the same convenient API surface for Rust. This would provide sandboxing for the QuickJS C code. It's is in my backlog, I might get to it eventually. [2]
Not sure if it helps, but I did that some time ago, with minor QuickJS patching: https://github.com/saghul/wasi-lab/tree/master/qjs-wasi
- Rust: 20k requests in 10.04s
- Node: 4k requests in 10.11s
Tested with `autocannon http://localhost:3030`.
Running multiple Node processes will beat it for sure.
But then you're using a lot more memory and CPU, I think.
Also, a single process can consume just as much CPU as multiple processes, so the efficiency isn't obvious unless you measure user time.
This is highly experimental, just a proof-of-concept so far. Security issues need to be reviewed and addressed for sure.
with that perhaps you could spawn node to all threads and do even better in terms performance/memory?
- The Warp handlers are blocked by the use of thread-blocking synchronization primitives (locks, channels) - which might harm performance and can even lead to deadlocks.
- The architecture with "passing work off to a threadpool via a chnanel and waiting for it to complete" is not very resilient, and prone to behave badly under high load. The reason is basically the inifinite queuing - if new requests come in faster than previous ones can be processed the queue length (and thereby the memory footprint of the app) will grow and grow. At some point the application will just be busy serving old queued up requests, which might already have timed out on the client side and potentially even being retried. That's a vicious circle, and you can only get out ot it by shutting down the app. One way to fix this is to limit the queue/channel size and perform load-shedding on requests which can not be enqueued.
Maybe Deno is hard to invoke from Rust Code.
I can easily see why one would go with QuickJS: it’ll be much quicker to get going.
Didn’t expect such a trivial thing to be in front of HN, but probably Rust marketing and evangelist are all on HN waiting to move them to top.
Stil waiting for good library in rust not dependent on C or unsafe code. Looking at most of the cargo libraries most good one’s are a wrapper around C or C++ library or use unsafe code.
There is no community goal or plan to do away with unsafe. Until we have an easy to use fully dependent and linearly typed language, there will be some degree of unsafety. Even if Idris 3 and ATS 4 come out with magical proof inference, we will assert many more complicated proofs.
This is the precise reason, Rust is a decade or two away from being a useful replacement for C/C++ like other contending systems programming language like go and Swift which are at present more popular than Rust for writing systems program for networking, servers and controlling Apple hardware directly.
Mozilla, Microsoft, Amazon, Apple and other's investments in Rust, clearly demonstrate the value of writing new systems software in Rust, alongside and inside existing C/C++ code bases. Rust is clearly monetarily useful, despite not being a systems programing panacea.
Rust evangelist promote Rust as replacement for C and frown upon anyone who has a contrary view including direct attack on those opinion.
Rust has a value like other programming languages and not a panacea As you said, it’s just not a C replacement for another decade or two or may be never.
(Three letter acronyms before anyone accuses me of hypocrisy)