asp.net的MVC 4控制器并行执行多个ajax调用 [英] asp.net mvc 4 controller execute multiple ajax calls in parallel

查看:798
本文介绍了asp.net的MVC 4控制器并行执行多个ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net MVC 4控制器多数民众赞成方法是通过AJAX调用。

I have an asp.net MVC 4 controller thats methods are called via ajax.

的问题是,所述AJAX请求由控制器按顺序处理。 这会导致性能问题作为装载页是所有Ajax请求的总和,而不是最长Ajax请求的时间。

The problem is that the ajax requests are handled sequentially by the controller. This causes performance issues as the time to load the page is the sum of all ajax requests and not the longest ajax request.

要证明这一点,我把一个破发点中的第一个(ReadOverview8Week)的方法。 每一种方法都有〜600毫秒执行的个性。

To demonstrate this, I put a break point in the first ("ReadOverview8Week") method. Each of these methods take ~600ms to execute individuality.

http://i.stack.imgur.com/HhtEX.png

我怎样才能让并行三个请求控制器响应? 我使用IIS 8。

How can I make the controller respond to all three requests in parallel? I am using iis 8.

这是Ajax请求(从剑道UI数据源)

This is the ajax request (from kendo ui dataSource)

.DataSource(dataSource => dataSource.Ajax()
   .Read(read => read.Action("ReadAllSitesOverview", "AbuseCase").Type(HttpVerbs.Get))

感谢。

推荐答案

你面对是造成道路ASP.NET的问题是管理会议。这里最重要的组成部分,从 ASP.NET会话状态概述并发请求和会话状态的部分):

The issue you are facing is caused by the way ASP.NET is managing session. Here is the most important part from ASP.NET Session State Overview (Concurrent Requests and Session State section):

访问ASP.NET会话状态是专属每个会话,这意味着,如果两个不同的用户作出并发请求,获得每个单独会话并发理所当然的。但是,如果两个并发请求为同一会议上提出的(使用相同的SessionID值),第一个请求获取独占访问会话信息。第二个请求的第一个请求完成后才能执行。

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.

您可以解决你的问题,如果你的行动并不需要访问会话。如果是这样的话,你可以装饰与控制器<一href="http://msdn.microsoft.com/en-us/library/system.web.mvc.sessionstateattribute%28v=vs.98%29.aspx">SessionStateAttribute属性:

You can resolve your issue if your actions doesn't require access to session. If that is the case, you can decorate the controller with SessionStateAttribute attribute:

[SessionState(SessionStateBehavior.Disabled)]

此方式,控制器将不必等待会话

This way the controller will not have to wait for session.

如果你的行为需要只读访问会话,你可以尝试使用 SessionStateBehavior.ReadOnly 值。这会不会导致一个排它锁,但该请求仍须等待锁被读写的要求设置。

If your actions require only read access to session, you can try using the SessionStateBehavior.ReadOnly value. This will not result in an exclusive lock but the request will still have to wait for a lock set by a read-write request.

这篇关于asp.net的MVC 4控制器并行执行多个ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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