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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ddv-worker

v0.0.30

Published

ddv-worker

Readme

ddv-worker

npm package NPM downloads

  • ddv-worker 是 ddv 的一个核心模块,他实现了整个线程的管护和管理,已经虚拟主机的 socket 的线程之间的转发

一、初始化

var worker = require('ddv-worker');

二、使用

1、子线程

  • 所有的站点都依赖这个模块开发,该模块需要开发者提供一个http-server
  • 比如封装了 testworker.js
'use strict';
//定义进程标题
process.title = 'ddvSizeTest';
//jsnet模块-子线程模块
const worker = require('ddv-worker');
//Express 应用生成器
const express = require('express');
//生成一个应用
const app = express();
//服务调度模块
worker.server = http.createServer(app);

//app的进一步开发

worker.config = Object.create(null);

//标记没有启动过
let isStart = false ;
//导出一个模块-服务启动
module.exports = function start(c){
  worker.config = c || worker.config || Object.create(null);
  c = void 0;
  if (isStart===true) {
	//防止重复启动
      console.warn('不能重复开始');
      return ;
  }
	worker.server.setConfig(worker.config);
  //发送所以修改给管理线程,更新 监听信息
	worker.updateServerConf({
		//修改是否默认监听站点
		defaultListen: worker.config.defaultListen,
		//修改监听数组
		listen : worker.config.listen,
		//修改监听cpu核数
		cpuLen : worker.config.cpuLen,
	}, (e)=>{
		if (e) {
			console.log(`[pid:${process.pid}][wid:${worker.id}]更新服务器监听配置参数失败!`);
		}else{
			console.log(`[pid:${process.pid}][wid:${worker.id}]更新服务器监听配置参数成功!`);
		}
	});
};

/***********************异常错误处理模块开始***********************/

//服务器错误捕获,抛出到server::error
worker.server.on('error', function (e) {
	//客户端socket重置 忽略这一错误
	if (e.message == 'read ECONNRESET'&&e.name === 'Error') {
		return false;
	}else{
		worker.emit('server::error',e);
	}
	e = undefined ;
});
//server错误捕获处理
worker.on('server::error',function(e){
	if(e.stack){
		e.stack = Error().stack;
	}
	e.stack +='\nthis error is server error';
	worker.emit('error',e);
});
//socket错误捕获处理
worker.on('socket::error',function(e){
	if(e.stack){
		e.stack = Error().stack;
	}
	e.stack +='\nthis error is socket error';
	worker.emit('error',e);
});

//错误
worker.on('error',function(e){
	console.error(`[pid:${process.pid}][wid:${worker.id}]服务器内部错误开始`);
	console.error(e);
	console.error(`[pid:${process.pid}][wid:${worker.id}]服务器内部错误结束`);
	console.error(Error().stack);
});

/***********************异常错误处理模块结束***********************/


  • 以下是index.js

require('./testworker.js')({
    //非默认站点
    defaultListen:false,
    //监听数组
    listen:[
        {
            'type':'tcp',
            'host':'rpc.iceovideo.ping-qu.com',
            'port':80
        }
    ],
    //监听cpu核数
    cpuLen:1
});
  • 通过以下代码运行

node index.js

2、管理线程

  • master.js

//引入管理线程模块
const master = require('ddv-worker');

master.on('error',function masterError(e){
	log.tip('ERR ','MASTER_ERROR_WARN');
	log.error(e);
});
master.on('server::listening',function masterError(info){
	log.tip('INFO',['MASTER_SERVER_LISTENING', info&&info.type_port_ip]);
});
master.on('server::close',function masterError(info){
	log.tip('INFO',['MASTER_SERVER_LISTENING_CLOSE', info&&info.type_port_ip]);
});
master.on('server::error',function masterError(e){
	log.tip('ERR ','MASTER_SERVER_ERROR_WARN');
	log.error(e);
	process.exit(1);
});

//主进程启动完毕
master.on('loadend',function masterInit(){
    let site = {};
    site.logOutput = site.logOutput || path.join(site.path, 'log/output.log');
    site.logError = site.logError || path.join(site.path, 'log/error.log');
    site.logAll = site.logAll || path.join(site.path, 'log/all.log');
    //站点文件
    site.workerFile = site.workerFile || site.path;
    master.loadSite(site);
	//服务器启动
	master.serverRun();
	//重新载入站点
	master.reLoadSite();

});

3、守护线程

  • daemon.js

//引入守护线程模块
const DdvDaemon = require('ddv-worker/daemon');
let daemon = new DdvDaemon();
//监听加载完毕
daemon.on('loadend',()=>{
    //设置管理线程启动文件
	daemon.setMasterFile(path.resolve(__dirname,'./master.js'));
	//开始运行管理线程
	daemon.run();
});