npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

grace-server

v1.1.63

Published

通过cluster集群,加强node服务器的稳定性

Downloads

25

Readme

grace-server


通过cluster集群,加强node服务器的稳定性

为什么(WHY)

由于node服务器上线有损,所以使用cluster实现无损上线。

原理(HOW)

img img img

使用(HOW TO USE)

  • 安装
npm i -g grace-server
  • 使用
    1、首先进行配置
    新建grace-config.js配置文件,格式如下:
module.exports = {
    entry: './index.js',                // server入口文件
    workerNum: 2,                       // cluster集群worker数量
    graceReloadOnFileChange: true,      // 监听文件修改时,进行平滑重启服务器
    reloadDelay: 1500,                  // worker重启延时,注意,在产品模式下,延时尽量大于1.5s,如果延时过小,会发生worker重启交叉,开发模式可以将性能考虑优先,发生重启交叉的情况不会有很大影响,所以可以设置小于1.5s。
    workerTimeOut: 5000                 // worker强制退出timeOut
};

2、server端入口app.js需要将server对象暴露出来

// app.js
var server = http.createServer((req, res) => {
    response.end('hello');
});
server.listen(8080);
// 将server对象导出
module.exports = server;

3、当想要上线时:

将server代码替换
使用kill进行平滑重启

kill pid

如果pid不清楚的话
可以使用ps进行查询

ps -A | grep grace
  • 查看版本
grace -v
  • 运行
grace

目录

|-- workPlace
    |-- .gitignore
    |-- README.md
    |-- index.js
    |-- package-lock.json
    |-- package.json
    |-- tree.md
    |-- img
    |   |-- entry.jpg
    |   |-- how.png
    |   |-- how2.png
    |-- src
        |-- command
        |   |-- argReader.js
        |   |-- index.js
        |   |-- showConfig.js
        |   |-- socket.js
        |   |-- start.js
        |   |-- stop.js
        |-- grace
        |   |-- index.js
        |   |-- master.js
        |   |-- readConfig.js
        |   |-- singnal.js
        |   |-- socket.js
        |   |-- task.js
        |   |-- work.js
        |-- util
            |-- log.js
            |-- util.js

版本更新

  • v1.1.70
    1、使用spawn添加后台常驻能力
    2、使用socket添加通信能力
    3、添加进程守护monitor
  • v1.1.62
    上传原理图
  • v1.1.61
    优化目录结构
  • v1.1.6
    优化目录结构 完善package.json信息
  • v1.1.5
    新增graceReloadOnFileChange
    通过监听本地文件,在文件修改时,进行平滑重启 新增reloadDelay
    设置worker重启延时 新增workerTimeOut 设置worker重启时强制离线timeOut
  • v1.1.4
    优化目录结构,将task任务管理进行抽象。
  • v1.1.0
    调整文件目录
  • v1.0.0
    新增grace命令。
grace index.js

使用集群方式来启动server服务。