#1 2019-12-20 06:23:01

psla314
Member
Registered: 2016-11-17
Posts: 5

TSQLHttpServer - Blocking acting like single thread running on windows

Hi

I am new to MORmot, but i wrote a simple server to handle rest call from browser and it works well. (code below)
However it seems like there is only 1 thread or its blocked.
I can make 10 calls at same time from browser to same endpoint and each one will only run in sequential fashion.
I even changed server calls to only log a message and then sleep for 5 seconds, and still the second call would only run after the first one finished.

I am running on windows 10 using free pascal to compile/run the MORmot and using javascript in chrome to send the requests on same machine.

Is there a trick to enable the 32 threads in server, or is it just windows being difficult ?
ps. I am running an older version of Mormot (1.18)

TServiceServer = class(TSQLRestServerFullMemory)   
...
procedure StartRestServer;
var
   iPort : Integer;
   bConnected : Boolean;
const
   c_StartPort = 8001;
begin
   Model := TSQLModel.Create([], 'data');
   iPort := c_StartPort;
   DB := TServiceServer.Create(Model, false);
   bConnected := false;
   while not bConnected and (iPort < c_StartPort+10) do
   begin
      try
        Server := TSQLHttpServer.Create(AnsiString(inttostr(iPort)),[DB],'+',HTTP_DEFAULT_MODE);
        bConnected := True;
        DebugLog('OAS Listening on Port '+inttostr(iPort));
      except
         DebugLog('Port '+inttostr(iPort)+' Used.');
         inc(iPort);
      end;
   end;
   Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
end;   

Thanks
Peter

Offline

#2 2019-12-20 08:27:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,263
Website

Re: TSQLHttpServer - Blocking acting like single thread running on windows

By default, the mORMot's http.sys server uses 32 threads.
There is an optional ServerThreadPoolCount parameter to the TSQLHttpServer.Create constructor with number of 32 threads.

Did you register the http.sys URI first?

Offline

#3 2020-01-05 22:59:48

psla314
Member
Registered: 2016-11-17
Posts: 5

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Yes i know there are 32 threads created by default, but i am wondering why the calls seem to be happening in a sequential fashion. (like there is only a single thread or its blocking the other threads)

I thought the URIs should be automatically registered using the HTTP_DEFAULT_MODE of TSQLHpptServer ?

Offline

#4 2020-01-06 16:17:06

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,263
Website

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Registration needs the administration rights to succeed on Windows.

It is needed only once, then next runs won't need to register, so the server can run with lower/normal user rights.

Offline

#5 2020-01-14 06:18:19

psla314
Member
Registered: 2016-11-17
Posts: 5

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Ok I tried running my exe as administrator and still no go. I can see there are 32 threads created for the process in the task manager, however here is the waterfall graph from chrome dev tools
(I also updated to latest version of mormot from github)
I can confirm that the exe loads httpapi.dll as well from C:\WINDOWS\SYSTEM32\httpapi.dll


Waterfall

As you can see the first 6 of the calls to mormot happen pretty much at once, but each response is delayed by the 3000 sleep in my published procedure after the previous call ends
( Chrome will only run 6 http request at a time, so that explains why the 7th call waits until the first one is done)

   TServiceServer = class(TSQLRestServerFullMemory)
   published
      procedure doit(Ctxt: TSQLRestServerURIContext);
   end;     

The doit function just parses the parameters and calls

      DebugLog('Getting: ' + string(src));
      sleep(3000); 

      Ctxt.Returns(s);

I would have expected all the sleeps to happen in parallel in each thread and return the results all around the same time.

Am I right in expecting this ?

Thanks
Peter

Offline

#6 2020-01-14 08:50:19

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,547
Website

Re: TSQLHttpServer - Blocking acting like single thread running on windows

All the sleeps must happen in parallel.

To eliminate possible problems in your code you can start your experiments with a plain web server - see "Samples/09 - HttpApi web server" (just add a sleep inside TTestServer.Process)

Offline

#7 2020-01-14 10:43:58

Eugene Ilyin
Member
From: milky_way/orion_arm/sun/earth
Registered: 2016-03-27
Posts: 132
Website

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Try to analyse Server logs.
Each thread has separate thead char symbol in logs (or you can enable one log file per thread).
Also you can check/log/return current ThreadID and ensure that all requests processed in parallel.
The other thing is that most modern browsers allow six connections per domain.
Most older browsers allow only two connections per domain.
The Section 8.1.4 in HTTP 1.1 protocol states that single-user clients should not maintain more than two connections with any server or proxy (this is the reason for browser limits).

Offline

#8 2020-01-14 11:49:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,263
Website

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Are you sure it is not Chrome which serializes all the calls on a single connection?

Offline

#9 2020-01-24 03:31:07

psla314
Member
Registered: 2016-11-17
Posts: 5

Re: TSQLHttpServer - Blocking acting like single thread running on windows

Thanks for all your help.
I found the issue it was not related to mOrmot.
The issue was caused by the client calls.
This thread can be closed.

Offline

Board footer

Powered by FluxBB