You are not logged in.
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
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?
Online
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
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.
Online
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
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
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
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
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