简体   繁体   English

在许多异步请求期间实际上有多少个同时(并发)连接处于活动状态

[英]How many simultaneous (concurrent) connections are actually active during a many async request

My understanding is the point of Task is to abstract out threads, and that a new thread is not guaranteed per Task . 我的理解是Task是抽象出线程,并且不能保证每个Task都有新线程。

I'm debugging in VS2010, and I have something similar to this: 我在VS2010中进行调试,并且与此类似:

var request = WebRequest.Create(URL);

Task.Factory.FromAsync<WebResponse>(
    request.BeginGetResponse, 
    request.EndGetResponse).ContinueWith( 
    t => {  /* ... Stuff to do with response ... */ });

If I make X calls to this, eg start up X async web requests, how am I to calculate how many simultaneous (concurrent) connections are actually being made at any given time during execution? 如果我对此进行了X调用,例如启动X异步Web请求,我如何计算在执行过程中的任何给定时间实际建立了多少个同时(并发)连接? I assume that somehow it is opening only the max it can (in the case X is very high), and the other Tasks are blocked while waiting? 我假设它以某种方式仅打开了它可以打开的最大值(在X很高的情况下),而其他Tasks在等待时被阻止了?

Any insight into this or how I can check with the debugger to determine how many active (open) connections are existent at a given point in execution would be great. 任何对此的见解或如何与调试器一起确定在执行的给定点存在多少活动(打开)连接的任何见解都将是非常好的。

Basically, I'm wondering if it's handled for me, or if I have to take special consideration so that I do not appear to be attacking a server? 基本上,我想知道是否为我解决了该问题,或者是否需要特别考虑以免我似乎没有在攻击服务器?

This won't really be specific to Task . 这实际上不是特定于Task The external connection is created as soon as you make your call to Task.Factory.FromAsync . 调用Task.Factory.FromAsyncTask.Factory.FromAsync立即创建外部连接。 The "task" that the Task is performing is simply waiting for the response to get back (not for it to be sent in the first place). Task正在执行的“任务”只是在等待响应返回(而不是首先发送)。 Thus the call to BeginGetResponse will fail if your machine is unable to send any more requests, and the response will contain an error message if the server is rejecting your requests due to their belief that you are flooding them. 因此,如果您的计算机无法再发送任何请求,对BeginGetResponse的调用将失败,并且如果服务器由于认为您正在泛滥它们而拒绝了请求,则响应将包含一条错误消息。

The only real place that Task comes into play here is the amount of time between when the response is actually received by the machine and when your continuation runs. Task在这里真正起作用的唯一实际位置是机器实际收到响应到继续运行之间的时间间隔。 If you are getting lots of responses, or otherwise have lots of work in the thread pool, it could take some time for it to get to your continuation. 如果您收到大量响应,或者线程池中有大量工作要做,那么可能需要一些时间才能继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM