Meteor服务器方法运行时

时间:2016-06-15 07:58:35

标签: javascript node.js meteor

我试图在我的应用程序中找到占用大量CPU的原因以及为什么我需要等待很长时间,所以我开始在应用程序中记录一些内容。当我记录我的应用程序中的每个部分时,我遇到了这个:

var updateTime = process.hrtime();

Nightclubs.update({_id: nightclubId}, {$push: { guests: {
  value: value,
  currentGuestAmount: currentGuestAmount+value,
  date: thisEntryDate.toDate(),
  gender: gender,
  age: age,
  guard: guardId
}}})

var updateDiff = process.hrtime(updateTime);

稍后在方法中,我这样记录:

console.log('update benchmark took %d nanoseconds', updateTime[0] * 1e9 + updateTime[1]);

结果如下:

update benchmark took 1084353904561267 nanoseconds

是的..这是1.8周......这真的很奇怪,因为这个方法总共需要916589992纳秒,或0.91秒(仍然有点太长)

有人对此有任何线索吗?

PS,关于我插入的数据的一些细节:

guests: { type: Array, defaultValue: [] },
'guests.$': { type: Object },
'guests.$.value': { type: Number },
'guests.$.currentGuestAmount': { type: Number },
'guests.$.date': { type: Date },
'guests.$.age': { type: Number },
'guests.$.gender': { type: String },
'guests.$.guard': { type: String },

1 个答案:

答案 0 :(得分:1)

总而言之,请使用console.timeconsole.timeEnd代替process.hrtime()

console.time("Update nightclub");

Nightclubs.update({_id: nightclubId}, {$push: { guests: {
  value: value,
  currentGuestAmount: currentGuestAmount+value,
  date: thisEntryDate.toDate(),
  gender: gender,
  age: age,
  guard: guardId
}}})

console.timeEnd("Update nightclub");