gpt4 book ai didi

javascript - Meteor 服务器方法运行时间

转载 作者:行者123 更新时间:2023-12-03 06:44:01 24 4
gpt4 key购买 nike

我试图找出我的应用程序中的哪些内容占用了如此多的 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.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");

关于javascript - Meteor 服务器方法运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37829400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com