ASP.NET Web API性能问题

Ali*_*RAN 8 c# asp.net performance asp.net-mvc-4 asp.net-web-api

我有一个简单的Web API,它返回联系人列表:

public class ContactsApi : ApiController
{
    public List<Contact> GetContacts()
    {
        Stopwatch watch = new Stopwatch();
        watch.Start();
        // Doing some business to get contacts;
        watch.Stop();
        // The operation only takes less than 500 milliseconds
        // returning list of contacts
    }
}
Run Code Online (Sandbox Code Playgroud)

正如我过去常常Stopwatch测试数据检索性能一样,它显然需要不到一秒的时间.但是,当我GetContacts通过Chrome浏览器向操作发出请求时,返回数据需要4到5秒.

在此输入图像描述

显然,延迟与我的数据检索代码无关.在我看来,Web API运行缓慢.但我不知道如何调试和跟踪它.

是否有任何实用程序来记录ASP.NET HTTP请求流程管道的时间?我的意思是,像Navigation Timing这样的事情表明每个事件都发生在什么时候?

Kon*_*osa 5

你的反应有多大?也许这是序列化和转移的成本?但是,有很多可能对它进行分析,我将从使用市场上的一种工具(如ANTS Performance ProfilerdotTrace)进行分析开始.


小智 0

尝试使用 Fiddler ( http://fiddler2.com/ ),一个免费的 Web 调试工具。它具有您正在寻找的大部分功能。

  • 这不是fiddler可以完成的事情!正如 Saeed Neamati 在之前的回答中提到的 (2认同)