You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Shane Nay <sh...@isupportlive.com> on 2000/06/19 12:09:13 UTC

Re: Apache::Session & Math::Currency thawing issue.

Okay, backup a second..., you're doing this... why?  Do you need a
Math::Currency object stored inside the session?..., that could be quite a
hefty object.  See, everything you write to a session you have to read back in,
and any time you update any small part of it it has to re-write the whole
record.  What storage mechanism are you using for sessions, Filestore,
Database?  Generally I think it's a best practice to be careful about what
you're stuff in your sessions, i.e. how much data you're putting in there.  A
complete update of several objects could be pretty hairy since you have to do a
complete re-write of that record whenever you change one small detail.  You
also have to read in that entire session, and decompose it which could take a
little while.  Basically you're adding quite a bit of overhead to your
web-application.  Personally I like to keep my sessions really small, and put
more permanent data elsewhere, does anyone else have a "best practices" sort of
thing on what should/should not be stored in a session?  (This seems to come up
almost weekly I think)

Thanks,
Shane.
(Also you should read up on freeze thaw, because they can't store _everything_)

On Mon, 19 Jun 2000, you wrote:
> Hello,
>   I'm trying to use Math::currency with sessions, and I've run into a
> stumper.  I initialize variables and make them Math::Currency objects, and
> display them just fine, but when I come back (unthaw the session) instead
> of seeing the value I get the reference showing
> "Math::Currency=HASH(0x86b022)" instead of the value as it showed the
> first time through.
> 
> It's a reference going in, and a reference coming out, but for some reason
> it doesn't like being stuck into Apache::Session.
> 
> I can work around it by testing if it's a Math::Currency reference, and
> call Math::Currency->new.  But this seems a little silly.  Anyone seen
> this before?
> 
> Jay Jacobs

Re: Apache::Session & Math::Currency thawing issue.

Posted by Shane Nay <sh...@isupportlive.com>.
(If anyone else wants to mention how they use sessions I'm curious)

> First off, I'm doing this becuase I need to store variables (in
> currency) that are generated on a per-user session, for a short period of
> time (3 to 5 requests).  I'm using a database back-end for the session.
> 
> I was initially wrong in my thinking about Math::Currency, and my solution
> was to "stringify" the instance, so I only store "$10.45" instead of a
> Math::Currency object.

Right, yes that's cool.  It's just a bit concerning when you try to store
objects in a backing store..., string stuff is a-okay because it's small.  I
would probably push forward in a form for this instance probably, but that's
just an implementation detail.

> Where do you put your "more permanent" data, and what constitutes "more
> permanent" data?  I can't think of anything that would be faster/easier to
> store and retrieve specific information related to that user or session.

Well, putting it in a form requires no overhead for your system.  This seems to
not constitute "more permanent data".  As far as specific information related
to the user, you bet there's a better place to store it :-), in a database with
real fields.  See..., a session doesn't allow incremental data lookups, or
incremental changes.  You dump the whole thing in memory, and then manipulate
it on the perl level.  Not to mention if you change one aspect of the session,
you trigger now a complete update of that field.  Maybe you're working on a
site that doesn't have anything related to "more permanent data"..., like
userid's and that sort of thing.  I somehow thought you were trying to store
the users preference of currency in the session as an object to use to convert
further stuff, or something like that.  (Haven't used that module in
particular, so I was just making a wild guess)

> I'd agree that the session needs to be handled carefully, but I think the
> careful part is not leaving stuff in the session that doesn't need to be
> there, instead of not using it.

Well obviously :-), it's there for a good reason... it makes our lives as site
programmers a lot easier.  I use sessions, but am really careful about how I
use them, I usually just put stuff in a session that will be used on 80% of
pages.  Normally it turns out that I only insert/modify the session on
login, and try to keep subsequent updates to a minimum.  (Cost to benefit
analysis, the session can save you a lot of sql queries, or it can add a lot) 
I'm working on sites right now that have very specific needs in terms of
performance, but everyones needs are different. 

Thanks,
Shane.

Re: Apache::Session & Math::Currency thawing issue.

Posted by Jay Jacobs <ja...@lach.net>.
First off, I'm doing this becuase I need to store variables (in
currency) that are generated on a per-user session, for a short period of
time (3 to 5 requests).  I'm using a database back-end for the session.

I was initially wrong in my thinking about Math::Currency, and my solution
was to "stringify" the instance, so I only store "$10.45" instead of a
Math::Currency object.

Where do you put your "more permanent" data, and what constitutes "more
permanent" data?  I can't think of anything that would be faster/easier to
store and retrieve specific information related to that user or session.

I'd agree that the session needs to be handled carefully, but I think the
careful part is not leaving stuff in the session that doesn't need to be
there, instead of not using it.

Jay

On Mon, 19 Jun 2000, Shane Nay wrote:

> Okay, backup a second..., you're doing this... why?  Do you need a
> Math::Currency object stored inside the session?..., that could be quite a
> hefty object.  See, everything you write to a session you have to read back in,
> and any time you update any small part of it it has to re-write the whole
> record.  What storage mechanism are you using for sessions, Filestore,
> Database?  Generally I think it's a best practice to be careful about what
> you're stuff in your sessions, i.e. how much data you're putting in there.  A
> complete update of several objects could be pretty hairy since you have to do a
> complete re-write of that record whenever you change one small detail.  You
> also have to read in that entire session, and decompose it which could take a
> little while.  Basically you're adding quite a bit of overhead to your
> web-application.  Personally I like to keep my sessions really small, and put
> more permanent data elsewhere, does anyone else have a "best practices" sort of
> thing on what should/should not be stored in a session?  (This seems to come up
> almost weekly I think)
> 
> Thanks,
> Shane.
> (Also you should read up on freeze thaw, because they can't store _everything_)
> 
> On Mon, 19 Jun 2000, you wrote:
> > Hello,
> >   I'm trying to use Math::currency with sessions, and I've run into a
> > stumper.  I initialize variables and make them Math::Currency objects, and
> > display them just fine, but when I come back (unthaw the session) instead
> > of seeing the value I get the reference showing
> > "Math::Currency=HASH(0x86b022)" instead of the value as it showed the
> > first time through.
> > 
> > It's a reference going in, and a reference coming out, but for some reason
> > it doesn't like being stuck into Apache::Session.
> > 
> > I can work around it by testing if it's a Math::Currency reference, and
> > call Math::Currency->new.  But this seems a little silly.  Anyone seen
> > this before?
> > 
> > Jay Jacobs
>