동시 HttpWebRequest의 최대 수
저는 웹 앱을 스트레스 테스트하고 있으며 여러 스레드를 회전시키고 각각에 대해 웹 요청을 보내는 Windows 테스트 프로그램을 설정했습니다.
문제는 다음과 같은 출력을 얻는 것입니다.
01/09/09 11:34:04 Starting new HTTP request on 10
01/09/09 11:34:04 Starting new HTTP request on 11
01/09/09 11:34:04 Starting new HTTP request on 13
01/09/09 11:34:05 Starting new HTTP request on 14
01/09/09 11:34:05 Starting new HTTP request on 11
01/09/09 11:34:05 11 has finished!
01/09/09 11:34:05 Starting new HTTP request on 13
01/09/09 11:34:05 13 has finished!
01/09/09 11:34:05 Starting new HTTP request on 14
01/09/09 11:34:05 14 has finished!
01/09/09 11:34:05 Starting new HTTP request on 11
01/09/09 11:34:05 11 has finished!
01/09/09 11:34:05 Starting new HTTP request on 14
01/09/09 11:34:05 14 has finished!
01/09/09 11:34:05 Starting new HTTP request on 13
01/09/09 11:34:05 13 has finished!
01/09/09 11:34:05 Starting new HTTP request on 15
01/09/09 11:34:06 Starting new HTTP request on 11
01/09/09 11:34:06 11 has finished!
01/09/09 11:34:06 Starting new HTTP request on 14
01/09/09 11:34:06 14 has finished!
100 개를 생성하더라도 최대 5 개의 스레드가있는 것처럼 보입니다.
int numberOfThreads = Convert.ToInt32(txtConcurrentThreads.Text);
List<BackgroundWorker> workers = new List<BackgroundWorker>();
for (int N = 0; N < numberOfThreads; N++)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
workers.Add(worker);
}
foreach(BackgroundWorker worker in workers)
{
worker.RunWorkerAsync();
}
누가 무슨 일이 일어나고 있는지 나를 깨달을 수 있습니까?
감사
편집 : 제안대로 httpwebrequest 대신 5 초 동안 잠을 자면 더 많은 스레드가 발생하지만 예상했던 것만 큼 많이 발생하지는 않습니다.
01/09/09 11:56:14 Starting new HTTP request on 7
01/09/09 11:56:14 Starting new HTTP request on 11
01/09/09 11:56:15 Starting new HTTP request on 12
01/09/09 11:56:15 Starting new HTTP request on 13
01/09/09 11:56:16 Starting new HTTP request on 14
01/09/09 11:56:16 Starting new HTTP request on 15
01/09/09 11:56:17 Starting new HTTP request on 16
01/09/09 11:56:17 Starting new HTTP request on 17
01/09/09 11:56:18 Starting new HTTP request on 18
01/09/09 11:56:19 Starting new HTTP request on 7
01/09/09 11:56:19 7 has finished!
01/09/09 11:56:19 Starting new HTTP request on 11
01/09/09 11:56:19 11 has finished!
01/09/09 11:56:19 Starting new HTTP request on 19
01/09/09 11:56:20 Starting new HTTP request on 20
01/09/09 11:56:20 Starting new HTTP request on 12
01/09/09 11:56:20 12 has finished!
여전히 매초마다 2 개의 스레드 만받는 것 같습니다. Console.WriteLine이 문제가 될 수 있다고 생각합니까?
편집 : 나는 설정
ThreadPool.SetMinThreads(100, 4);
과
System.Net.ServicePointManager.DefaultConnectionLimit = 100;
다음 결과를 얻었습니다.
01/09/09 14:00:07 Starting new HTTP request on 11
01/09/09 14:00:07 Starting new HTTP request on 81
01/09/09 14:00:07 Starting new HTTP request on 82
01/09/09 14:00:07 Starting new HTTP request on 79
01/09/09 14:00:07 Starting new HTTP request on 83
01/09/09 14:00:07 Starting new HTTP request on 84
01/09/09 14:00:07 Starting new HTTP request on 85
01/09/09 14:00:07 Starting new HTTP request on 87
01/09/09 14:00:07 Starting new HTTP request on 88
...
01/09/09 14:00:07 84 has finished! Took 323.0323 milliseconds
01/09/09 14:00:08 88 has finished! Took 808.0808 milliseconds
01/09/09 14:00:08 96 has finished! Took 806.0806 milliseconds
01/09/09 14:00:08 94 has finished! Took 806.0806 milliseconds
01/09/09 14:00:08 98 has finished! Took 801.0801 milliseconds
01/09/09 14:00:08 80 has finished! Took 799.0799 milliseconds
01/09/09 14:00:08 86 has finished! Took 799.0799 milliseconds
01/09/09 14:00:08 92 has finished! Took 799.0799 milliseconds
01/09/09 14:00:08 100 has finished! Took 812.0812 milliseconds
01/09/09 14:00:08 82 has finished! Took 1010.101 milliseconds
so was able to push out a whole lot of web requests concurrently. Which seemed to queue (calling out to an STA COM+ server) so that's what I expected.
Thanks for your help
Are all (or most) of your requests going to the same host by any chance? There's a built-in limit on a per-host basis. You can change this in app.config in the system.Net connectionManagement element.
The other thing is that the thread pool only ramps up its number of threads gradually - it starts a new thread every half second, IIRC. Could that be what you're seeing? Try getting rid of HttpWebRequest
from the equation - just sleep for a couple of seconds instead...
I suspect the latter problem is the one you're initially running into, but the first one is going to cause you problems as well.
There is a limit in the number of simultaneous outgoing HTTP connections. I think you can control this by using the System.Net.ServicePointManager.DefaultConnectionLimit
static property before creating the HttpWebRequest
objects.
I haven't heard much about this for .NET Core. ServicePointManager was not included in .NET Core 1, but appears to be back again in version 2. However, for the HttpClient, you can also set the maximum number of connections like this:
new HttpClient(new HttpClientHandler
{
MaxConnectionsPerServer = 100
})
If i write below tag in windows config than will it be executed every time when below code is executed. So every time below code is executed i will be allowed to have max 1000000 no of parallel request/response.
HttpWebRequest POSTRequest = (HttpWebRequest)WebRequest.Create("http://yahoo.com");
Tag
<connectionManagement>
<clear/>
<add address="*" maxconnection="1000000" />
</connectionManagement>
참고URL : https://stackoverflow.com/questions/1361771/max-number-of-concurrent-httpwebrequests
'development' 카테고리의 다른 글
FirebaseInstanceId.getInstance (). getToken ()이 더 이상 사용되지 않으므로 이제 사용할 사항 (0) | 2020.11.30 |
---|---|
내 SQL Server를 망치고있는 것이 무엇인지 어떻게 알 수 있습니까? (0) | 2020.11.30 |
친구 함수와 정적 멤버 함수를 어디에서 사용 하시겠습니까? (0) | 2020.11.30 |
Excel 통합 문서의 모든 워크 시트를 data.frames가있는 R 목록으로 읽습니다. (0) | 2020.11.29 |
DrawerLayout에서 제스처 리스너 비활성화 (0) | 2020.11.29 |