- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不明白,为什么 async/await 不能解决 IIS 线程的问题。
我发现,当我使用 IIS 时,我们对 IIS 线程的限制等于 10,而对 IIS Express 则没有限制。
我在 HomeController 中添加了 2 个方法来重复这个问题。其中一种(方法)使用Thread.Sleep,另一种使用async/await。
当然,我使用记录器(NLog)来更详细地描述这个问题。
我使用 apache-jmeter-3.0 对一个 url 进行 100 个并行请求作为压力测试。
当 IIS 的测试执行时间大致相同而 IIS Express 的测试执行时间不同时,我感到非常惊讶。
来自 HomeController 的一些代码
[SessionState(SessionStateBehavior.Disabled)]
public class HomeController : Controller
{
private const int _waitTimeout = 30000;
private const string _beginFmt = "Begin method; Count = {0}; OperId = {1};";
private const string _endFmt = "End method ; Count = {0}; OperId = {1};";
private static volatile int _counter = 0;
private static Logger _logger = LogManager.GetCurrentClassLogger();
public JsonResult GetWithThreadSleep()
{
Guid operId = Guid.NewGuid();
_logger.Info(_beginFmt, Interlocked.Increment(ref _counter), operId);
Thread.Sleep(_waitTimeout);
_logger.Info(_endFmt, Interlocked.Decrement(ref _counter), operId);
return Json(null, JsonRequestBehavior.AllowGet);
}
public async Task<JsonResult> GetWithTaskAwait()
{
Guid operId = Guid.NewGuid();
_logger.Info(_beginFmt, Interlocked.Increment(ref _counter), operId);
await Task.Delay(_waitTimeout);
_logger.Info(_endFmt, Interlocked.Decrement(ref _counter), operId);
return Json(null, JsonRequestBehavior.AllowGet);
}
}
日志格式
<target xsi:type="File"
name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${threadid} @ ${date:format=HH\:mm\:ss} @ ${level} @${aspnet-sessionid} @ ${message} @ ${callsite:className=False}"
/>
测试场景一:我向方法 GetWithTaskAwait 发送 100 个并行 GET 请求,并期望请求的处理速度快于 5 分钟,因为线程应该被重用。
但事实并非如此。测试持续时间为 5 分钟
1 @ 23:43:54 @ Info @ @ MVC Count = 1; @ .ctor
1 @ 23:43:54 @ Info @ @ APP Count = 1; @ Application_Start
11 @ 23:44:06 @ Info @ @ MVC Count = 2; @ .ctor
...
13 @ 23:45:36 @ Info @ @ End method ; Count = 8; OperId = 28818fba-5535-4c01-9d6d-5efa3943cf37; @ MoveNext
19 @ 23:45:36 @ Info @ @ Begin method; Count = 9; OperId = c3cd3339-ec29-4625-adb9-62d5c72831b0; @ GetWithTaskAwait
12 @ 23:45:36 @ Info @ @ End method ; Count = 9; OperId = d1686c05-ca7a-400c-8c17-43dfb7b9218a; @ MoveNext
16 @ 23:45:36 @ Info @ @ Begin method; Count = 10; OperId = c1ec5517-649c-4733-9db3-e666e648abae; @ GetWithTaskAwait
13 @ 23:45:36 @ Info @ @ End method ; Count = 9; OperId = fbcfc9d9-fb84-456b-82a1-a0d593ef0815; @ MoveNext
...
26 @ 23:49:06 @ Info @ @ End method ; Count = 8; OperId = 766d4bc5-3739-4e20-a242-1f114dd44442; @ MoveNext
22 @ 23:49:06 @ Info @ @ End method ; Count = 7; OperId = 0ba18b30-11c9-49fe-8c94-40bbfa817e88; @ MoveNext
16 @ 23:49:06 @ Info @ @ End method ; Count = 9; OperId = 6d7afd57-6128-4bee-bf32-92de7cfc6a34; @ MoveNext
26 @ 23:49:06 @ Info @ @ End method ; Count = 6; OperId = 4c022744-9932-4f94-be1d-b982e36460f2; @ MoveNext
22 @ 23:49:06 @ Info @ @ End method ; Count = 5; OperId = 05476e6a-106f-4da5-b99b-098b90dbab89; @ MoveNext
16 @ 23:49:07 @ Info @ @ End method ; Count = 4; OperId = 3aba1ad2-56b0-4cf5-8aee-7e918eca9fba; @ MoveNext
27 @ 23:49:07 @ Info @ @ End method ; Count = 3; OperId = ef972cdd-7992-4816-9452-ecabaf189767; @ MoveNext
15 @ 23:49:07 @ Info @ @ End method ; Count = 2; OperId = 9a0f735e-bf6b-4217-b2ef-8abd9ce01d27; @ MoveNext
30 @ 23:49:07 @ Info @ @ End method ; Count = 0; OperId = cc75b44a-4e8d-4534-9906-40bddc027267; @ MoveNext
33 @ 23:49:07 @ Info @ @ End method ; Count = 1; OperId = bbef36b3-051b-444d-858a-2766bcfcd12b; @ MoveNext
...
26 @ 23:49:49 @ Info @ @ MVC Count = 10; @ Dispose
30 @ 23:50:19 @ Info @ @ MVC Count = 9; @ Dispose
16 @ 23:50:49 @ Info @ @ MVC Count = 8; @ Dispose
测试场景二:我向方法 GetWithThreadSleep 发送 100 个并行 GET 请求,并预计这些请求将在 5 分钟内同等得到处理,因为线程不应该重用。
1 @ 00:15:41 @ Info @ @ MVC Count = 1; @ .ctor
1 @ 00:15:41 @ Info @ @ APP Count = 1; @ Application_Start
11 @ 00:16:14 @ Info @ @ MVC Count = 2; @ .ctor
...
15 @ 00:16:15 @ Info @ @ Begin method; Count = 8; OperId = cedb5075-405c-4c23-93cb-388dc34537ba; @ GetWithThreadSleep
17 @ 00:16:15 @ Info @ @ MVC Count = 10; @ .ctor
17 @ 00:16:15 @ Info @ @ Begin method; Count = 9; OperId = 777d7464-f900-48c1-991f-ef8c8f7e6e86; @ GetWithThreadSleep
18 @ 00:16:16 @ Info @ @ MVC Count = 11; @ .ctor
18 @ 00:16:16 @ Info @ @ Begin method; Count = 10; OperId = f9b4b717-94a5-4196-958f-c1234d19514c; @ GetWithThreadSleep
12 @ 00:16:45 @ Info @ @ End method ; Count = 8; OperId = 9e40acd4-888f-4656-a5a3-c5a1d210cc88; @ GetWithThreadSleep
5 @ 00:16:45 @ Info @ @ End method ; Count = 9; OperId = b068e03e-37e9-446e-ad42-c9ab4c30da93; @ GetWithThreadSleep
11 @ 00:16:45 @ Info @ @ End method ; Count = 7; OperId = 22e510e5-62f7-4bc8-8ab0-fdeb3080e250; @ GetWithThreadSleep
...
18 @ 00:21:15 @ Info @ @ End method ; Count = 2; OperId = 169ef436-6b27-4f4c-a3ca-0b18a5a796cf; @ GetWithThreadSleep
13 @ 00:21:16 @ Info @cubgm2zsojblkhrwwpixaaej @ End method ; Count = 1; OperId = ee346be8-17c5-45ac-88b5-67e724250bbf; @ GetWithThreadSleep
12 @ 00:21:16 @ Info @ @ End method ; Count = 0; OperId = 68d5deaa-95d6-4627-a129-144ffafcc2ef; @ GetWithThreadSleep
13 @ 00:22:11 @ Info @ @ MVC Count = 10; @ Dispose
9 @ 00:22:41 @ Info @ @ MVC Count = 9; @ Dispose
重要信息:
您可以从 GitHub 下载完整的解决方案
最佳答案
桌面操作系统 (Win 7/8/10) 上的 IIS 会将您的请求限制为 10 个并发。
在服务器操作系统 (2008/2012/2016) 上,不存在该限制。
在 IIS Express 上也不存在该限制。
设置此限制的原因是您不会在桌面操作系统上将 IIS 用于生产目的。
https://weblogs.asp.net/owscott/windows-8-iis-8-concurrent-requests-limit
关于asp.net - 为什么 async wait 在 IIS 上不起作用,但在 IIS Express 上起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328703/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!