You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Neil Gunton <ne...@nilspace.com> on 2000/12/23 02:31:00 UTC

Question re Embperl memory usage

Gerald, this question has been bugging me for a few days. In one of your
previous emails you said the following:

> > I use __PACKAGE__ because I have global variables which are set up in
> > various different files (such as init.html and constants.html) which are
> > executed before '*', and it is just more convenient to include all these
> > in the same namespace. I don't doubt there's some kind of workaround.
> >
> 
> By includeing them in the same namespace you also need much more memory,
> because you have to compile all common files for every file you invoke. To
> pass "global" data around, use the Embperl Request Object.
> http://perl.apache.org/embperl/EmbperlObject.pod.5.html#Example_for_using_me
> thod_calls contains an example (the $self -> {fontsize} )

This thing about using more memory doesn't make sense to me. As I see
it, if I include files in the same package as base.html, then they all
share base.html's package. And after the first compilation, these pages
are cached. So, in what way do they use more memory than otherwise? I am
talking about files which would need to be included anyway, since they
are used by base.html. So what difference does it make if they are
compiled using their own package, or base.html's package? They still
have to be cached, and only once, as far as I can see. I obviously don't
know about the inner workings of Embperl, but I include below the output
of the embperl log, with EMBPERL_DEBUG set to 16384, so we see what is
being compiled and used. As you can see, there is (in this instance) a
total success rate of hitting the cache rather than re-compiling
anything, and I don't see how having these files in their own packages
gains anything other than requiring the use of $req->{variable} rather
than just $variable.

The reason I am asking is that when I started changing my code over to
using $req everywhere, I rapidly noticed a huge decrease in readability
of my code, due to the added verbosity involved in using
$req->{variable} rather than just $variable. This is really bad as far
as I am concerned.

Is it reasonable to say that there are really two kinds of inheritance
which we could talk about in EmbperlObject - one is the subs.html which
we have discussed before, which I could see having its own package. This
is the method which we just came up with, using Execute('subs.html#NEW')
etc. This is ok, because it makes sense to enable true Perl inheritance
for certain subroutines, if you want it.

But for other files, such as navbar.html, or head.html, which are really
just over-ridable HTML files (no subs), couldn't these be included by
base.html using __PACKAGE__? The great benefit is that they can all use
the common variables (which is not a trivial gain), and moreover
conceptually they are really all part of the same document anyway.
EmbperlObject very nicely gives us file over-riding by choosing the
right version of navbar.html, head.html etc, based on the directory of
'*'. So the only question then is, Am I using a lot more memory in this
situation too? And if so, why?

Here is the embperl log for the case where I just use package =>
__PACKAGE in my calls to Execute. Does this log look ok in terms of mem
usage? Or can you even tell from this?

[1976]REQ:  Embperl 1.3.0 starting... Fri Dec 22 20:15:25 2000

[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Formdata... length = 22
[1976]Using APACHE for output...
[1976]Reading /www/crazyguyonabike/com/htdocs/base.html as input using
PerlIO ...
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/constants.html as input
using PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/constants.html
[1976]PERF: Time: 0 ms Evals: 1 Cache Hits: 1 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20813 -OBJs: 33 Exit-SVs: 20817 -OBJs: 33
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/subs.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/subs.html
[1976]PERF: Time: 0 ms Evals: 1 Cache Hits: 1 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20817 -OBJs: 34 Exit-SVs: 20820 -OBJs: 33
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/init.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/init.html
[1976]PERF: Time: 20 ms Evals: 1 Cache Hits: 1 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20819 -OBJs: 34 Exit-SVs: 20804 -OBJs: 29
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/head.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/head.html
[1976]PERF: Time: 0 ms Evals: 0 No Evals to cache
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20803 -OBJs: 30 Exit-SVs: 20806 -OBJs: 29
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/security.html as input
using PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/security.html
[1976]PERF: Time: 0 ms Evals: 1 Cache Hits: 1 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20805 -OBJs: 30 Exit-SVs: 20808 -OBJs: 29
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/navbar.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/navbar.html
[1976]PERF: Time: 10 ms Evals: 26 Cache Hits: 26 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20811 -OBJs: 30 Exit-SVs: 20812 -OBJs: 29
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/sub_navbar.html as input
using PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/sub_navbar.html
[1976]PERF: Time: 0 ms Evals: 0 No Evals to cache
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20809 -OBJs: 30 Exit-SVs: 20812 -OBJs: 29
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/index.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/index.html
[1976]PERF: Time: 10 ms Evals: 7 Cache Hits: 7 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20811 -OBJs: 30 Exit-SVs: 20863 -OBJs: 35
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/bottom.html as input using
PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/bottom.html
[1976]PERF: Time: 0 ms Evals: 0 No Evals to cache
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20862 -OBJs: 36 Exit-SVs: 20865 -OBJs: 35
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/navbar.html
[1976]PERF: Time: 10 ms Evals: 27 Cache Hits: 27 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20868 -OBJs: 36 Exit-SVs: 20868 -OBJs: 35
[1976]REQ:  No Safe Eval  All Opcode allowed   mode = mod_perl (3)
[1976]REQ:  Package = HTML::Embperl::DOC::_1
[1976]Reading /www/crazyguyonabike/com/htdocs/cleanup.html as input
using PerlIO ...
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/cleanup.html
[1976]PERF: Time: 0 ms Evals: 1 Cache Hits: 1 (100%)
[1976]Sub-Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20865 -OBJs: 36 Exit-SVs: 20868 -OBJs: 35
[1976]PERF: input = /www/crazyguyonabike/com/htdocs/base.html
[1976]PERF: Time: 60 ms Evals: 9 Cache Hits: 9 (100%)
[1976]Request finished. Fri Dec 22 20:15:25 2000
. Entry-SVs: 20795 -OBJs: 31 Exit-SVs: 20856 -OBJs: 33
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/cleanup.html
in HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/bottom.html
in HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/index.html in
HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for
/www/crazyguyonabike/com/htdocs/sub_navbar.html in
HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/navbar.html
in HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/security.html
in HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/head.html in
HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/init.html in
HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/subs.html in
HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for
/www/crazyguyonabike/com/htdocs/constants.html in HTML::Embperl::DOC::_1
[1976]MEM: Free buffer for /www/crazyguyonabike/com/htdocs/base.html in
HTML::Embperl::DOC::_1


Thanks in advance,

-Neil

Re: Question re Embperl memory usage

Posted by Neil Gunton <ne...@nilspace.com>.
Gerald Richter wrote:
> > So the only question then is, Am I using a lot more memory in this
> > situation too?
> 
> No, as long as you include them only in _one_ document (base.html), you will
> not use more memory
> 
> Hope this is more clear now

Yes! Thanks so much. Have a good Christmas!

I will hopefully have some perldocs for you sometime next week...

-Neil

Re: Question re Embperl memory usage

Posted by Gerald Richter <ri...@ecos.de>.
>
> This thing about using more memory doesn't make sense to me. As I see
> it, if I include files in the same package as base.html, then they all
> share base.html's package. And after the first compilation, these pages
> are cached. So, in what way do they use more memory than otherwise?

If you only inlcude these files in base.html, then you of course don't use
more memory. What I wanted to say is, that if you inlcude them in foo.html,
bar.html and whatever.html, you use three times more memory.

>
> Is it reasonable to say that there are really two kinds of inheritance
> which we could talk about in EmbperlObject - one is the subs.html which
> we have discussed before, which I could see having its own package. This
> is the method which we just came up with, using Execute('subs.html#NEW')
> etc. This is ok, because it makes sense to enable true Perl inheritance
> for certain subroutines, if you want it.
>

yes

> But for other files, such as navbar.html, or head.html, which are really
> just over-ridable HTML files (no subs), couldn't these be included by
> base.html using __PACKAGE__? The great benefit is that they can all use
> the common variables (which is not a trivial gain), and moreover
> conceptually they are really all part of the same document anyway.
> EmbperlObject very nicely gives us file over-riding by choosing the
> right version of navbar.html, head.html etc, based on the directory of
> '*'.

Yes, you can do so, as long as you don't have subs with the same name in it.

> So the only question then is, Am I using a lot more memory in this
> situation too?

No, as long as you include them only in _one_ document (base.html), you will
not use more memory

Hope this is more clear now

Gerald

-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------