How to debug slow meteor methods?

Several of my meteor methods have mysteriously slowed down lately. While they were pretty fast, many of them took 10 or so seconds.

Things not causing slowdown:

  • Additional functionality, slow sections of the code base have not been significantly changed
  • Machine load (CPU load is about 30%)
  • Additional database loading (no new queries added)
  • return data transfer time (returns undefined)
  • lock method (I tried with this.unblock () inside the method)

I debugged using console.time () / console.timeEnd () both on the server and on the client side. The server code takes about 0.3 seconds to start, but the client does not receive a callback about 11 seconds after meteor.call () ...

This is the server method:

function cancelSomething(somethingId, reason) {
  console.time('cancelSomething method');
  check(somethingId, String);
  check(reason, String);

  if (!AuthChecks()))
    throw new Meteor.Error(401, 'Not Authorized');

  var something = MySomethings.findOne({'_id': somethingId});
  if (!something)
    throw new Meteor.Error(404, 'Something not found');

  var returnVal = SomethingService.cancel(something, reason);
  console.timeEnd('cancelSomething method'); // <--- prints "cancelSomething 350ms" or there abouts
  return returnVal;
}

on the client side:

  console.time('meteorCall');
  Meteor.call('cancelSomething', this._id, reason, function(err) {
    if (err) {
        console.log('an error occurred', err);
    }
    console.timeEnd('meteorCall'); // <--- prints "meteorCall 11500" or so
  });

EDIT: I noticed that there is some correlation with the number of documents in "somethings" in db. with 500 documents it takes about 1 second to receive a return to the client, with 5000 it takes about 8.5 seconds ...

+4
source share
1 answer

Interesting. I think it's hard to answer without knowing more about your application, but I have suggestions that will help you in the right direction.

blocking

, , , , , . unblock . , this.unblock .

SomethingService.cancel -, DDP, . , :

  • ,
  • ( )

, observe, , . , , , . , :

  • oplog.
  • , , oplog. 1.0.
  • , .
  • , oplog, .
+4

Source: https://habr.com/ru/post/1524411/


All Articles