You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Mike Blancas <mb...@mozcom.com> on 2001/08/31 04:43:21 UTC

Virtual Hosts and Cached subs

Hi,

I have this bug/problem with Apache ASP. The caching of subs doesn't uses
the same memory space for different virtual hosts. Lets say I have three
virtual hosts all are using a sub called print_header and print_footer.
These subs have different content on their print_header and print_footer.
Problem is sometimes one of the virtual hosts uses the cached print_header
of another virtual host, resulting in a not so sightly result. One of my
solution is just to rename the sub, but what if a client names his sub the
same as another client's sub. I think this is not a memory problem since
my box has 2GB of physical memory.

Any help would be appreciated.

-- 
Mike Blancas <mb...@mozcom.com>
Mosaic Communications, Inc.


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


Re: Virtual Hosts and Cached subs

Posted by Joshua Chamas <jo...@chamas.com>.
Mike Blancas wrote:
> 
> Hi,
> 
> I have this bug/problem with Apache ASP. The caching of subs doesn't uses
> the same memory space for different virtual hosts. Lets say I have three
> virtual hosts all are using a sub called print_header and print_footer.
> These subs have different content on their print_header and print_footer.
> Problem is sometimes one of the virtual hosts uses the cached print_header
> of another virtual host, resulting in a not so sightly result. One of my
> solution is just to rename the sub, but what if a client names his sub the
> same as another client's sub. I think this is not a memory problem since
> my box has 2GB of physical memory.
> 

If print_header() is defined in a script or include, then all
you need to do is have each client have a unique Global, 
since the print_header() will be compiled into the GlobalPackage
namespace, by default defined to be the Global directory.

If they have the same Global, then you can try to circumvent
this problem by setting 

  PerlSetVar UniquePackages 1

http://www.apache-asp.org/config.html#UniquePackages
Each script will get its own namespace then.

But this can always be a problem because of how mod_perl
is set up.  Let's say you have a package Site and in it 
you have print_header()... this print_header will be 
everyones Site::print_header() because the perl interpreter
is being shared across requests for various clients.

A cleaner way to run mod_perl for many people is to have
a separate mod_perl server for EACH party running on a 
high port ( > 1024 ) and have your root httpd on port 80 
configured to forward requests for those domains to those 
servers on the backend using ProxyPass/ProxyPassReverse 
settings.

Another thing you might try is to have MaxRequestsPerChild
set to 1.  This will be incredibly inefficient, but it will
at least keep the perl namespace clean.  This would still
be better than CGI perl because you can cache module
compilations like Apache::ASP with the PerlModule directive...
so then you could put all your ASP VirtualHosts on some high
port backend server, and just ProxyPass to those, leaving
your gif requests & such to be served at the front end.

Sorry if none of these seems nice, but I don't think mod_perl
was meant to be used in a VirtualHost environment where
multiple untrusted parties can modify the code.  People
talk about modperl/apache 2.0 being better at this because
of having the ability for separate perl interpreters per
VirtualHost, but we'll see when these are released as stable.

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

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


Re: Virtual Hosts and Cached subs

Posted by Joshua Chamas <jo...@chamas.com>.
"John D. Leonard II" wrote:
> 
> Mike:
> 
> I believe that documents are compiled into packages whose namespace is
> constructed from their file name.  If the file name is similar (even if the
> desired behavior is to load them from a different directory) the one in
> memory is used first.  This similarity will often occur because the files
> are loaded from the @INC, the Global directory, or because their package
> names are build from a relative rather than absolute file name.
> 
> SOLUTION:
> 
> $Response->Include( $Server->MapPath("./header.asp") );
> 
> 

This is a good work around, but perhaps this needs to be treated
as a bug.  Its seems reasonable that if you are in different
parts of an application, defined by a shared Global setting, but 
just in different directories, that each should be able to include 
a separate header.inc.

What was defeating this was the notion of '.' for the first directory,
which when later used for as part of the file name parsed into
a subroutine name would give you something like $GlobalPackage::__header_asp 
regardless of where you included it from.

To fix, this I'll try to have not '.' for the first directory
in the search path, but rather dirname($0), or the directory 
the current script is in.

I'll try this in my dev version, and send it to you John when
its ready.

--Josh

_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

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


RE: Virtual Hosts and Cached subs

Posted by "John D. Leonard II" <jo...@ce.gatech.edu>.
Mike:

I've run into a similar problem when sharing a common "GLOBAL.ASA" file
between different directories.  I am developing  "course" web sites at
Georgia Tech, and while I want to share some common scripts (and ASP
modules) between different directories, I also want to allow each class to
have a "custom" header, specific to that class.

I found a solution that seems to work.  Perhaps Joshua can fine-tune this
solution.

PROBLEM:

$Response->Include( "./header.asp" ) will often use the content of the first
"header.asp" compiled into memory, rather than using the one located in the
current directory.  I have found this to be true even if "UniquePackages 1"
is placed in the configuration file.

I believe that documents are compiled into packages whose namespace is
constructed from their file name.  If the file name is similar (even if the
desired behavior is to load them from a different directory) the one in
memory is used first.  This similarity will often occur because the files
are loaded from the @INC, the Global directory, or because their package
names are build from a relative rather than absolute file name.

SOLUTION:

$Response->Include( $Server->MapPath("./header.asp") );

This forces the document to be cached(?)/compiled(?) using the absolute
filename.  When combined with the "PerlSetVar UniquePackages 1", you should
get your desired behavior.

This is only a theory - Joshua can offer a definitive answer to my reasons
"why" above.  However, this solution appeared to satisfy my needs.

JL
------
John D. Leonard II, Associate Professor            Phone: 404/894-2360
School of Civil and Environmental Engineering       FAX:  404/894-2278
Georgia Institute of Technology           http://traffic.ce.gatech.edu
Atlanta, GA  30332-0355              mailto:john.leonard@ce.gatech.edu


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