【问题标题】:webservice response time increased...how?网络服务响应时间增加了...如何?
【发布时间】:2011-12-15 18:43:44
【问题描述】:

我有一个webservice方法:

[WebMethod]
public Response Process()
{
   return RunCode();
}

RunCode() 需要 6 秒才能运行,但 IIS/浏览器需要 20 多秒才能返回 XML。

如果我将 RunCode() 放入一个线程中,它现在将在 6 秒内返回:

private _response Response;
[WebMethod]
public Response Process()
{
   new Thread(RunProcess).Start()
   while(_response==null)
   {
     Thread.Sleep(100);
   }
   return _response;
}

private void RunProcess()
{
   _response=RunCode();
}

我的问题是……在 RunCode() 中会发生什么来强制 IIS/ASP.NET 延迟响应?代码只需要 6 秒即可运行...如果某种资源不在单独的线程上,是否会被占用和锁定,所以 ASP.NET 会等待它?

编辑#1:请求响应的示例。 响应示例如下:

<PostResponse>
      <isValidPost>false</isValidPost>
      <ResponseType>Post_Over_Max</ResponseType>
      <ResponseDetails>System is currently at max leads allowed</ResponseDetails>
      <LeadIdentifier>0</LeadIdentifier>
      <VendorAccountAssigned>0</VendorAccountAssigned>
      <PendingQCReview>false</PendingQCReview>
      <Price>0</Price>
      <RedirectURL/>
</PostResponse>

基于此类:

public class PostResponse : IPostResponse
{
    public PostResponse()
    {
    }

    public PostResponse(bool isValid, ResponseErrors responseType, string details, long leadIdentifier,
                        long vendorAccountAssigned, bool pendingQCReview, double price, string redirectUrl)
    {
        isValidPost = isValid;
        ResponseType = responseType;
        ResponseDetails = details;
        LeadIdentifier = leadIdentifier;
        VendorAccountAssigned = vendorAccountAssigned;
        PendingQCReview = pendingQCReview;
        Price = price;
        RedirectURL = redirectUrl;
    }

    #region IPostResponse Members

    public bool isValidPost { get; set; }
    public ResponseErrors ResponseType { get; set; }
    public string ResponseDetails { get; set; }
    public long LeadIdentifier { get; set; }
    public long VendorAccountAssigned { get; set; }
    public bool PendingQCReview { get; set; }
    public double Price { get; set; }
    public string RedirectURL { get; set; }

    #endregion
}

【问题讨论】:

  • 您在重置 IIS 后运行了多少次测试?
  • 方法返回多少输出?此外,您不需要执行“忙碌”的 while 循环。您可以在您创建的线程上执行 thread.Join()。
  • 您的代码可能需要 6 秒才能运行,但是 IIS 需要做多少工作才能将结果返回给您并接受您的消息?
  • -Maess:我尝试过重置 IIS 以及仅从头开始完全删除和重新创建网站
  • – Ingenu:我添加了一个示例响应。另外,感谢您的提示:)

标签: c# asp.net web-services


【解决方案1】:

如果请求挂起,ASP.NET 运行时将阻止来自同一用户会话的线程。

Why can’t I execute two requests from the same session simultaneously for an ASP.NET application?

【讨论】:

  • 需要注意的是,无论多个并发请求如何,我的整个 web 方法从开始到结束只需要 6 秒的运行时间......延迟发生在我的代码运行后,将响应返回给浏览器.
  • – x0n:平均 POST 大约需要 500 毫秒,但此示例确实对数百万行的实时数据进行重复检查,执行 Web 服务调用以及所有正常的事情(数据库调用等) .相信我,它已经优化了……我们使用 ANTS 性能分析器来找到优化代码的瓶颈。在 SQL 太慢的地方,我们集成了 mongo 以实现扁平化/缓存数据,以便更快地查询。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-01
  • 1970-01-01
相关资源
最近更新 更多