Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not balancing #136

Closed
danwkennedy opened this issue Aug 5, 2016 · 2 comments
Closed

Not balancing #136

danwkennedy opened this issue Aug 5, 2016 · 2 comments
Labels

Comments

@danwkennedy
Copy link

Either I'm not configuring it right or the balancer doesn't actually balance the load between the servers.

My setup is the following:

  • a two node service getting written to
  • 3 nodes discovering the service via Consul and posting data to it

When I start the 3 consumers, they each latch onto one of the two service servers and never let go. In the case below, two consumers latch onto one node in the service while the third latches onto the second (which I guess is a bit better than all three on one but theoretically worse than a simple randomization strategy).

Consumer 1:

Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.69.231:32778/sales-record

Consumer 2:

Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record

Consumer 3:

Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.69.231:32778/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record
Calling out to: http://172.31.65.172:32781/sales-record

The configuration used is as follows:

let client = Resilient({
    service: {
      headers: {
        <custom auth headers>
      },
      json: true
    },
    balancer: {
      roundRobin: true
    }
  });

client.use(resilientConsul({
    service: 'ms-service',
    servers: [
      `<single Consul server>`
    ],
    onlyHealthy: true
  }));

client.on('request:outgoing', opts => {
    console.log(`Calling out to: ${ opts.url }`);
  });

The behavior is the same for the default balancer options as well. Since basic client-side load balancing was the goal of importing this project, this is a deal breaker for me.

@h2non
Copy link
Contributor

h2non commented Aug 7, 2016

This should be fixed in version 0.3.4. Feel free to update your dependency tree.

Moreover, 2 minor features were added to resilient.

  • Optional random balancer.
  • Custom balancer strategy.

You can enable the random balancer simply enabling the option, such as:

var client = Resilient({
  balancer: {
    random: true
  }
})

Additionally, if you want to use a custom balancer strategy, you can use it via balanceStrategy option:

var client = Resilient({
  balancer: {
    balanceStrategy: servers => {
       return servers.sort(myCustomSorter)
    }
  }
})

For more details, take a look the docs:
https://github.com/resilient-http/resilient.js#balancer

@h2non h2non closed this as completed Aug 7, 2016
@danwkennedy
Copy link
Author

Works like a charm now. Thanks for the quick turnaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants