测量服务中的平均执行时间
我正在尝试使用 Windows 性能计数器来测量 WCF 服务的每秒点击次数和每次点击秒数,但看到一些奇怪的结果。
目前,我正在做的是:
public void MethodToTime()
{
StopWatch sw = new StopWatch();
sw.Start();
//...do stuff...
totalHitsCounter.Increment(); //this one works fine - NumberOfItems32 counter
hitsPerSecondCounter.Increment(); //appears broken - RateOfCountsPerSecond32 counter
secondsPerHitBaseTime.Increment(); //can't tell - AverageBase counter
sw.Stop();
secondsPerHitCounter.IncrementBy( sw.ElapsedTime ); //appears broken - AverageTimer32
}
在一天结束时,我想知道:
-该方法被点击了 x 次(在其生命周期中)。 - 该方法平均需要 xx 秒来执行。 - 该方法每秒被调用 x 次(在所有服务实例中,因为对服务的一次调用会导致对方法的一次调用)。
我走在正确的轨道上吗?有更好的方法来解决这个问题吗? 非常感谢任何反馈:)
预先感谢大家!
I'm trying to use Windows Performance Counters to measure the Hits Per Second and Seconds Per Hit of a WCF service and am seeing some strange results.
Currently, what I'm doing is this:
public void MethodToTime()
{
StopWatch sw = new StopWatch();
sw.Start();
//...do stuff...
totalHitsCounter.Increment(); //this one works fine - NumberOfItems32 counter
hitsPerSecondCounter.Increment(); //appears broken - RateOfCountsPerSecond32 counter
secondsPerHitBaseTime.Increment(); //can't tell - AverageBase counter
sw.Stop();
secondsPerHitCounter.IncrementBy( sw.ElapsedTime ); //appears broken - AverageTimer32
}
At the end of the day, I want to know:
-This method was hit x times (in its lifetime).
-This method takes, on average, x.x seconds to execute.
-This method is called x times per second (across all service instances, since one call to the service results in one call to the method).
Am I on the right track? Is there a better way to approach this issue?
Any feedback is much appreciated :)
Thanks in advance, everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如您所知,秒数/点击数只是点击数/秒的倒数。您只需将 1 除以每秒的点击次数即可得到。
Just so you know, the seconds / hit is simply the inverse of the hits / second. You just need to divide 1 by your hits / second to get it.