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

n-tpool2

v0.1.7

Published

thrift连接池

Readme

n-tpool

介绍

实现一个node客户端thrift连接池。基于Promise API接收trift服务返回的数据。 可创建一个端口一个服务的连接池,也可以创建单端口富应用的连接池。

软件架构

使用generic-pool和thrift。

更新说明(0.1.7)

  1. 修复连接泄漏:服务端无响应/连接中途断开时,调用 Promise 永远不会结束,导致连接被永久占用直至连接池耗尽。现在每次 RPC 调用有超时保护(默认 15s,可通过 poolOption 的 rpcTimeoutMillis 配置),超时或连接损坏时自动销毁连接重建,坏连接不再回池。
  2. 连接入池后同步监听 socket 断开/出错,借出前校验连接有效性,失效连接自动剔除。
  3. 错误提示中文化:网络连接错误 / 连接池已占满 / 获取连接超时 / 服务端响应超时,并保留原始错误信息便于排查。

安装教程

  1. npm i n-tpool2
  2. 示例:
// 引入包
// mypool是连接池初始化函数
// 参数:[object]constructor 必须:thrift生成的文件, 
//       [object]thriftOption 必须:thrift连接配置项 + host + port + serviceName, 
//       [object|undefine]poolOption 可选: 连接词配置项
const mypool = require('n-tpool');
// 我的thrift客户端文件
var  Service = require('./Service');

var thriftConfig = {
  host: '127.0.0.1',
  port: 33206,
  // thrift服务是单端口富应用时,使用serviceName指定调用的服务名
  // serviceName: 'user'
}

var client = mypool(Service, thriftConfig);
// 配置连接池最大连接数是10
// var client = mypool(Service, thriftConfig, { max: 10 });
// 可以直接通过client.method().then(data => console.log(data)).catch(err => console.log(err))
// 调用thrift客户端方法,并取得返回值。
// 当服务端关闭时,这个线程池也不会退出,每次调用也会尝试创建连接,直到服务重新启动
// poolOptions是连接池配置,具体配置参考:[https://github.com/coopernurse/node-pool#readme](https://github.com/coopernurse/node-pool)