I have a collection of roughly 50K documents in a DB. And this collection is not used for subscription/publication. I use this only with a method call to retrieve data.
However, I figured out that the meteor server’s CPU regularly spikes up depending on the amount of data in the MongoDB. FYI, Meteor server and MongoDB are hosted on separate AWS EC2 instances.
It seems that meteor fetches all the data when the collection is declared and holds it for poll-and-diff, which causes CPU to hit high regularly. How can I stop this?
I appreciate any comments!
~~~~~~~~~~~~~ update ~~~~~~~~~~~~~~
The issue is solved by implementing a different pattern. Because I do not need reactivity for this collection, I simply declared and initialized the collection from the raw database by using MongoInternals. It has a different syntax, (eg. there is no cursor.fetch() which makes it a bit tricky if you want to return the collection docs through method calls… Also you need to implement collection hooks on your own.) but the CPU is now on zero to 2 percent at most. Before it reached up to 30 percent on a single node on M4.large EC2 instance.
Just not using pub-sub pattern didn’t solve my problem. (By the way, I am sure that the oplog tailing is working properly when I see the other reactivity-based collections. And the MongoDB replicaSet is also working properly.)
Hope this can be a reference to anyone with similar concerns.