这是为什么网页API控制器没有并发? [英] Why is this web api controller not concurrent?

查看:146
本文介绍了这是为什么网页API控制器没有并发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方法内的Web API控制器:

I have a Web API Controller with the following method inside:

public string Tester()
{
    Thread.Sleep(2000);

    return "OK";
}

当我把它的10倍(使用招),我希望所有的10调用〜2秒后返回。然而,电话分别为2,4,8 ...... 20秒后返回。
什么是从并行运行阻止它?我该如何解决呢?

When I call it 10 times (Using Fiddler), I expect all 10 calls to return after ~ 2 seconds. However the calls return after 2,4,8...20 seconds, respectively. What is blocking it from running concurrently? How do I fix that?

做定期的控制器行为相同网络的API控制器?

Do regular Controllers behave the same as web-api controllers?

推荐答案

你描述的相匹配的ASP.NET会话状态的默认行为,可以通过在web.config中禁用它来解决。

What you describe matches the default behavior of the ASP.NET Session State and can be solved by disabling it in web.config.

访问ASP.NET会话状态是每个会话,这意味着如果两个不同的用户进行并发请求,获得每个单独会话同时授予独占。但是,如果两个并发请求为同一会议上提出的(通过使用相同的SessionID值),第一个请求获取会话信息的独占访问。第二个请求的第一个请求完成后才能执行。 (如果因为第一个请求超出锁定超时的信息独占锁被释放的第二次会议,也可以访问)。如果在@ Page指令中的EnableSessionState值设置为只读,为只读的请求会话信息不会导致对会话数据的排他锁。但是,只读会话数据的请求仍然可能需要等待一个锁被读写请求会话数据清除设置。

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. (The second session can also get access if the exclusive lock on the information is freed because the first request exceeds the lock time-out.) If the EnableSessionState value in the @ Page directive is set to ReadOnly, a request for the read-only session information does not result in an exclusive lock on the session data. However, read-only requests for session data might still have to wait for a lock set by a read-write request for session data to clear.

来源: ASP.NET会话状态概述

这篇关于这是为什么网页API控制器没有并发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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