Question

I just wrote a small program in meteor and using MongoHQ running under Heroku. This simple app will create a live count of how many people submit the email. You can find the example here: DearJJAbrams Here is the collection:

Counts = new Meteor.Collection("supporters");

On client side, I run:

Template.CountWrapper.SupporterCount = function () {
    return  Counts.find().count();
};

Template.BodySupporter.events({
    'click .support-click' : function () {
      if ($("#supportInputName").val() != "") {
        Supporters.insert({name: $("#supportInputName").val()});
        $(".signup-form").fadeOut(600, function() {
          $(".thank-you-message").fadeIn(600);
        });
      }
      return false;
    }
})

The problem is that when the number of users submit their email include, the database seems to do the count query very slow. Is there any better way to handle this? Thank you.

Was it helpful?

Solution

A look over the raw DDP socket shows you're sending down the entire collection to the client, so in effect everyone downloads the entire 'supporters' collection.

This looks like the bit inefficient. This is because you send down the whole collection (~7000 records - which each looks to be ~100 bytes on the DDP wire), in total nearly 1 mb of data to be downloaded.

So these have to be downloaded first, then the count can be displayed. Why not store the count in a separate collection and only send that down? It should be much faster that way. Unless you're giving the entire list of names on a table or something somewhere it might be better to do this.

The other thing is on your hosting provider you're not letting websockets work so meteor falls back to long-polling (XHR) which is a bit slower to initially connect since there is all this extra overhead. You might want to look at something you have in between, typically a proxy or firewall that isn't configured to let through websocket requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top