You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Daniel <em...@7thfire.com> on 2006/02/22 18:00:26 UTC

object life

Hi,

I'm running two websites from the same apache session, and I have some
issues with objects being live between the two sessions.

I load an object with configs for one particular instance of my website,
a certain DBH config.

When I access my other instance of the website, it tries to use the
instance from the first one, causing database errors.

I have a lot of shared code between the two, but the difference in
configs is what's hurting.

Is it possible for me to destroy the objects so that apache doesn't
reuse them?

Why doesn't apache detect that I'm using a different instance?

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Re: Re: object life

Posted by Daniel <em...@7thfire.com>.
On Tue, Feb 28, 2006 at 06:36:33PM +1100, Kathryn Andersen wrote:
> On Mon, Feb 27, 2006 at 09:53:05PM -0800, Daniel wrote:
> > has noone bumped into this? I think apache for speeds sake is trying to
> > load the classes and keep them in memory.
> > 
> > Is there no way to turn that 'off' ?
> 
> Don't use mod_perl?

how can I use embperl without mod_perl? I use PerlSetEnv EMBPERL_OPTIONS
16 and other such flags. How can I get that behaviour without mod_perl?

-d

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Re: object life

Posted by Kathryn Andersen <ka...@katspace.homelinux.org>.
On Mon, Feb 27, 2006 at 09:53:05PM -0800, Daniel wrote:
> has noone bumped into this? I think apache for speeds sake is trying to
> load the classes and keep them in memory.
> 
> Is there no way to turn that 'off' ?

Don't use mod_perl?

I do believe that loading classes and keeping them in memory is a
*feature* of mod_perl, not a bug.  That is one of the reasons it is so
fast, because it doesn't have to re-load classes all the time.

I have certainly noticed, when using Embperl under mod_perl, that if I
have a new version of a perl module which is being used with something
like

        use ModuleX;

then I have to restart Apache in order to get it to load the new version
of the module.

But I've never tried to use two different versions of the same module.

Kathryn Andersen
-- 
 _--_|\     | Kathryn Andersen	<http://www.katspace.com>
/      \    | 
\_.--.*/    | GenFicCrit mailing list <http://www.katspace.com/gen_fic_crit/>
      v     | 
------------| Melbourne -> Victoria -> Australia -> Southern Hemisphere
Maranatha!  |	-> Earth -> Sol -> Milky Way Galaxy -> Universe

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Re: object life

Posted by Martin Moss <ma...@btopenworld.com>.
Hi Daniel,

I hope this helps, I've had to make some assumptions,
so please feel free to correct me.. 

Firstly, the bad news.
> Is there no way to turn that 'off' ?
No:-)   (none that I know of that are actually worth
it)

I think you have a fundamental problem that cannot be
solved without some re-engineering on your part. I
think you would find it really beneficial to spend a
little time looking at how mod_perl works. In that it
has a preforking mechanism and a copy on write memory
system.
(http://perl.apache.org/docs/1.0/guide/performance.html
- not sure what the MP2 link is..)

The issue I think you are having is that you aren't
declaring your use db; in a startup.pl. Now I suspect
this is because until a user makes a page request (for
a given site) you don't know which db.pm they need to
access. 

Bear with me (I think I'm going in the right
direction)

So IF (and I am assuming a few things here, so correct
me if I'm wrong) you aren't preloading db.pm at
startup then if you remove the 'use db;' line, your
epl will die at runtime saying can't load method
blahblah on module db.pm at line xxx...). BUT because
you DO have a use db.pm in your epl Embperl and thus
Mod perl tries to be clever and tries to guess what
you want to do, and tries to load that module at
runtime. First it checks if it's already loaded db.pm
and if not it goes and loads it. If it had already
loaded it, then it'd give you what it already has. 

Apache, uses forked children to handle each page
request. These children can serve ANY virtual host on
your server. so the first request a child handles is
from site X and the second site y.  What is happenning
in your case is that the first request is for site x
and so x's db.pm gets loaded, then the second request
is for site y... However x'db.pm fools mod_perl that
db.pm is already loaded....

So what can you do?

Well, firstly I think your original intention sounds
kinda right, but the implementation wasn't ready for
the Namepsace clash you're having...  Fixing the
namespace would work

use X::db;
use Y::db;
my $db_inst;

if ($req_req->server_hostname eq 'SiteX.com') #or
however you are identifying your sites
{
    $db_inst=X::db->new();
}
else
{
    $db_inst=Y::db->new();
}

Without knowing more about your system it's difficult
to try to work anything else out.

Feel free to send me more info and I'll try to help,

Marty






--- Daniel <em...@7thfire.com> wrote:

> On Mon, Feb 27, 2006 at 05:24:55PM +0100, RobertCZ
> wrote:
> > not very clear what exactly you are doing - you
> have two apache virtual 
> > servers both using Embperl::Object and they clash?
> you use 
> > Embperl_App_Name, right?
> 
> hm, no, not quite.
> > 
> > if I dont understand, would you mind showing us
> some simplified code?
> 
> let me try.
> 
> index.epl has a use statement.
> use db;
> 
> That loads a Class::DBI database abstraction class.
> 
> I have two instances of my application running.
> 
> they live in two different paths, but the db module
> exists in both.
> 
> the db module get's loaded with certain configs,
> which live in
> config.pm which is done with a require.
> 
> my $cfg = require config.pm or some such.
> 
> I have a function for the database abstraction class
> called getConfig.
> 
> For my two instances, if I do something like this...
> 
> print OUT $db_inst->getConfig->{'mysql'}{'dbname'}
> 
> from indexer.epl, and I keep reloading, sometimes I
> will get the dbname
> appropriate for the first instance of my
> application, and sometimes for
> the second.
> 
> My applications both share the same framework, but
> are supposed to run
> as completely seperate instances.
> 
> I think apache objects witht he same filenames get
> passed around,
> regadless if the content is different.
> 
> Let me give an example of another scenario where
> I've seen it happen.
> 
> I've got one version of db.pm loaded for one app,
> then I have another
> db.pm loaded for another app. Apache shares the
> loaded libraries between
> it's instances, and one version of db.pm may have a
> function called
> PrintRows, while the other doesn't. Randomly the
> correct one will get
> loaded, randomly not.
> 
> has noone bumped into this? I think apache for
> speeds sake is trying to
> load the classes and keep them in memory.
> 
> Is there no way to turn that 'off' ?
> 
> I hope this is more clear.
> 
> -d
> 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail:
> embperl-help@perl.apache.org
> 
> 



	
	
		
___________________________________________________________ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: Re: object life

Posted by Daniel <em...@7thfire.com>.
On Mon, Feb 27, 2006 at 05:24:55PM +0100, RobertCZ wrote:
> not very clear what exactly you are doing - you have two apache virtual 
> servers both using Embperl::Object and they clash? you use 
> Embperl_App_Name, right?

hm, no, not quite.
> 
> if I dont understand, would you mind showing us some simplified code?

let me try.

index.epl has a use statement.
use db;

That loads a Class::DBI database abstraction class.

I have two instances of my application running.

they live in two different paths, but the db module exists in both.

the db module get's loaded with certain configs, which live in
config.pm which is done with a require.

my $cfg = require config.pm or some such.

I have a function for the database abstraction class called getConfig.

For my two instances, if I do something like this...

print OUT $db_inst->getConfig->{'mysql'}{'dbname'}

from indexer.epl, and I keep reloading, sometimes I will get the dbname
appropriate for the first instance of my application, and sometimes for
the second.

My applications both share the same framework, but are supposed to run
as completely seperate instances.

I think apache objects witht he same filenames get passed around,
regadless if the content is different.

Let me give an example of another scenario where I've seen it happen.

I've got one version of db.pm loaded for one app, then I have another
db.pm loaded for another app. Apache shares the loaded libraries between
it's instances, and one version of db.pm may have a function called
PrintRows, while the other doesn't. Randomly the correct one will get
loaded, randomly not.

has noone bumped into this? I think apache for speeds sake is trying to
load the classes and keep them in memory.

Is there no way to turn that 'off' ?

I hope this is more clear.

-d




---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: object life

Posted by RobertCZ <ro...@robert.cz>.
not very clear what exactly you are doing - you have two apache virtual 
servers both using Embperl::Object and they clash? you use 
Embperl_App_Name, right?

if I dont understand, would you mind showing us some simplified code?

- robert

Daniel wrote:
> Hi,
>
> I'm running two websites from the same apache session, and I have some
> issues with objects being live between the two sessions.
>
> I load an object with configs for one particular instance of my website,
> a certain DBH config.
>
> When I access my other instance of the website, it tries to use the
> instance from the first one, causing database errors.
>
> I have a lot of shared code between the two, but the difference in
> configs is what's hurting.
>
> Is it possible for me to destroy the objects so that apache doesn't
> reuse them?
>
> Why doesn't apache detect that I'm using a different instance?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: object life

Posted by Daniel <em...@7thfire.com>.
anyone?


On Wed, Feb 22, 2006 at 09:00:26AM -0800, Daniel wrote:
> Hi,
> 
> I'm running two websites from the same apache session, and I have some
> issues with objects being live between the two sessions.
> 
> I load an object with configs for one particular instance of my website,
> a certain DBH config.
> 
> When I access my other instance of the website, it tries to use the
> instance from the first one, causing database errors.
> 
> I have a lot of shared code between the two, but the difference in
> configs is what's hurting.
> 
> Is it possible for me to destroy the objects so that apache doesn't
> reuse them?
> 
> Why doesn't apache detect that I'm using a different instance?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

-- 
"One certain effect of war is to diminish freedom of expression. Patriotism
becomes the order of the day and those who question the war are seen as
traitors, to be silenced and imprisoned." - Howard Zinn

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org