Hi, I'm working on my first POE program (using POE 0.1203). It's purpose is
to replace a hodgpodge of patches, scripts, and procedures between my
database and (extremely busy) webserver.
WHOA.
:-)
I mostly get POE, I think. I've even got some working code. But still,
there is some weirdness that I was hoping somebody could help me clear up.
The design goals of this program are relatively simple. I have two sessions
running, one to accept connections and one to hit the database.
That being the case, I started with Socketfactory.perl as my starting point,
to get me running w/ a tcp server out of the gate.
(is there a "more efficient", "more idiomatic" way to do this? comments?)
Then I define a session that connects to the DB, reads some info from the
DB, and then essentially waits for a watermark to go refresh that info.
The idea is,
once the info is pre-fetched
I can serve it out via the tcp server
without melting my database
(and at roughly 500,000 hits/day, all server parsed, all requiring a DB
touch, DB melt is a VERY serious issue. *EVEN* on a Sun 450 w/ 4x400 & 2GB
of RAM!)
Then, when the info I've prefetched becomes stale, I want to send an event
to my DBFetch session to begin the refresh process. The state machine idiom
for this is particularly convenient, actually, because I can execute in one
state, and fetch individual rows in the "read" state, while still serving
hits to the server session.
But now I run into issues.
1) At first, I couldn't keep my DB session alive...
however, I ended up solving that by creating an alias to it so I could
access it from another state:
# from StreamServerSession::gotline()
# print the results of DBFetch::fetch out to the socket
$kernel->call( db => fetch => $line, $heap->{wheel} ) or die "couldn't
execute db::fetch: $!";
But that seems kinda crufty... especially the passing of the wheel as a
parameter in another session.
2) When my DB session is loaded, POE stops responding to SIGINT & Ctrl-Z
altogether. I have to kill -TERM in another window to restart my program
and test changes... YUCK! Now, I'm using DBD::Oracle, and I've seen this
kind of thing before, but setting trace levels SHOWS the signals arriving! I
just don't know where they're going.
3) The socketfactory.perl sample used a "Package as Object" session idiom,
so I went with it... if it ain't broke, right? So, following that
convention I copied the constructor and object methods (even tho i actually
use the HEAP for session info). So imagine my confusion at this output:
Bootstrap session is starting.
InetTcpServer=HASH(0x80d03a4) is being created.
InetTcpServer=HASH(0x80d03a4) received _start. Hi!
********** InetTcpServer=HASH(0x80d03a4) wheel is bound to: 127.0.0.1 :
30000
DBFetch=HASH(0x80d03bc) is being created.
DBFetch=HASH(0x80d03bc) received _start.
DBFetch=HASH(0x80d03bc): initialized
Bootstrap=HASH(0x80c7150) has stopped.
----------------------------------( SIGTERM received here)
HASH(0x83a1be8): received _stop (db_fetch).
InetTcpServer=HASH(0x80d03a4) received _stop.
Bootstrap=HASH(0x80c7150) has stopped.
InetTcpServer=HASH(0x80d03a4) is destroyed.
DBFetch=HASH(0x80d03bc) is destroyed.
Bootstrap=HASH(0x80c7150) is destroyed.
See the first line after the TERM signal? My question is simple... WTF?????
TIA!
L8r,
Rob