0
我試圖找到在我的應用程序中需要佔用太多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 },
您可能需要使用'console.time'和'console.timeEnd' https://developer.mozilla.org/zh-CN/docs/Web/API/console#Timers – Ser
@Ser是的,那個給了一個更好的答案:15ms!我想我會繼續那個! –