Performance 对web服务进行故障排除';s速度

Performance 对web服务进行故障排除';s速度,performance,web-services,Performance,Web Services,C#.NET 2.0,如果事实证明适用的话 我将开始深入了解为什么我们的web服务运行缓慢—此web服务跳过代理,进入另一个域,查询存储过程中的一些数据,然后返回int/string/dataset,具体取决于我的要求。我刚刚编写了一个控制台应用程序,它以同样的方式重复查询,这样我就可以收集一些统计数据 对于每个请求,“保持活动”(Keep alive)都处于关闭状态,因为某些遗留原因,没有人记录,因此会立即发出气味 当多次循环处理同一个请求时,我注意到一些奇怪的行为。下面是我的输出,它反映了每

C#.NET 2.0,如果事实证明适用的话

我将开始深入了解为什么我们的web服务运行缓慢—此web服务跳过代理,进入另一个域,查询存储过程中的一些数据,然后返回int/string/dataset,具体取决于我的要求。我刚刚编写了一个控制台应用程序,它以同样的方式重复查询,这样我就可以收集一些统计数据

对于每个请求,“保持活动”(Keep alive)都处于关闭状态,因为某些遗留原因,没有人记录,因此会立即发出气味

当多次循环处理同一个请求时,我注意到一些奇怪的行为。下面是我的输出,它反映了每次迭代进行查询和返回数据所花费的时间

Beginning run #1...completed in 4859.3128 ms
Beginning run #2...completed in 3812.4512 ms
Beginning run #3...completed in 3828.076 ms
Beginning run #4...completed in 3828.076 ms
Beginning run #5...completed in 546.868 ms
Beginning run #6...completed in 3828.076 ms
Beginning run #7...completed in 546.868 ms
Beginning run #8...completed in 3828.076 ms
Beginning run #9...completed in 3828.076 ms
Beginning run #10...completed in 578.1176 ms
Beginning run #11...completed in 3796.8264 ms
Beginning run #12...completed in 3828.076 ms
Beginning run #13...completed in 3828.076 ms
Beginning run #14...completed in 3828.076 ms
Beginning run #15...completed in 3828.076 ms
Beginning run #16...completed in 3828.076 ms
Beginning run #17...completed in 546.868 ms
Beginning run #18...completed in 3828.076 ms
Beginning run #19...completed in 3828.076 ms
Beginning run #20...completed in 546.868 ms
Total time: 61165 ms
Average time per request: 3058 ms
我觉得奇怪的是,有多个重复的值,下降到一个非常小的水平是否存在导致在相同时间内重复返回的瓶颈?

…希望我的计算和显示毫秒持续时间的代码没有关闭,但是TimeSpan对象跟踪它是每个循环的局部,所以我不认为是这样

EDIT:Jon要求提供计时代码,所以现在可以了(变量名已更改以保护专有名称,因此可能有一些粗制滥造的东西使其无法编译)

inttotalruntime=0;
对于(int i=0;i
最简单的方法是,在不运行探查器等的情况下,让web应用程序记录开始操作的准确时间(显然,尽可能接近您所能获得的时间)、调用中的不同时间以及完成时间。然后你就可以看到它花了多少时间。(使用秒表会让你更准确,但要做到这一点会稍微困难一些。)

我同意你重复几次是很奇怪的。你能把测量它的代码贴出来吗?如果我看到某种捕获变量的问题使你的计时变得混乱,我不会感到非常惊讶

编辑:你的计时代码看起来不错。真奇怪。我建议您也在web服务上记录时间,看看它看起来是否相同。就好像有什么东西在故意扼杀它


当你运行它时,它看起来是否像它所说的那样花费了大量的时间-例如,当它说它花费了3秒时,是在最后一行被写入后的3秒左右吗?

现在你需要为链中的其他步骤获取一些基准值。查看服务器日志以获取您的请求到达Web服务器的时间,并在Web服务代码中添加一些日志记录,以查看Web服务器何时切换到实际的“工作”代码

完成后,您可以开始缩小最慢部分的性能范围,重复您喜欢的内容。

SimpleService的创建(以及创建时间)是否会扭曲您的数字? 如果你把它从循环中拉出来会发生什么

int totalRunTime = 0;
SimpleService ws = new SimpleService();
for (int i = 0; i < numberOfIterations; i++)
{
    Console.Write("Beginning run #" + (i + 1).ToString() + "...");
    DateTime start = DateTime.Now;
    DataSet ds = ws.CallSomeMethod();
    DateTime end = DateTime.Now;
    TimeSpan runTime = end - start;
    totalRunTime += (int)runTime.TotalMilliseconds;
    Console.Write("completed in " + runTime.TotalMilliseconds.ToString() + " ms\n");
}
Console.WriteLine("Total time: " + totalRunTime.ToString() + " ms");
Console.WriteLine("Average time per request: " + (totalRunTime / numberOfIterations).ToString() + " ms\n");
inttotalruntime=0;
SimpleService ws=新SimpleService();
对于(int i=0;i
还有一件事:重复运行测试应用程序会给出上述时间大致相同的不同组合。同样的毫秒时间值,但顺序不同。re:你的编辑…是的,如果其中一个亚秒运行命中,它肯定会以那么快的速度扫描过去。我可以访问请求服务器和端点服务器(而不是代理服务器),因此我将在每个服务器上启动网络跟踪,以查看是否可以识别某些内容。
int totalRunTime = 0;
SimpleService ws = new SimpleService();
for (int i = 0; i < numberOfIterations; i++)
{
    Console.Write("Beginning run #" + (i + 1).ToString() + "...");
    DateTime start = DateTime.Now;
    DataSet ds = ws.CallSomeMethod();
    DateTime end = DateTime.Now;
    TimeSpan runTime = end - start;
    totalRunTime += (int)runTime.TotalMilliseconds;
    Console.Write("completed in " + runTime.TotalMilliseconds.ToString() + " ms\n");
}
Console.WriteLine("Total time: " + totalRunTime.ToString() + " ms");
Console.WriteLine("Average time per request: " + (totalRunTime / numberOfIterations).ToString() + " ms\n");