ASP.Net并通过开放连接监听事件 - 是否可以提高并发执行线程的数量?

时间:2011-05-14 16:04:24

标签: asp.net iis limit threadpool connection

我正在尝试使用IIS来托管事件驱动的Web应用程序。假设我想将它用于聊天类应用程序。

而不是每隔一秒左右轮询一次(延迟)我希望保留一个打开的连接到我的应用程序,一旦有数据可用就会返回。

问题是我无法执行超过10个并发线程。

我将MaxThreads设置为5000/5000,MaxConcurrentRequestsPerCpu设置为5000,QueueLimit默认为5000,MaxConcurrentThreadsPerCPU为0(无界限)。

唯一的问题是默认情况下DefaultConnectionLimit似乎是12,我似乎无法在web.config中更改它。我已设法在global.asax Application_Start中设置它,但我不知道在那时设置它是否为时已晚。它在文档中说它不会影响已经初始化的ServicePoints。

<system.net>
  <connectionManagement>
     <add address="*" maxconnection="100" />
  </connectionManagement>
</system.net>

以上是我在web.config中的内容(涉及DefaultConnectionLimit)。

5/14/2011 3:34:45 PM with timediff 0         :  Entered method with threadId: 6, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4998 and DefaultConnectionLimit is 1500
5/14/2011 3:34:45 PM with timediff 0         :  Entered method with threadId: 5, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4998 and DefaultConnectionLimit is 1500
5/14/2011 3:34:46 PM with timediff 0.5       :  Entered method with threadId: 7, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4997 and DefaultConnectionLimit is 1500
5/14/2011 3:34:47 PM with timediff 1.5       :  Entered method with threadId: 8, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4996 and DefaultConnectionLimit is 1500
5/14/2011 3:34:48 PM with timediff 2.5       :  Entered method with threadId: 9, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4995 and DefaultConnectionLimit is 1500
5/14/2011 3:34:49 PM with timediff 3.5       :  Entered method with threadId: 10, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4994 and DefaultConnectionLimit is 1500
5/14/2011 3:34:50 PM with timediff 4.5       :  Entered method with threadId: 12, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4993 and DefaultConnectionLimit is 1500
5/14/2011 3:34:51 PM with timediff 5.5       :  Entered method with threadId: 13, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4992 and DefaultConnectionLimit is 1500
5/14/2011 3:34:52 PM with timediff 6.5       :  Entered method with threadId: 14, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4991 and DefaultConnectionLimit is 1500
5/14/2011 3:34:52 PM with timediff 7         :  Entered method with threadId: 15, MaxThreads is 5000/5000, MaxConcurrentRequestsPerCPU is 5000, MaxConcurrentThreadsPerCPU is 0, MinThreads is 1, AvailableThreads is 4990 and DefaultConnectionLimit is 1500
5/14/2011 3:36:45 PM with timediff 120       :      Exiting method with threadId: 6
5/14/2011 3:36:45 PM with timediff 120       :      Exiting method with threadId: 5
5/14/2011 3:36:46 PM with timediff 120.5     :      Exiting method with threadId: 7
5/14/2011 3:36:47 PM with timediff 121.5     :      Exiting method with threadId: 8
5/14/2011 3:36:48 PM with timediff 122.5     :      Exiting method with threadId: 9
5/14/2011 3:36:49 PM with timediff 123.5     :      Exiting method with threadId: 10

以上是我为测试线程并发而生成的日志文件的摘录。它只是一个MVC动作方法,其中有120秒的睡眠时间。 Timediff是从第一个请求到记录当前请求的区别。

如您所见,AvailableThreads下降到4990,然后在继续之前等待其他线程退出。请求之间的延迟似乎是Fiddlers故障(我用它来加载测试)。

我也尝试过BadBoy发出相同的请求,它也受到10个线程限制的影响。

这是因为连接来自同一个客户端吗?我错过了其他一些限制吗?无可否认,很难对不同的主机进行负载测试。

1 个答案:

答案 0 :(得分:1)

如果您在Windows 7下测试您的应用程序。它有10个并发连接限制。此外,您可能会发现(IISTuner)有用。