Fast Vue SSR with Rust and QuickJS

栏目: IT技术 · 发布时间: 4年前

内容简介:An ongoing experiment usingSo far using a thread pool and channels to communicate with the Warp route handler. The goal is to get a full Node-likeNode outperforms QuickJS by a wide margin. Especially with enough cores and memory. However, QuickJS is very s

Fast Vue SSR with Rust and QuickJS

An ongoing experiment using Rust , Warp and QuickJS to server-side render Vue.js applications.

use renderer::RendererPool;
#[tokio::main]
pub async fn main() -> io::Result<()> {
    let pool = Arc::new(Mutex::new(RendererPool::new(64)));
    let renderer = warp::path::full().map(move |path: FullPath| {
        let renderer = Arc::clone(&pool);
        let s = path.as_str().to_string();
        // Currently only passing path to renderer is possible
        // Full Request object is a WIP
        let result = renderer.lock().unwrap().render(s);
        result
    });
    let routes = warp::path::full()
        .and(renderer)
        .map(|_, result| reply::html(result));

So far using a thread pool and channels to communicate with the Warp route handler. The goal is to get a full Node-like IncomingMessage object available as $ssrContext.req . It already includes a /static handler and serves a code-splitted build on the client via Rollup.

Node outperforms QuickJS by a wide margin. Especially with enough cores and memory. However, QuickJS is very small and has very low memory consumption, so running it threaded in a Rust shell makes it possible to have very high throughput using very few resources in comparison.

Inspired by Xinjiang Shao's experiment .

Running

  1. Install Rust .
  2. npm install
  3. npm test

Or npm run build for generating the Rust binary.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

史蒂夫·乔布斯传

史蒂夫·乔布斯传

[美] 沃尔特·艾萨克森 / 管延圻、魏群、余倩、赵萌萌、汤崧 / 中信出版社 / 2011-10-24 / 68.00元

这本乔布斯唯一授权的官方传记,在2011年上半年由美国出版商西蒙舒斯特对外发布出版消息以来,备受全球媒体和业界瞩目,这本书的全球出版日期最终确定为2011年11月21日,简体中文版也将同步上市。 两年多的时间,与乔布斯40多次的面对面倾谈,以及与乔布斯一百多个家庭成员、 朋友、竞争对手、同事的不受限的采访,造就了这本独家传记。 尽管乔布斯给予本书的采访和创作全面的配合,但他对内容从不干......一起来看看 《史蒂夫·乔布斯传》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具