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

seneca-load-balancer

v0.0.1

Published

A seneca service that will allow you to easily manage multiple running services with the same patterns

Downloads

14

Readme

Seneca

A Seneca.js service load balancer that allows you to run multiple instances of services listening for the same pattern.

Seneca-load-balancer

IN PROGRESS, NOT PROD READY

npm version Build Status Dependency Status Gitter chat

This is a plugin for Seneca that allows you to load balance between multiple running instances of your services. This allows you to build what appears to be the evolving standard for microservices (run as many as needed of the same service at once to meet demand, load balance between them). This only works with http and tcp transports.

Example

At the end of this example, you will have seen how to run some services, hook your load-balancer to them, and then the load balancer will send out jobs to them from some client. The client sends all acts to the load-balancer, the load-balancer then sends acts to a running service, and the service gets a reply from the client.

The service/server below (service.js) is run with the command node math.js SOME_PORT, allowing you to create the same service listening on multiple ports.

var seneca = require('seneca')()

// A basic pattern to use
seneca.add({ a: 1 }, function (input, done) {
  console.log(input)
  done(null, { b: 1, port: process.argv[2] })
})

// eg. run with node ./test.js 10201
seneca.listen({ port: process.argv[2] })

The code below (balancer.js) is how you would setup your customised load-balancer. You just .use() the load-balancer, and supply it with some options/config. I will supply SOME_LOAD_BALANCE_CONFIG_OBJECT later.

var Seneca = require('seneca')()
var SOME_LOAD_BALANCE_CONFIG_OBJECT = {...}

seneca.use(require('seneca-load-balancer'), SOME_LOAD_BALANCE_CONFIG_OBJECT)

seneca.listen({port: 10100})

The code below (client.js) is an example of a client that wants to use our already defined service. This client connects to our load-balancer, NOT the services themselves.

var seneca = require('seneca')()

seneca.client({ port: 10100, pin: {} })

setInterval(function () {
  seneca.act({ a: 1 }, console.log)
}, 10000)

If you ran service.js three times, you need some way of connecting to it. e.g if you ran the following:

node ./service.js 10201
node ./service.js 10202
node ./service.js 10203

now run the client. this will try every ten seconds to hit our currently running service, and log the result. when it starts getting replies with the b and port property, we know we succeeded

node ./client.js

Now, we need the balancer to connect our client to our services. This is where the config object mentioned above comes in. This object has a specific stucture, explained in full later. however, for this example, the following config works:

var config = {
  services: [
    {
      //we can use seneca pattern style definitions here, or standard objects!
      pattern: 'a:1',
      locations: [
        { host: 'localhost', port: '10201', spec: 'http' },
        { host: 'localhost', port: '10202', spec: 'http' },
        { host: 'localhost', port: '10203', spec: 'http' }
      ]
    }
  ]
}

now, with the config above, run ./balancer.js with the following:

node ./balancer.js

Contributing

This module follows the general Senecajs org contribution guidelines, and encourages open participation. If you feel you can help in any way, or discover any Issues, feel free to create an issue or create a pull request!

If you wish to read more on our guidelines, feel free to

License

Copyright Glen Keane and other contributors 2016, Licensed under MIT.