#1 2015-01-30 15:19:21

Daniela
Member
Registered: 2015-01-30
Posts: 1

Session Keep Alive

Hello,

I am new to mORMot and found this framework during research for a DataSnap replacement. Because DS is slow and... oh I am sure you all know why...

My application is only publishing services and I need to live with some circumstances (e.g. to return plane text). Everything is fine and works perfectly. But... the only thing is that it seems the socket gets closed after 20 or 30 seconds. Then the next call to the function needs 1,0s instead of 30ms. Of course it would be fine to keep it alive for about 30min. I am not able to find how I am able to keep the connection alive?

I connect to the service within an asp.net website. Using the DataSnap solution the connection stays alive, so I think there is a setting missing in one of the components of the mORMot framework. Please can anyone help me to solve this?

Thanks in advance,
Daniela


  TMyService = class(TSQLRestServerFullMemory)
  private
  public

  published
    procedure Test(Ctxt: TSQLRestServerURIContext);
  end;


procedure TMyService .Test( Ctxt: TSQLRestServerURIContext );
begin
  if UrlDecodeNeedParameters(Ctxt.Parameters,'strParam') then
    Ctxt.Returns(DoSomething( Ctxt.InputUTF8['strParam']),
        HTML_SUCCESS,
        TEXT_CONTENT_TYPE_HEADER)
  else Ctxt.Error('Missing Parameter');
end;


var
  fModel: TSQLModel;
  fRestServer: TSQLRestServer;
  fHttpServer: TSQLHttpServer;
begin
  try
    SQLite3Log.Family.Level := LOG_VERBOSE;
    SQLite3Log.Family.PerThreadLog := ptIdentifiedInOnFile;

    fModel := TSQLModel.Create([],'root');
    try
      fRestServer := TMyService.Create(fModel);
      try
        fRestServer.CreateMissingTables;
        fHttpServer := TSQLHttpServer.Create('9000',[fRestServer],'+',useHttpApiRegisteringURI);
        try
          fHttpServer.AccessControlAllowOrigin := '*';
          writeln('Server is running at port 9000.');
          write('Press [Enter] to close the server.');
          readln;
        finally
          fHttpServer.Free;
          end;
      finally
        fRestServer.Free;
        end;
    finally
      fModel.Free;
      end;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
    end;


// sample code from the webserver....

        HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(cmdLink);
        myHttpWebRequest1.KeepAlive = true;
        HttpWebResponse myHttpWebResponse1 = (HttpWebResponse)myHttpWebRequest1.GetResponse();
        Stream streamResponse = myHttpWebResponse1.GetResponseStream();
        StreamReader streamRead = new StreamReader(streamResponse);
        string result = streamRead.ReadToEnd();
        streamRead.Close();
        return result;

Offline

#2 2015-01-31 10:21:12

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

Re: Session Keep Alive

AFAIR the keep alive timeout is
- 2 minutes for http.sys (THttpApiServer) - see IdleConnection default parameter of https://msdn.microsoft.com/en-us/library/aa364661
- 3 seconds for our socket-based - see THttpServer.ServerKeepAliveTimeOut

Which class is running on your server?
What are the HTTP headers sent and received by your .Net clients?

Edit: I've added the THttpApiServer.SetTimeOutLimits() method for HTTP API 2.0 so that you could change aIdleConnection value, which corresponds to the keep alive timeout, AFAIK.
See http://synopse.info/fossil/info/0a45da0be6

Offline

Board footer

Powered by FluxBB