question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confusing Behavior of client.info('statistics') on Cluster

See original GitHub issue

This might be caused by my lack of understanding of JS/Node.js in general but when I tried to do something like this (assuming client being successfully connected already):

var i = 0;

client.info('statistics', function(err, response, host) {
  console.log(err, i++);
});

The output would be:

{ code: 0, message: null, func: null, file: null, line: null } 0
{ code: 0, message: null, func: null, file: null, line: null } 1
{ code: 0, message: null, func: null, file: null, line: null } 2
{ code: 0, message: null, func: null, file: null, line: null } 3
{ code: 0, message: null, func: null, file: null, line: null } 4
{ code: 0, message: null, func: null, file: null, line: null } 5
{ code: 0, message: null, func: null, file: null, line: null } 6
{ code: 0, message: null, func: null, file: null, line: null } 7

Which indicates to me that this anonymous callback function gets invoked N times, where N being the number of nodes of given cluster in the client connection.

I know there might be techniques to work around this behavior to have a streamlined workflow to collect all statistics of all the nodes within given cluster synchronously (?), but wouldn’t it be easier to have this request (I haven’t tested other requests through client.info API) behave somewhat similar to client.batchGet where the callback would get an array of results and the callback being effectively just executed once?

I’m happy to elaborate more on this issue. My specific use case is to have a client regularly checks a given Aerospike cluster’s health, and maybe there’s a better and easier way to do it? Regardless, in my opinion the current behavior of client.info('statistics') is a little bit weird and due to the async nature of js/node.js, it’s really hard to collect info from a cluster of nodes.

To give an example of this undesirable behavior, I’m using async, and client.info('statistics') is one of the tasks (I’m using async.parallel if this is relevant):

var jobs = [];

// some other jobs

jobs.push(function(callback) {
  client.info('statistics', function(err, response, host) {
    callback(err);
  });
});

And async would complain to me as Error: Callback was already called. (expected as my observation in the first example).

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jheckingcommented, Jul 14, 2016

The info method works as designed, i.e. it returns the requested info per each cluster node through the callback method as soon it is received by the client. Note that the method also has an additional, 2nd callback, which is called once all the nodes have responded:

Client.prototype.info = function (request, host, policy, infoCb, doneCb) { ... }

See the API docs for the full method signature.

But I get how this behavior be a bit unexpected and that for many use cases it would be more convenient to have all the info returned in a single callback. I’ll consider this a feature request for a future update. A pull request would be welcome as well. 😃

0reactions
jheckingcommented, Aug 5, 2016

I’ve added a new Client#infoAll method, which queries all the cluster nodes and returns the results in a single callback method call. This will be included in the next release, which is tentatively scheduled for next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

(PDF) Know Your Clients' behaviours: a cluster analysis of ...
examine the relationship between KYC and trading behaviour. The KYC data is comprised of objective. demographic and identifying information ...
Read more >
Know Your Clients' Behaviours: A Cluster Analysis of ... - MDPI
In this paper, we look to better understand the relationship between collected KYC information and trading behaviors through applications of behavioral finance ...
Read more >
Cluster Analysis and Segmentation
In such situations, to identify segments in the data one can use statistical techniques broadly called Clustering techniques.
Read more >
Customer Behavior Mining Framework (CBMF) using ...
Customer clustering and analyzing behavioral patterns of each cluster can be important steps in implementing customer relationship management ...
Read more >
Cluster Analysis for Marketers: The Ultimate Guide - Improvado
Read our ultimate guide to cluster analysis: what it is, what techniques it includes, and what pros and cons of using cluster analysis...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found