PetaMem has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
a (Mason-based) webapp connects to a backend server via IO::Socket::INET. Now I would like to make that connection persistent for the session. unfortunately, simply pouring the client object into the session storage doesn't work, as this immediately complains:
The handle is created the usual way - I think.
$handle = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $host, PeerPort => $port, Blocking => $blocking, );
But if I want to store it in a session, like this (Dumper output)
'one-session-key' => bless( { ... '_handle' => bless( \*Symbol::GEN40, 'IO::Socket::INET' + ), ...
I see this error
(in cleanup) Can't store GLOB items at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/_freeze.al) line 339, <GEN40> line 7, at /usr/lib64/perl5/vendor_perl/5.8.8/Apache/Session/Serialize/St +orable.pm line 21
I have read here about why this doesn't work and why some people think it doesn't make sense to try to achieve that persistence. Well - for me the reason is, that when the traffic gets high, I would prefer for a session not always to:
Actually I'd be pretty happy if one could omit the 1st and 3rd point, because they are simply performance killers during a session. Now what I have tried;
Circumventing the "Storable cannot store GLOB" problem by transfering bless( \*Symbol::GEN40, 'IO::Socket::INET' ), to a string and later evaluating that actually DOES work, but as I've been told this doesn't keep up the connection, instead it recreates just some glob. The result being a program that astonishingle DOES still work, but I see connections being established and terminated (probably when the last reference to the glob vanishes).
So what could one do? My next ideas would be:
1. some kind of mini-persistent-proxy on the frontend side that would keep up the persistent connections under some accessible index (and the index number of course easily storable in session data.
2. and/or by somehow tieing these sockets to the filesystem (socket files) and using them as the proxy. No idea HOW to do that, just an Idea, because I know there are socket "files".
What would you suggest?Bye
PetaMem All Perl: MT, NLP, NLU
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to keep network connection persistent during session?
by Joost (Canon) on Oct 11, 2009 at 22:38 UTC | |
by PetaMem (Priest) on Oct 12, 2009 at 08:15 UTC | |
by afoken (Chancellor) on Oct 13, 2009 at 19:38 UTC | |
Re: How to keep network connection persistent during session?
by moritz (Cardinal) on Oct 11, 2009 at 21:02 UTC | |
Re: How to keep network connection persistent during session?
by sflitman (Hermit) on Oct 11, 2009 at 22:17 UTC |