Meteor Perfomance Issue

We are using meteor V1.5 in our project. We noticed a strange behavior with publish and subscriber method. Posting a screen shot from KADIRA for one of the subscriber

Dhluk

publish method

Meteor.publish( 'companyBuiltCourses', companyId => {  
    return BuiltCourses.find({ company_id: companyId })
});

When we use below subscriber and we visit xyz page, KADIRA shows continuous fetching of documents as shown in screen shot. Even though we visit another page, this graph remains same

Template.xyz.onCreated(function() {
   Tracker.autorun( () => {
     if (Meteor.user()) {
        Meteor.subscribe('companyBuiltCourses',Meteor.user().profile.company_id);
     }
   });
});

When we use below subscriber method and we visit xyz page, KADIRA shows continuous fetching of documents as shown in screen shot. But when we visit another page, this graph goes down to 0. It won’t fetch document anymore

Template.xyz.onCreated(function() {
   this.autorun( () => {
     let self = this;
      if(Meteor.user()){
        self.subscribe('companyBuiltCourses',Meteor.user().profile.company_id);
     }
   });
});

For development environment both methods fetch documents only once when required. This is the PRODUCTION issue.

We are hosting MongoDB remotely and we run production on pm2 . There should not be a continuous fetching I guess.

1 Like

Don’t do things this way. You’ll resubscribe over and over again, whenever the user document changes!

That’s part one of what’s wrong. Part two is you are probably mutating documents inside an autorun or template helper.

3 Likes

We switched everything to calls from subscribes that didn’t need to be reactive. Performance was horrible until we made that change.