长期分析ASP.net应用程序? [英] Profiling ASP.net applications over the long term?

查看:53
本文介绍了长期分析ASP.net应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对网站进行记录以记录执行统计信息的公认方法是什么?

What is the accepted way to instrument a web-site to record execution statistics?

例如,我想知道执行某些操作需要多长时间,例如通过Active Directory服务器验证用户的凭据:

For example, i want to know how long it takes to perform some operation, e.g. validating the user's credentials with the Active Directory server:

authenticated = CheckCredentials(Login1.UserName, Login1.Password);

很多人会建议使用各种追踪来输出或记录或记录有趣的性能指标:

A lot of people will suggest using Tracing, of various kinds, to output, or log, or record, the interesting performance metrics:

var sw = new System.Diagnostics.Stopwatch();
sw.Start();
authenticated = CheckCredentials(Login1.UserName, Login1.Password);
sw.Stop();

//write a number to a log
WriteToLog("TimeToCheckCredentials", sw.ElapsedTicks);

不是X;所有X

与此有关的问题是,我对根据Active Directory验证用户凭据所花的时间不感兴趣.我对在ActiveDirectory中验证数千个用户凭据所花费的时间感兴趣:

Not an X; all X

The problem with this is that i'm not interested in how long it took to validate a user's credentials against Active Directory. i'm interested in how long it took to validate thousands of user's credentials in ActiveDirectory:

var sw = new System.Diagnostics.Stopwatch();
sw.Start();
authenticated = CheckCredentials(Login1.UserName, Login1.Password);
sw.Stop();

timeToCheckCredentialsSum = timeToCheckCredentialsSum + sw.ElapsedTicks;
timeToCheckCredentialsCount = timeToCheckCredentialsCount + 1;
if ((sw.ElapsedTicks < timeToCheckCredentialMin) || (timeToCheckCredentialMin == 0))
   timeToCheckCredentialMin = sw.ElapsedTicks;
if ((sw.ElapsedTicks > timeToCheckCredentialMax) || (timeToCheckCredentialMax == 0))
   timeToCheckCredentialMax = sw.ElapsedTicks;
oldMean = timeToCheckCredentialsAverage;
newMean = timeToCheckCredentailsSum / timeToCheckCredentialsCount;
timeToCheckCredentialsAverage = newMean;

if (timeToCheckCredentailsCount > 2)
{
   timeToCheckCredentailsVariance = (
         ((timeToCheckCredentialsCount -2)*timeToCheckCredentailsVariance  + (sw.ElapsedTicks-oldMean)*(sw.ElapsedTicks-newMean))
         / (timeToCheckCredentialsCount -1))
}
else
    timeToCheckCredentailsVariance = 0;

其中有很多样板代码可以轻松地抽象为:

Which is a lot of boilerplate code that can easily be abstracted away into:

var sw = new System.Diagnostics.Stopwatch();
sw.Start();
authenticated = CheckCredentials(Login1.UserName, Login1.Password);
sw.Stop();

//record the sample
Profiler.AddSample("TimeToCheckCredentials", sw.ElapsedTicks);

还有很多样板代码,可以抽象为:

Which is still a lot of boilerplate code, that can be abstracted into:

Profiler.Start("TimeToCheckCredentials");
authenticated = CheckCredentials(Login1.UserName, Login1.Password);
Profiler.Stop("TimeToCheckCredentials");

现在我有一些统计信息正在记忆中.我可以让该网站运行几个月,并且可以随时连接到服务器并查看性能分析统计信息.这是SQL Server在各种报告中呈现其自己的运行历史记录的非常能力:

Now i have some statistics sitting in memory. i can let the web-site run for a few months, and at any time i can connect to the server and look at the profiling statistics. This is very much the ability of SQL Server to present it's own running history in various reports:

问题在于,这是一个ASP.net网站/应用程序.在一年的过程中,网络服务器会随机决定通过回收应用程序池来关闭该应用程序:

The problem is that this is an ASP.net web-site/application. Randomly throughout the course of a year, the web-server will decide to shut down the application, by recycling the application pool:

  • 也许闲置了3周
  • 可能达到了最大回收时间限制(例如24小时)
  • 也许文件上的日期已更改,并且网络服务器必须重新编译应用程序

当网络服务器决定关闭时,我所有的统计信息都会丢失.

When the web-server decides to shut down, all my statistics are lost.

有没有解决此问题的 任何 ASP.net性能/仪器框架?

Are there any ASP.net performance/instrumentation frameworks that solve this problem?

我考虑过将统计信息存储在SQL Server中.就像ASP.net会话状态可以在每个请求完成后都可以存储在SQL Server中一样,我可以每次将值存储在SQL Server中:

i thought about storing my statistics in SQL Server. Much like ASP.net session state can be stored in SQL Server after every request is complete, i could store my values in SQL Server every time:

void AddSample(String sampleName, long elapsedTicks)
{
    using (IDbConnection conn = CreateDatabaseConnection())
    {
        ExecuteAddSampleStoredProcedure(conn, sampleName, elapsedTicks);
    }
}

除了现在,我已经在我的应用程序中引入了巨大的延迟.此概要分析代码每秒被称为数千次.如果仅在内存中执行数学运算,则需要花费几微秒的时间.现在只需要几十毫秒.(1,000的因子;明显的延迟).那是行不通的.

Except now i've introduced a huge latency into my application. This profiling code is called many thousand times a second. When the math is performed only in memory it takes few microseconds. Now it takes few dozen milliseconds. (Factor of 1,000; noticeable delay). That's not going to work.

我考虑过通过实现

i have considered registering my static helper class with the ASP.net hosting environment by implementing IRegisteredObject:

public class ShutdownNotification : IRegisteredObject
{
    public void Stop(Boolean immediate)
    {
        Profiler.SaveStatisticsToDatabase();
    } 
}

但是我很好奇解决这个问题的正确方法是什么.比我聪明的人之前必须已经在ASP.net中添加了配置文件.

But i'm curious what the right way to solve this problem is. Smarter people than me must have added profiling to ASP.net before.

推荐答案

为此,我们使用了Microsoft的应用程序性能监视.它捕获页面加载时间,数据库调用时间,API调用时间等.当页面加载异常缓慢时,它还会向我们发出警报,并提供堆栈跟踪以及影响加载时间的各种调用的时间.它有些基本,但是可以解决问题,使我们能够验证是否没有任何表现不理想的变体.

We use Microsoft's Application Performance Monitoring for this. It captures page load times, DB call times, API call times, etc. When a page load is unexpectedly slow, it also alerts us and provides the stack trace along with the timings of various calls that impacted the load time. It's somewhat rudimentary but it does the trick and allowed us to verify that we didn't have any variations that were not performing as expected.

高级警告:UI仅在IE中有效.

Advance warning: the UI only works in IE.

http://technet.microsoft.com/en-us/library/hh457578.aspx

这篇关于长期分析ASP.net应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆