Skip to main content

· One min read
Alan

容器内使用 pm2-runtime

示例

ecosystem.config.js
/**
* PM2 使用
* https://pm2.keymetrics.io/docs/usage/application-declaration/
*/
module.exports = {
apps: [{
name: "SPA_Application",
cwd: `${ROOT_DIR}/build`,
script: "serve",
instances: 1,
args: "",
env: {
PM2_SERVE_PORT: 8080,
PM2_SERVE_SPA: "true",
PM2_SERVE_PATH: ".",
PM2_SERVE_HOMEPAGE: './index.html'
},
env_production: {
},
env_development: {
},
max_restarts: 5,
restart_delay: 300_000,
out_file: "spa.log"
}]
}

· 33 min read

原文 Caching Tutorial for Web Authors and Webmasters

This is an informational document. Although technical in nature, it attempts to make the concepts involved understandable and applicable in real-world situations. Because of this, some aspects of the material are simplified or omitted, for the sake of clarity. If you are interested in the minutia of the subject, please explore the References and Further Information at the end.

· 14 min read
Alan

本文转摘自公众号文章: GraphQL实践

随着业务的增长,页面涉及的业务线越来越多, 为了实现一个需求, 需要调用多个接口组合数据, 然后绑定到 UI 组件上. 每个接口返回的数据会有很多字段是不会使用的, 浪费了网络流量. 为了解决该问题, 我们小组引入了 GraphQL 作为 BFF 层, 利用 GraphQL 服务减少网络请求次数, 以及数据裁减能力减少网络响应数据量.

下面简单介绍一下我们组的 GraphQL Node 服务端项目的搭建过程.

· 3 min read

问题

为什么try catch能捕捉await后promise错误? 和执行栈有关系吗?

为什么try catch 中promise的错误catch不了。 await后就可以catch了?

普通函数不能try catch promise,因为其throw error时的执行栈,和try catch它的函数无关了。

而async await能像generate一样在控制执行流,触发时,函数执行栈恢复到 try catch它时的函数执行栈,所以能try catch。

· 18 min read

问题

async/await异步模型是否优于stackful coroutine模型?

这里说的coroutine是stackful的,可以对比js的async/await和fibjs,还有c#的async/await对比go的goroutine。

async/await的优点是不需要为每个coroutine分配单独的栈内存,只需要一个闭包保存状态,避免了内存浪费;在调度上也更加灵活,可以让用户手动调度;另外在实现上也不需要改动虚拟机,只要在语言层面加上generator的支持就可以实现。那么是不是可以认为async/await是一个更好的异步方案呢?