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

@sex-pomelo/sex-scale-plugin

v0.0.4

Published

sex pomelo scale-plugin ===================

Downloads

6

Readme

pomelo-scale-plugin

遵循 pomelo plugin

sex-scale-plugin for scale up servers. 插件使用redis存取相关配置/数据。

Usage(用法)

// app.js
let scale = require('@sex-pomelo/sex-scale-plugin');

app.configure('production|development', 'server', function() {
	app.use(scale, 
  {
    scale: {
      checkerPath:__dirname+'/checker/',
      prefix: 'scfg:vs:',
      redisNodes:{
          nodes:[{"host":127.0.0.1,"port":6379}],
          name:"mymaster",
      },
      password:''
      redisOpts: {
        username: 'test',
        password: 'pass'
      }
    }
  });
});
  • checkerPath, 检测脚本存放位置。
  • prefix, redis键前缀
  • redisNodes, redis 连接配置
    • nodes, redis 节点配置,如果数组长度 >1,使用哨兵模式
    • name, 哨兵名称,哨兵模式有效
  • password, redis密码

redis配置

配置数据存储在 键 monitor:backupSer,hash 类型。 如果 prefix 设置为 scale:, redis键为 scale:monitor:backupSer 包含下面几个字段:

  • scale, scale服务类型配置( json格式 )
  • scaleUpTime, scale服务类型配置更新时间戳,插件根据这个判断是否配置更改;
  • servers, 备份服务器列表(json 格式)
  • updateTime, 备份服务器列表更新时间戳

scale格式

{
  "servers":  {
    "connector":  {
      "limit0":  200,         // 启动新服务器门限,连接玩家数量,超过此数量,从备份列表里启动一个同类型服务器
      "maxCount0":  300,      // 最大连接数量,用于UI显示
      "interval":  5000,      // 检测间隔
      "increasement":  1,     // 每次增加服务器数量
      "checker": "connectChecker.js"  // checker 脚本位置
    }
  }
}

我们的connector 会定时把在线人数记录在 redis里面,connectChecker.js 在 check函数里定时获取在线人数值,当所有connector的平均在线人数超过 limit0后就从备用服务器里启动一个 connector

servers

{
	"connector":[
	  {"id":"connector-server-1", "host":"127.0.0.1", "port":4050, "clientPort": 3050, "frontend": true},
	  {"id":"connector-server-2", "host":"127.0.0.1", "port":4051, "clientPort": 3051, "frontend": true},
	  {"id":"connector-server-3", "host":"127.0.0.1", "port":4052, "clientPort": 3052, "frontend": true}
	],
	"chat":[
	  {"id":"chat-server-1", "host":"127.0.0.1", "port":6050}
	],
	"gate":[
	  {"id": "gate-server-1", "host": "127.0.0.1", "clientPort": 3014, "frontend": true}
	]
}

checker.js

请参照 cpuChecker.js

  • 可以通过 manager.rdm 获取到插件的redis实例,执行redis相关命令。 例如, this.manager.hget() .
'use strict';

let Checker = function( manager,app,condition,type )
{
    this.app = app;
    this.manager = manager;
    this.condition = condition;
    this.type = type;

    //console.log('-- Chceker:', this.condition);
};


module.exports = Checker;
let pro = Checker.prototype;


/** 数据获取,获取各个服务器的用于判断的数值(例如 connector 的在线人数),每次获取数据所有服务器会执行一次此函数
*@param serInfo 服务器信息
*@return 判断值,返回 Promise 对象
*/
pro.check = function( serInfo)
{
    return new Promise(function (resolve,reject) {
        let child = exec("ps aux|grep " + serInfo.pid + "|grep -v grep|awk '{print $3}'",
            function(error, stdout, stderr)	{
                if(!!error)	{
                    reject();
                }else{
                    resolve(stdout.slice(0, -1));
                }
            });
    });
};

/** 是否需要启动服务器
 *@param results check 函数,返回的所有服务器的判断数据
 *@param cb callback(err, true|false )
*/
pro.scale = function( results,cb ){
    
	let total = 0;
	for(let i=0; i<results.length; i++)	{
		total += Number(results[i]);
	}

	let average = Math.round(total/results.length);
	if(average > this.condition.limit) {
		if( cb ){
            cb( null, true );
        }
	}else{
        if( cb ){
            cb( null, false );
        }
    }
};

/** 初始化checker */
pro.init = function() {
    /** some init */
};
 
/** 在所有checker 启动完后调用 */
pro.afterStart = function(){
    let manager = this.manager;

};