Indy non-blocking HTTP client, setup stress-test to compare performance of thread-based approach and non-blocking coroutine-based approach.

Indy non-blocking HTTP client, setup stress-test to compare performance of thread-based approach and non-blocking coroutine-based approach.


I've released TAioIdIOHandlerSocket (source code here: https://github.com/Purik/AIO/blob/master/AioIndy.pas) that make standart Indy components non-blocking.

You can see full code example here: https://github.com/Purik/AIO/blob/master/Demos/HowTo/HowTo.HttpClient.dpr

Thread-based implementation take 14 sec 469 msec on my PC
Non-blocking implementation take 6 sec 552 msec

Writeln('Workers Count = ' + IntToStr(PARALLEL_NUM));
Writeln('Using blocking Indy sockets');
Stamp := Now;
// Threads with blocking sockets
Threads := TList.Create;
try
for I := 0 to PARALLEL_NUM-1 do begin
Th := TThread.CreateAnonymousThread(procedure
var
Client: TIdHTTP;
Response: string;
I: Integer;
begin
Client := TIdHTTP.Create(nil);
try
Client.IOHandler := TIdIOHandlerStack.Create(Client);
Client.HandleRedirects := True;
for I := 1 to STRESS_FACTOR do begin
Response := Client.Get('http://uit.fun/aio');
Assert(Response <> '');
end;
finally
Client.Free;
end;
end
);
Threads.Add(Th);
Th.FreeOnTerminate := False;
Th.Start;
end;
// Join
for I := 0 to PARALLEL_NUM-1 do begin
Threads[I].WaitFor;
Threads[I].Free;
end;
PrintTimeout(Stamp, Now);
finally
Threads.Free
end;

Writeln('Using non-blocking Aio IO handler');
Stamp := Now;
for I := 0 to PARALLEL_NUM-1 do begin
G := TSymmetric.Create(procedure
var
Client: TIdHTTP;
Response: string;
I: Integer;
begin
Client := TIdHTTP.Create(nil);
try
//Write('*');
Client.IOHandler := TAioIdIOHandlerSocket.Create(Client);
Client.HandleRedirects := True;
for I := 1 to STRESS_FACTOR do begin
Response := Client.Get('http://uit.fun/aio');
Assert(Response <> '');
end;
finally
Client.Free;
end;
end
);
Greenlets[I] := G;
end;
try
Greenlets.Join(INFINITE, True);
except
on E: Exception do begin
Writeln('Error: ' + E.Message);
end
end;
PrintTimeout(Stamp, Now);


Next step: make non-blocking implementation for SSL Http IOHandler

Full docs: https://aio.uit.fun/

Comments

  1. On Windows IOCP will give highest perf and Indy's Fibers used them.

    ReplyDelete
  2. Павел Миненков I havent had a chance to fully grok it yet, but it looks interesting from the surface. Im really tied up now and 3 weeks late on a delivery, but if you can ping me in a week or so....

    ReplyDelete

Post a Comment