New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tcp-balance

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcp-balance

A server that provides load balancing function for TCP connections.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
0
Weekly downloads
 
Created
Source

tcp-balance

A simple TCP load balancer.
一个简单的TCP负载均衡器。

Installation

$ npm install -g tcp-balance

Usage

$ tcp-balance [-b [host:]port] [-a single|robin|random|weighted] host:port[%weight] [host:port[%weight]...]

-b, --bind
Bind to the specified address and port. Default: 127.0.0.1:8080.
绑定到指定的地址和端口。默认:127.0.0.1:8080。

-a, --algorithm
Load balancing algorithm. Algorithms: single, robin, random, weighted. Default: robin.
负载均衡算法。可选值:single, robin, random, weighted。默认:robin。

host:port[%weight]
Upstream server address and port. Weight is a optional numeric leading with percentage sign. If not specified, the default weight is 100. It's only effective when algorithm is weighted.
上游服务的地址和端口。权重是一个可选的数值,以百分号开头。如果未指定,默认权重为100。仅在weighted算法下有效。

Examples

Single. Load balance to the first available server only. For example: Failover.
Single. 只负载到第一个可用的服务器。例如:故障转移。

$ tcp-balance -b 0.0.0.0:1883 -a single s1.example.com:1883 s2.example.com:1883

Weighted round robin. For example: HTTP load balancing.
权重轮询。例如:HTTP负载均衡。

$ tcp-balance -b 0.0.0.0:80 -a weighted s1.example.com:80%30 s2.example.com:80%70

Programing

Install tcp-balance as npm dependency.
安装tcp-balance为npm依赖。

$ npm i tcp-balance

Import and use it.
引入并使用。

// Import tcp-balance components
// 导入tcp-balance组件
import { Agent } from 'tcp-balance/bin/agent';
import { SingleBalancer } from 'tcp-balance/bin/balancer';
import { Logger } from 'tcp-balance/bin/logger';

// Optional, using console for log output.
// 可选的,使用console输出日志。
Logger.setChannel(console);

// Create a balancer and register upstream servers.
// 创建一个负载均衡器并注册上游服务器。
const balancer = new SingleBalancer();
balancer.putUpstream('s1.example.com', 80);
balancer.putUpstream('s2.example.com', 80);

// Create an agent and start it.
// 创建一个代理并启动。
const agent = new Agent(balancer);
agent.start(0.0.0.0, 80);

Build

$ npm i -g typescript
$ git clone https://github.com/iwares/tcp-balance.git
$ cd tcp-balance
$ npm i
$ npm run build

License

MIT

Keywords

FAQs

Package last updated on 10 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc