Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-10

Threaded webserver and TJSONRPCModule instances: can I be sure there's only one?

8 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

Hello,

I'm using a TFPHTTPServerHandler in threaded mode. I'm also using a TJSONRpcModule.
I see that, even if the calls come from different threads, only one instance of the rpc module is ever created (on demand, the first time an rpc request comes in) and used.
Since I'm relying on this behaviour, can I be 100% sure it's by design and not a quirk of my test setup?

Bye

Luca

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 9 lines
Hello, I'm using a TFPHTTPServerHandler in threaded mode. I'm also using a TJSONRpcModule. I see that, even if the calls come from different threads, only one instance of the rpc module is ever created (on demand, the first time an rpc request comes in) and used. Since I'm relying on this behaviour, can I be 100% sure it's by design and not a quirk of my test setup?

It is controllable.

There is the 'Modulekind' : wkPooled.

Type
   TWebModuleKind = (wkPooled, wkOneShot{, wkSession});

And a property of your module:

  property Kind: TWebModuleKind read FWebModuleKind write FWebModuleKind default wkPooled;

wkPooled is the default, but if you explicitly set this to 'wkPooled' in the constructor, you'll be sure there is only ever 1 instance of the module, which is reused for every request...

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 21/10/22 a les 9:39, Michael Van Canneyt via fpc-pascal ha escrit:

Show quoted text 8 lines
And a property of your module:  property Kind: TWebModuleKind read FWebModuleKind write FWebModuleKind default wkPooled; wkPooled is the default, but if you explicitly set this to 'wkPooled' in the constructor, you'll be sure there is only ever 1 instance of the module, which is reused for every request...

Thank you,

I see that the property isn't published, so it's not available in the object inspector.
Can I set it in the DataModuleCreate os is it too late?

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 21/10/22 a les 9:48, Luca Olivetti via fpc-pascal ha escrit:

Show quoted text 16 lines
El 21/10/22 a les 9:39, Michael Van Canneyt via fpc-pascal ha escrit: > And a property of your module: > >   property Kind: TWebModuleKind read FWebModuleKind write > FWebModuleKind default wkPooled; > > wkPooled is the default, but if you explicitly set this to 'wkPooled' > in the constructor, you'll be sure there is only ever 1 instance of > the module, which is reused for every request... Thank you, I see that the property isn't published, so it's not available in the object inspector. Can I set it in the DataModuleCreate os is it too late?

I overrode the CreateNew method, I hope that's enough.

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 21/10/22 a les 9:57, Luca Olivetti via fpc-pascal ha escrit:

Show quoted text 19 lines
El 21/10/22 a les 9:48, Luca Olivetti via fpc-pascal ha escrit: > El 21/10/22 a les 9:39, Michael Van Canneyt via fpc-pascal ha escrit: > >> And a property of your module: >> >>   property Kind: TWebModuleKind read FWebModuleKind write >> FWebModuleKind default wkPooled; >> >> wkPooled is the default, but if you explicitly set this to 'wkPooled' >> in the constructor, you'll be sure there is only ever 1 instance of >> the module, which is reused for every request... > > Thank you, > > I see that the property isn't published, so it's not available in the > object inspector. > Can I set it in the DataModuleCreate os is it too late? I overrode the CreateNew method, I hope that's enough.

I see that Kind is used after the module has been created, so setting it in either method (CreateNew or DataModuleCreate) should be OK, am I right?

Bye

Luca

Reply by email

Michael Van Canneyt
to Luca Olivetti
Luca Olivetti wrote 23 lines
El 21/10/22 a les 9:57, Luca Olivetti via fpc-pascal ha escrit: > El 21/10/22 a les 9:48, Luca Olivetti via fpc-pascal ha escrit: >> El 21/10/22 a les 9:39, Michael Van Canneyt via fpc-pascal ha escrit: >> >>> And a property of your module: >>> >>>   property Kind: TWebModuleKind read FWebModuleKind write FWebModuleKind >>> default wkPooled; >>> >>> wkPooled is the default, but if you explicitly set this to 'wkPooled' in >>> the constructor, you'll be sure there is only ever 1 instance of the >>> module, which is reused for every request... >> >> Thank you, >> >> I see that the property isn't published, so it's not available in the >> object inspector. >> Can I set it in the DataModuleCreate os is it too late? > > I overrode the CreateNew method, I hope that's enough. I see that Kind is used after the module has been created, so setting it in either method (CreateNew or DataModuleCreate) should be OK, am I right?

You are right.

I will publish the method. That's an oversight.

Michael.

Reply by email

Luca Olivetti
to Michael Van Canneyt

El 21/10/22 a les 12:48, Michael Van Canneyt via fpc-pascal ha escrit:

Show quoted text 7 lines
> I see that Kind is used after the module has been created, so setting > it in either method (CreateNew or DataModuleCreate) should be OK, am I > right? You are right. I will publish the method. That's an oversight.

Meanwhile I changed the method I use to route the calls to the main thread (Application.QueueAsyncCall instead of a critical section and Synchronize) so it doesn't matter any more if there is just one instance or more than one.

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 21/10/22 a les 17:09, Luca Olivetti via fpc-pascal ha escrit:

Show quoted text 14 lines
El 21/10/22 a les 12:48, Michael Van Canneyt via fpc-pascal ha escrit: >> I see that Kind is used after the module has been created, so setting >> it in either method (CreateNew or DataModuleCreate) should be OK, am >> I right? > > You are right. > > I will publish the method. That's an oversight. Meanwhile I changed the method I use to route the calls to the main thread (Application.QueueAsyncCall instead of a critical section and Synchronize) so it doesn't matter any more if there is just one instance or more than one.

Now that I think of it, even with the previous method it wouldn't have mattered (since each instance would have been using its own critical section and other fields).

Bye

Luca

Reply by email