I would like to make four simultaneous HTTPS GET requests to a web server. I have created a thread to use a TScHttpWebRequest object to generate the GET call.
If I run just a single thread, the GetResponse() method returns in ~500ms. All good so far. But if I start four threads in parallel, I note the following:
- The first GetResponse() to return does so after ~4000ms
- Subsequent threads return at 500ms intervals after the first one.
In other words, there's an unexplained delay before things start working, and then everything runs in sequence anyway: there seems to be something stopping the TScHttpWebRequest objects running in parallel.
Have I missed something? Or is there a better way to make parallel calls to a Web server?
Code: Select all
//-- Thread Execute() function (error checking code not shown)
void TMyThread::Execute()
{
// Declarations
TMemoryStream* memStream = new TMemoryStream();
TScHttpWebRequest* Request = new TScHttpWebRequest(NULL);
TScHttpWebResponse* Response;
// Execute HTTPS "GET" call
Request->RequestUri = sURL; // sURL is defined elsewhere
Response = Request->GetResponse();
// Process the response
Response->ReadToStream(memStream);
memStream->SaveToFile(sFilename); //sFilename is defined elsewhere
// Tidy up
Request->Disconnect();
delete Response;
}