Delphi: Why does IdHTTP.ConnectTimeout make requests slower?

I found that when setting the ConnectTimeoout property for the TIdHTTP component, it makes requests (GET and POST) about 120 ms slower?

Why is this, and can I somehow avoid this?

Env: D2010 with Indy components sent, all updates are installed for D2010. OS is WinXP (32 bit) SP3 with most patches ...

My sync procedure:

Procedure DoGet; Var Freq,T1,T2 : Int64; Cli : TIdHTTP; S : String; begin QueryPerformanceFrequency(Freq); Try QueryPerformanceCounter(T1); Cli := TIdHTTP.Create( NIL ); Cli.ConnectTimeout := 1000; // without this we get < 15ms!! S := Cli.Get('http://127.0.0.1/empty_page.php'); Finally FreeAndNil(Cli); QueryPerformanceCounter(T2); End; Memo1.Lines.Add('Time = '+FormatFloat('0.000',(T2-T1)/Freq) ); End; 

With the ConnectTimeout installed in the code, I get avg. times 130-140 ms, without it about 5-15 ms ...

+7
delphi indy
source share
1 answer

When ConnectTimeout is zero (and TIdAntifreeze not valid), Indy just connects. Otherwise, TIdIOHandlerStack.ConnectClient calls DoConnectTimeout , which creates a new thread to make the connection, and the calling thread falls asleep and processes TIdAntifreeze operations, waiting for connection to. If there is no connection at the timeout, it throws an exception.

Themes are not free, and the calling thread will always sleep before checking if the communication thread has completed its task. The default sleep duration is 125 ms . (To use something else, activate TIdAntifreeze and set its IdleTimeout property below 125.)

+14
source

All Articles