ASP.NET中的性能计数器

Did some great performance testing this last Sunday on the bank we're taking live soon.  We needed to get a few thousand users on the box, all banking at the same time.  The Host Interface side has some great performance counters that made it very easy to measure.  Even though they have a rich serious of counters, I added some counters to the UI side. 

上周日在我们即将上线的银行做了一些出色的性能测试。 我们需要吸引数千名用户,同时进行所有银行业务。 主机接口端具有一些出色的性能计数器,这使其非常易于测量。 即使他们有大量的计数器,我还是在UI端添加了一些计数器。

As I've mentioned before, we describe our Domain Objects and Messages with XSD, and generate loads of C# code with CodeSmith (and some with XSLT).  Using these 'nouns' we create services (verbs) that act on them as they move through the system.  We build 1st class interfaces on top of a 3rd class router that basically does an Invoke/Execute/DoIt/IDispatch...a lot the way Invoke() works with ASMX WebServices. 

正如我之前提到的,我们使用XSD描述域对象和消息,并使用CodeSmith(以及一些XSLT)生成C#代码负载。 使用这些“名词”,我们创建在它们在系统中移动时对其起作用的服务(动词)。 我们在基本执行Invoke / Execute / DoIt / IDispatch的3类路由器之上构建1类接口,这与Invoke()与ASMX WebServices的工作方式非常相似。

There's a whole vocabulary of messages that can be sent to Voyager, like 'GetAccounts' or 'AddPayment.'  Some come with Voyager and some are added for the implementation. 

可以将整个词汇表发送到Voyager ,例如“ GetAccounts”或“ AddPayment”。 Voyager附带了一些功能,另外一些则用于实施。

Typically with Performance Counters there are either static counters, like 'Avg Bytes/sec' through the system, or instance counters like 'Bytes/sec on this hard drive.'  Often these instance counters are per process, or per piece-of-hardware. 

通常,在性能计数器中,要么是静态计数器,例如通过系统的“ Avg Bytes / sec”,要么是实例计数器,例如该硬盘驱动器上的“ Bytes / sec ”。 这些实例计数器通常是按进程或按硬件的。

But since the verbs that head through the system can be dynamic, why not make new per counters as we see new verbs? (there's usually no more than 100, really usually <50)  So, on both the UI and HI we can look at instance Performance Counters like 'Time in (ms) for GetAccounts' or 'Bytes Out for AddPayee.' 

但是,由于贯穿系统的动词可以是动态的,所以为什么当我们看到新的动词时不按计数器编新词呢? (通常不超过100,实际上通常不超过50)因此,在UI和HI上,我们都可以查看实例性能计数器,例如“ GetAccounts的时间(毫秒)”或“ AddPayee的字节数”。

By adding the same counters but for an 'instance' that is really a verb, we can find out when a certain operation (verb) is not performing well on the system. 

通过添加相同的计数器,但对于实际上是动词的“实例”,我们可以找出某个操作(动词)在系统上的运行状况不佳。

And, since we can look at what the UI's round-trip time is (for example, 500ms) and what the HI's times are (200ms to the host, 150ms in the code) we can start measuring interstitial times like marshalling time, logging overhead, etc. at a very granular level.

并且,由于我们可以查看UI的往返时间是什么(例如500ms)和HI的时间是什么(主机200ms,代码中150ms),所以我们可以开始测量插播时间,例如编组时间,日志记录开销等等。

Fortunately we baked in hooks to allow Performance Counters early on in the project.  You should to!  It's nice to REALLY know what's happening in your app.  The less of a black box your own app feels like, the more confident you can be when you make Service Level Agreements and predictions as to performance.  Nothing is more scary than NOT knowing how to measure your own application.

幸运的是,我们在钩子上进行了烘烤,以便在项目早期就启用性能计数器。 你应该去! 真的很高兴知道您的应用程序中发生了什么。 您自己的应用程序感觉到的黑匣子越少,则在制定服务水平协议和性能预测时就越自信。 没有不知道如何衡量自己的应用程序,没有什么比这更可怕了。

Tips and Best Practices:

提示和最佳做法:

  • Remember the ASPNET process has access to WRITE to Performance Counters, but not READ, CREATE, or DELETE counters.

    请记住,ASPNET进程有权访问写入性能计数器,但是不能读取,创建或删除计数器。

  • Add an Installer class to your ASP.NET application that does the creating of the PerformanceCategory, the creation of the PerformanceCounters and the deletion at uninstall.  You can run 'installutil [/u] yourclass.dll' from the command-line.  You can also add your installer dll to the Custom Actions section of your Web Setup and the Performance Counters will get created/deleted automatically when your MSI runs.

    将一个Installer类添加到您的ASP.NET应用程序中,该类执行PerformanceCategory的创建,PerformanceCounters的创建以及卸载时的删除。 您可以从命令行运行“ installutil [/ u] yourclass.dll 。 您还可以将安装程序dll添加到Web设置的“自定义操作”部分,并且在运行MSI时会自动创建/删除性能计数器。

  • Use some High Performance Timer for your timing - don't use DateTime.anything.

    使用一些高性能计时器进行计时-不要使用DateTime。 什么都可以

It was a good weekend.

那是个愉快的周末。

翻译自: https://www.hanselman.com/blog/performance-counters-in-aspnet

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值