POE's garbage collection is pretty good, it does a heck of a job of keeping track of which sessions are in use and destroying them when they are no longer doing anything. One of the things it uses to determine if a session is doing anything is whether there is anything running that could post events to that session. In my case, my application is being hung by a TCP client with a connection to a messaging server.

My situation is that all the POE processes in this application have a session that handles a connection to a STOMP-like messaging server. At startup time, all the other sessions post events to the messaging session to inform it which message queues on the server they would like to subscribe to. These sessions will sometimes change their subscriptions as the application runs. I'm using refcount_increment and refcount_decrement from POE::Kernel to indicate to POE that those sessions are still in use as long as they have at least one subscription to a messaging channel.

What I haven't been able to figure out though, is how I can tell POE that those sessions that are not subscribed to any messaging queues should not include the fact that there are events being generated by the messaging session in the calculation of which sessions are still active.

Basically, right after startup my application looks something like this....

Messaging Session
Connected to STOMP server
Worker Session 1
Subscribed to /queue/foo/bar
Worker Session 2
Subscribed to /queue/something/else
Worker Session 3
Worker Session 4

The problem is that when POE is determining which sessions are still active, it thinks that all four worker sessions are still in use, because they may get sent events from some of the other sessions, so it doesn't shut them down. Because of the design of the application, I know that this isn't the case, the worker sessions don't communicate with each other directly, if they do have information to send to one another (and in the vast majority of cases, they won't) then they will always send it through the STOMP server. I also know that the worker sessions that aren't subscribed to any queues and don't have any events of their own queued up, will never get sent another event, they will always idle until the application ends. So what I'm looking for is a way to tell POE this is the case, so I don't have these extra sessions hanging around all the time.

If it isn't possible to do this at the session level, I'd settle for a way to tell POE that the application can end if the only thing keeping it alive is that socket connection. At least that way my tests wouldn't hang. :) I've looked at POE::Kernel::_idle_queue_{grow,shrink}, but they seem to only apply to the event queue, not to filehandles being watched.

What I'm doing currently is not connecting to the server until a subscription is active, and then shutting down the connection when the last subscription is unsubscribed, which works OK, but is less than ideal, and has some issues (like if a session unsubscribes from the last subscription, and then subscribes to something else, causing the connection to drop and reconnect).

Any suggestions would be appreciated!


We're not surrounded, we're in a target-rich environment!

In reply to Telling POE to ignore a filehandle for garbage collection purposes? by jasonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.