I’ve httpApi function server and get out of memory issue when callling many times say 2000 times. I want to ask for the TROHttpApiResult Create and Free Handling:
Like Below Function:
I used the TROHttpApiResult.Create and stream the result to client side. How to free the binary object? As I tried Binary.free , the result I get at client is nil.
If the Binary object, no need to free , can you advise why I get the out of memory?
I can’t reproduce any memory leaks with simple code like
function TNewProjectService.NewMethod: Binary;
begin
Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_application_json_charset_utf8,'',false);
Result.LoadFromFile('C:\Windows\explorer.exe');
end;
I used fastMM4 to check the project , it did not find any memory leakage.
I running a heavy testing on a batch to create a 400 thread to call this following function.
→ Login User ( DA operation to check password)
→ GetUser( DA operation to get user info)
If compile in 32 bit server , running this test I get out of memory error.
The exact error is below:
Error reading AllTableDASchema.Datasets: Out of memory
Error reading AllTableDASchema.Datasets: Error reading TDAServerDataset.Fields: Out of memory
If I need test a heavy loading, how to check why invoke this out of memory.
→ I already set the DB connection pool to 400 in Connection Manager.
If I need concurrent session around 400, what parameter do I need to take care?
You have 32bit server and 400 simultaneous requests so each request can consume only 2048 mb / 400 = ~5mb
also you have
Looks like, your task requires 64-bit server because peak memory consumption is great that 5mb per request.
Under peak memory consumption I mean 400 datasets and 400 TROHttpApiResult that contain a content of dataset in json format.
Also pay attention, that the server copies method’s result to response stream so available memory will be smaller, i.e. ~ 2,5 mb. This is in ideal conditions.
In real life, delphi memory manager also consumes some memory …
in your scenario you should try to decrease usage of memory for each request.
what I can recommend:
if you use TDASchema in read-only mode - try to move it to server datamodule. in this case you will decrease usage of memory required for each request and get some performance.
you may play with class factories. in your case you may change it to Pooled Class Factory . also you get some performance but usage of memory also will be increased because it should keep service instance in memory.