Sign in Join

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

Mailing lists / fpc-devel / 2008-09

fcl-web improvement for apache modules, question

10 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

ABorka

Hi,

I'm working on the Apache application (TCustomApacheApplication) simultaneous request handling.

When the Apache module tries to create additional instances of the web module I get
`Error: Duplicate name: A component named "FPWebModule1" already exists`

How can we create multiple instances of a TDatamodule descendant without getting this error? The apache module will need to create multiple web modules when multiple requests are arriving at the same time (not like CGI).

For one request at a time it is working.

Thanks,

AB

Reply by email

Michael Van Canneyt
to ABorka
ABorka wrote 8 lines
Hi, I'm working on the Apache application (TCustomApacheApplication) simultaneous request handling. When the Apache module tries to create additional instances of the web module I get `Error: Duplicate name: A component named "FPWebModule1" already exists`

How was the component instantiated ?

Michael.

Reply by email

ABorka
to Michael Van Canneyt

Hi Michael,

It was created in fpapache.pp in the handlerequest event.

M:=MC.create(self);

It worked without using the createnew, with the latest FPC source code.

AB

Show quoted text 22 lines
On Thu, 18 Sep 2008, ABorka wrote: > Hi, > > I'm working on the Apache application (TCustomApacheApplication) > simultaneous > request handling. > > When the Apache module tries to create additional instances of the web > module > I get > `Error: Duplicate name: A component named "FPWebModule1" already exists` How was the component instantiated ? Michael. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to ABorka
ABorka wrote 8 lines
Hi Michael, It was created in fpapache.pp in the handlerequest event. M:=MC.create(self); It worked without using the createnew, with the latest FPC source code.

This is weird, because the code before that searches if there is an existing instance. If so, it should be reused ?

OK, I'll have a should probably be created with owner Nil, and then a unique name should be made and assigned, after which self can be put as the owner.

Michael.

Reply by email

ABorka
to Michael Van Canneyt

The thing is that for apache modules it is needed to have multiple webmodules created for simultaneous requests coming from multiple people browsing the web server. I was creating some pooling for the web modules in fpapache.pp and simulated 2 concurrent requests when it happened. If we change the name, will the next call find the changed named module for reuse?

Show quoted text 26 lines
On Fri, 19 Sep 2008, ABorka wrote: > > Hi Michael, > > It was created in fpapache.pp in the handlerequest event. > > M:=MC.create(self); > > It worked without using the createnew, with the latest FPC source code. This is weird, because the code before that searches if there is an existing instance. If so, it should be reused ? OK, I'll have a should probably be created with owner Nil, and then a unique name should be made and assigned, after which self can be put as the owner. Michael. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Martin Friebe
to Michael Van Canneyt: This is weird, because the code before that searches if there is an existing instance. If…
Michael Van Canneyt wrote 16 lines
On Fri, 19 Sep 2008, ABorka wrote > Hi Michael, > > It was created in fpapache.pp in the handlerequest event. > > M:=MC.create(self); > > It worked without using the createnew, with the latest FPC source code. > This is weird, because the code before that searches if there is an existing instance. If so, it should be reused ? OK, I'll have a should probably be created with owner Nil, and then a unique name should be made and assigned, after which self can be put as the owner.

Just an idea (not tested), but why creating it with owner nil, and assign self later.

Just immediately after the create (or better within the create) assign it a new unique name (using a counter, or the address in memory). Then when the next instance is created it can be created again with the default name, as all others have already new names. (Only have to make sure that it's done thread save, if threads are in use)

If the default name is set via the property, setter-method, then it can be modified there too...

Regards
Martin

Reply by email

Michael Van Canneyt
to ABorka: The thing is that for apache modules it is needed to have multiple webmodules created for…
ABorka wrote 6 lines
The thing is that for apache modules it is needed to have multiple webmodules created for simultaneous requests coming from multiple people browsing the web server. I was creating some pooling for the web modules in fpapache.pp and simulated 2 concurrent requests when it happened. If we change the name, will the next call find the changed named module for reuse?

No.

Michael.

Reply by email

ABorka
to Michael Van Canneyt

This is how currently the code looks like for the problematic call:

FCriticalSection.Enter;
try
   if (FMaxRequests>0) and (FWorkingWebModules.Count>=FMaxRequests) then
     Raise EFPApacheError.Create(SErrTooManyRequests);
   if FIdleWebModules.Count > 0 then
   begin
     II := FIdleWebModules.Count - 1;
     while (II>=0) and not (TComponent(FIdleWebModules[II]) is MC) do
       Dec(II);
     if II >= 0 then
     begin
       M:=TCustomHTTPModule(FIdleWebModules[II]);
       FIdleWebModules.Delete(II);
     end;
   end;
   if (M=nil) then
     M:=MC.Create(Self);  {<- here comes the problem with the names when
another module needs to be created while this one is still working on a
request}
   FWorkingWebModules.Add(M);
finally
   FCriticalSection.Leave;
end;

I am gonna play with this a little bit more later today. Somehow we have to make it work.

AB

Michael Van Canneyt wrote 17 lines
On Fri, 19 Sep 2008, ABorka wrote: > The thing is that for apache modules it is needed to have multiple > webmodules created for simultaneous requests coming from multiple people > browsing the web server. I was creating some pooling for the web modules > in fpapache.pp and simulated 2 concurrent requests when it happened. > If we change the name, will the next call find the changed named module > for reuse? No. Michael. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to Martin Friebe: Just an idea (not tested), but why creating it with owner nil, and assign self later.…
Martin Friebe wrote 28 lines
Michael Van Canneyt wrote: > On Fri, 19 Sep 2008, ABorka wrote > > Hi Michael, > > > > It was created in fpapache.pp in the handlerequest event. > > > > M:=MC.create(self); > > > > It worked without using the createnew, with the latest FPC source code. > > > This is weird, because the code before that searches if there is an existing > instance. If so, it should be reused ? > > OK, I'll have a should probably be created with owner Nil, > and then a unique name should be made and assigned, after which self can > be put as the owner. > Just an idea (not tested), but why creating it with owner nil, and assign self later. Just immediately after the create (or better within the create) assign it a new unique name (using a counter, or the address in memory). Then when the next instance is created it can be created again with the default name, as all others have already new names. (Only have to make sure that it's done thread save, if threads are in use) If the default name is set via the property, setter-method, then it can be modified there too...

The name is set throught the streaming system, and you can't control that.

Michael.

Reply by email

Mattias Gaertner
to ABorka: This is how currently the code looks like for the problematic call:…
Show quoted text 21 lines
This is how currently the code looks like for the problematic call: FCriticalSection.Enter; try if (FMaxRequests>0) and (FWorkingWebModules.Count>=FMaxRequests) then Raise EFPApacheError.Create(SErrTooManyRequests); if FIdleWebModules.Count > 0 then begin II := FIdleWebModules.Count - 1; while (II>=0) and not (TComponent(FIdleWebModules[II]) is MC) do Dec(II); if II >= 0 then begin M:=TCustomHTTPModule(FIdleWebModules[II]); FIdleWebModules.Delete(II); end; end; if (M=nil) then M:=MC.Create(Self); {<- here comes the problem with the names when another module needs to be created while this one is still working on a request}
M.Name:=''; // or to a unique name
Show quoted text 8 lines
FWorkingWebModules.Add(M); finally FCriticalSection.Leave; end; I am gonna play with this a little bit more later today. Somehow we have to make it work.

Mattias

Reply by email