server: Delphi VCL app, using TIdHTTPWebBrokerBridge, TIdServerIOHandlerSSLOpenSSL with SSLOptions.CertFile/KeyFile/OnGetPassword assigned. In WebModule, a WebActionItem.OnAction tied to /some/path returns a tiny amount of characters from the db. The whole OnAction handler takes cca 50 ms
client: Delphi (test) VCL app using TRestClient and TRestRequest (method=rmPost) accessing https://localhost:NNNN/some/path. First TRequest.Execute takes over 2000 ms, subsequent ones take cca 1100 ms to return the said tiny amount of characters.
client 2: Delphi (test) VCL app, using TIdHttp with IOHandler= instance of TIdSSLIOHandlerSocketOpenSSL. The execution of the request is a simple TIdHttp.Post(https://localhost:NNNN/some/path ..) - the first one takes slightly under 1000ms and subsequent ones cca 60 ms
Server runs interactively on localHost as do both clients. Both clients return the same correct result as expected. The server side timing does not change from one client to the next.
So my question is obviously - how can this be ? What could I be doing wrong in TRestRequest usage ? I'll provide more details if needed, but for starters I just want to get an idea whether Delphi TRestClient has any known problems ..
EDIT: Simply re-reading the question, I noticed the similarity in TIdHttp.Post first timing and TRestRequest.Execute subsequent timings. Could it be that TRestRequest re-creates SSL IOHandler for each call and loses all the caching benefits on performance?
EDIT2: TRESTRequest.Execute ends up in System.Net.HttpClient.Win.TWinHTTPClient.DoExecuteRequest() which spends all the time calling into winhttp.dll:WinHttpSendRequest(), so this is obviously an external problem (Windows Server 2019, WinHttp.dll version 10.0.17763.4492)..here the docs in case anyone has an idea what is slowing this down https://learn.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpsendrequest
also this is worrying: https://microsoft.public.winhttp.narkive.com/x5OOQlt0/winhttp-15-second-delay-sending-my-data-caused-by-windowsupdate