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

Question: Is there a way in app that we can detect current running core? #51

Closed
vuhpham opened this issue Apr 30, 2015 · 2 comments
Closed

Comments

@vuhpham
Copy link

vuhpham commented Apr 30, 2015

I'm running to an issue that I have an Mongo update query in startup code of server:

if (Meteor.isServer) {
 Meteor.startup(function(){
    Posts.find().observeChanges({
        added: function(id, fields) {
            Authors.update({_id: fields.authorId}, {$inc: {count: 1}});
        }
    })
 });
}

I run app with 4 cores server and this added event run 4 times which I expected just 1.
Is there a way in app that we can detect current running core? Or any other best practices to run observerChanges in multicore environment?

@arunoda
Copy link
Member

arunoda commented May 1, 2015

It's very tricky to run these kind of stuff. This is not only for cores,
think what will be happen when you are running multiple servers of your app.

Here's a way to to that.

  • Inside every worker there's a env variable called CLUSTER_WORKER_ID.
    Try to create the observer when there is no such worker
  • When you are running multiple servers, expose a new env for only one
    server. And check for that env as well.
  • So, this observer runs on a single server and single core.

You can even look at some other stuffs like, doing these things as a job
queue or running different app.

On Fri, May 1, 2015 at 1:49 AM Vu Pham notifications@github.com wrote:

I'm running to an issue that I have an Mongo update query in startup code
of server:

if (Meteor.isServer) {
Meteor.startup(function(){
Posts.find().observeChanges({
added: function(id, fields) {
Authors.update({_id: fields.authorId}, {$inc: {count: 1}});
}
})
});
}

I run app with 4 cores server and this added event run 4 times which I
expected just 1.
Is there a way in app that we can detect current running core? Or any
other best practices to run observerChanges in multicore environment?


Reply to this email directly or view it on GitHub
#51.

@vuhpham
Copy link
Author

vuhpham commented May 1, 2015

Thanks @arunoda I think I'd better run this in a microservice then.
However that env variable is nice as well. 👍

@vuhpham vuhpham closed this as completed May 4, 2015
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