Curtis Spencer
2006-Jul-25 19:59 UTC
[Mongrel] Question about how Mongrel process works with singletons
Hi, I have a controller where I access a singleton class that I use to connect to a DRbprocess DrbConnector.instance.some_method I notice that on every request, the constructor is called so it is making a new instance of this singleton. Is this normal? Thanks, Curtis
Rick Olson
2006-Jul-25 20:17 UTC
[Mongrel] Question about how Mongrel process works with singletons
On 7/25/06, Curtis Spencer <thorin at gmail.com> wrote:> Hi, > > I have a controller where I access a singleton class that I use to > connect to a DRbprocess > > DrbConnector.instance.some_method > > I notice that on every request, the constructor is called so it is > making a new instance of this singleton. Is this normal? > > Thanks, > > CurtisIf you look in the mongrel source under trunk/projects/mongrel_upload_progress, I start and maintain a drb process. -- Rick Olson http://techno-weenie.net
Curtis Spencer
2006-Jul-25 20:26 UTC
[Mongrel] Question about how Mongrel process works with singletons
Rick Olson wrote:> On 7/25/06, Curtis Spencer <thorin at gmail.com> wrote: >> Hi, >> >> I have a controller where I access a singleton class that I use to >> connect to a DRbprocess >> >> DrbConnector.instance.some_method >> >> I notice that on every request, the constructor is called so it is >> making a new instance of this singleton. Is this normal? >> >> Thanks, >> >> Curtis > > If you look in the mongrel source under > trunk/projects/mongrel_upload_progress, I start and maintain a drb > process. >Rick, Thanks for the information. This looks to be a little lower level than I was originally working with (using Mongrel handlers instead of Rails Controllers). Do I need to bind a variable to a Mongrel constant in order to have it persist between requests? My question is more about why the singleton is reinitialized every request rather than about drb specifically. Thanks, Curtis
Rick Olson
2006-Jul-25 20:33 UTC
[Mongrel] Question about how Mongrel process works with singletons
> Thanks for the information. This looks to be a little lower level than > I was originally working with (using Mongrel handlers instead of Rails > Controllers). Do I need to bind a variable to a Mongrel constant in > order to have it persist between requests? My question is more about > why the singleton is reinitialized every request rather than about drb > specifically.Oh, well I just assumed, this being a mongrel list and all :) It''s probably a development issue. Rails controller classes are reloaded every request. Turn cache_classes to false in config/environments/dev.rb (or run in production) mode to see if this is the case. -- Rick Olson http://techno-weenie.net