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

node-intlb

v0.8.4

Published

Node business-driven loadbalancer

Downloads

36

Readme

node-intlb

  • index.js - dispatcher implementation
  • lib/registry - registry implementations
  • lib/balancers - balancer implementations

intlb is a business driven dispatcher/loadbalancer. Image you have many backends which have different states or data. You want to proxy the request on base of this data, finding just the backends in your pool which have a certain data-state, version etc.

##Features

  • proxies requests on base of tags
  • endpoints provide these tags via registry (different implementations possible)
  • statsd-support for profiling and endpoint-utilization

###How does dispatching work in detail Endpoints are checked for status by one of the service registry implementations. The list of possible endpoints is then passed to one of the balancer implementations (ootb roundrobin and failover - second is default), which are responsible for choosing one final endpoint the request is dispatched to. Balancers send a HEAD request to verify the endpoint compatibility, providing the tag in the x-lb-match request header. Endpoints have to send a HTTP 200 if compatible, or pass HTTP 412 precondition failed if the endpoint does not accept the provided tag. This additional "endpoint verification" can be enabled/disabled in configuration.

###How does intlb know which tag to use? Tags can be provided statically via configuration, provided via REST or even set per request (providing the tag as http header x-lb-match)

###Usage Just instantiate Dispatcher and pass the configuration.

var d = new Dispatcher({
  //id (intlb if not specified)
  id:"mydispatcher",
  //used balancer implementation - roundrobin is default when not specified
  balancer:balancer, 
  //endpoint registry - default implementation is static, but your implementation can be zookeeper, redis etc.
  registry:registry,  statis-registry needs it)
  //node-statsd client instance to log utilization
  statsdclient:self.statsdclient, 
  //winston logging implementation (useful when you run intlb embedded in your application), if not specified will create its own winston instance
  logger: self.logger
});
d.run(3000,'0.0.0.0');

##Dispatcher Events and Statsd-Metrics intlb fires two events - one when a request is dispatched to an endpoint, one when the response comes back. When you provide a statsd-instance intlb will automatically provide metrics about the overall utilization as well as the utilization of each endpoint

###Events

   dispatcher.on('lb-enq',function(data /* endpoint, requestid */) {
     logger.info('request %s was dispatched to %s',requestid,endpoint.id);
   });
   dispatcher.on('lb-deq',function(data /* endpoint, requestid */) {
     logger.info('request %s finished',requestid);        
   });

###Statsd-Series intlb will provide some series telling about the overall and the endpoint utilization

  • mydispatcher.currentrequests (using the dispatcher-id and telling about overall utilization) Its quite easy to implement per-request count/duration etc. yourself using the events above

##Additional Features ###lbtrace Providing a request-parameter lbtrace to get information about which endpoint was used

curl  -v localhost:3000/test/someurl?foo=bar&lbtrace=true

will set the following response-header (telling about that endpoint 1 got its first request)

x-lb-forwarded: endpoint1#1

###Dynamically balancer implementation In this case we use the failover balancer just for this request

curl  -v localhost:3000/test/someurl?foo=bar -H 'x-lb-balancer:failover'