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

socket.io-flex

v0.0.1

Published

socket.io-flex 柔性服务组件

Downloads

9

Readme

socket.io-flex

socket.io 使用 socket.io-flex 组件让服务端能够提供柔性服务.

How to use

var app = require('http').createServer(handler);

var io = require('socket.io')(app);
var flex = require('socket.io-flex');

function handler (req, res) {
    res.setHeader("Access-Control-Allow-Origin", "*");
    res.writeHead(200);
    var data = 'no http service available!';
    res.end(data);
}

io.adapter(flex({
    threshold:[5,2000],
    thresholdTime:1,
    sysReTime:10,
    loadavg: [ 3,10 ],
    cpuusage: [ 10,30 ],
    memory: [ 0.99,0.3 ]
}));

io.on('connection', function (socket) {

	io.of('/').adapter.flexService(socket.id,function (err, obj,flag) {
		//TODO
	});

});

app.listen(3000);

API

adapter(opts)

The following options are allowed:

  • pingInterval: 隔多少毫秒发送一个新的ping包 (25000)
  • threshold: 柔性服务变化区间,第一个元素是websocket达到转短连数,第二个是websocekt达到转长连数 ([5,2])
  • thresholdTime: 每次变换等待小时数,不设置则达到就变 (1)
  • allowUpgrades: 是否运行协议升级,不设置该项时才能设置柔性服务功能 (true)
  • sysReTime: 读取系统信息间隔时间 (1)
  • loadavg: 根据CPU 1分钟的负载,设置柔性服务功能 ([0.9,0.5])
  • cpuusage: 根据CPU 使用率,设置柔性服务功能 ([70,1])
  • memory: 根据内存使用率,设置柔性服务功能 ([0.7,0.3])

FlexAdapter

The flex adapter instances expose the following properties that a regular Adapter does not

FlexAdapter#flexService(id:String, fn:Function)

io.of('/').adapter.flexService(id,function (err, obj, flag) {
  console.log(obj,flag);
});

The following obj are allowed:

  • pingInterval: 隔多少毫秒发送一个新的ping包 (25000)
  • threshold: 柔性服务变化区间,转websocekt的区间 ([5,2])
  • thresholdTime: 每次变换等待小时数,不设置则达到就变 (1)
  • clientsCount: 目前服务的总连接数 (11)
  • clientsWebSocketCount: 目前服务WebSocket的总连接数 (10)
  • clientsPollingCount: 目前服务轮询的总连接数 (1)
  • changeTime: 上一次协议改变的时间 (1489649263605)
  • isWs: 是否是WebSocket连接 (true)
  • sysReTime: 读取系统信息间隔时间 (1)
  • loadavg: 根据CPU 1分钟的负载,设置柔性服务功能 转websocekt的区间 ([0.9,0.5])
  • cpuusage: 根据CPU 使用率,设置柔性服务功能 转websocekt的区间 ([70,1])
  • memory: 根据内存使用率,设置柔性服务功能 转websocekt的区间 ([0.7,0.3])
  • currcpuusage: 当前CPU使用率 (0.3)
  • currmemusage: 当前内存使用率 (0.2)

The following flag are allowed:

  • flag: 0表示没有转变,1表示转为短链,2表示转为长链 (0)

License

MIT