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 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-cluster

v0.1.18

Published

A graceful node library to contribute a permanent "master-worker" server.

Downloads

96

Readme

特性

node-cluster 是一个简单易用的 NodeJS 类库,帮助开发人员快速地搭建基于NodeJS的服务程序:

  • 基于master + worker 模式,能够有效利用多核处理器;
  • 支持多端口监听,master 传递请求端的 socket fd 给各个 worker,性能损失极低;
  • 同一端口下的多个worker之间提供简单的负载均衡支持;
  • 支持对 worker 进程数的监控,支持单个 worker 根据已处理的请求数自动消亡;
  • 支持 master 和 worker 的平滑重启,不丢失请求.

使用

demo目录下提供了一个典型的示例,你可以通过下列命令启动这个服务:

$ nohup node demo/main.js &

其中:

  • main.js 是master进程,通过 register 方法注册 worker进程,并通过 dispatch 进行工作; 除此之外,master 进程不需要做任何工作,你就可以实现一个高稳定性的生产服务;
  • worker/admin.js 提供了监听在 33749 端口上的 HTTP 服务; 通过NodeJS 原生的http模块实现,demo中仅提供了 hello world的示例;
  • worker/api.js 提供监听在 8080 端口上的Socket应答服务.

原理

请参考我的同事windyrobin的这篇文章: http://club.cnodejs.org/topic/4f16442ccae1f4aa27001081 本文的 node-cluster 在核心功能的实现原理上没有任何新意,只是对代码的组织做了更友好的封装,同时加入了一些基于稳定性考虑的特性.

性能

我只能说, node-cluster不会让你失望. 你可以拿 demo 程序实际压测一下,33749端口,开一个worker; 然后拿来和用NodeJS原生的http模块构造的服务进行对比.

注意

  • worker 进程中的 remain 变量,是判断一个 worker 是否空闲的依据; 因此我强烈建议在你的应用程序 worker 进程中,采用更优雅的幂等操作对其计数,并且通过 worker.monset('remain', remain.value) 的方法回写;