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

Can a cluster node signal that it is busy? #121

Open
cspecter opened this issue Mar 28, 2016 · 2 comments
Open

Can a cluster node signal that it is busy? #121

cspecter opened this issue Mar 28, 2016 · 2 comments

Comments

@cspecter
Copy link

I have an app with a processor intensive background task. It process a bunch of data that is all related to each other. To get through this quickly I want to launch multiple instances of the background task service. I have a cluster that looks like this.

--Background manager
--Proc node A
--Proc node B

The manager figures out if there is data to be processed and sends it to one of the nodes. I'm using the boiler plate connection pool code from this post.

My background task is pretty intensive, so I'm splitting it up into smaller jobs and sending each small job to one of the nodes. My question is: Is there a way I can have the node send a message saying it is busy? Right now I'm using a return into a variable on the manager, but it seems inelegant.

On node

`Meteor.methods({
     something: function(limit) {
          //...do something
          return "ready"
     };
});

On manager

var nodeA = "ready";
var nodeB = "ready";
while (stuffToDo > 0) {
     if (nodeA == "ready") {
          nodeA = "busy;
          nodeA.call("something", 1000, function(err, res) {
               if (err) {throw err}
               if (res) {nodeA = res}
          }
     }
}

Is there a better way to do this?

@MasterJames
Copy link

Yes. Make a jobs table and get them if not busy.
Same difference if you have a processing system make its availability know through the database via a status value. The server will get the notification when it's status changes automatically.

@cspecter
Copy link
Author

Thanks for the tip. I ended up rolling my own jobs system and just submit the individual jobs through there. A little more legwork to make it work, but seems more scaleable in the long run.

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

No branches or pull requests

2 participants