Re: POE HTTP server with WebSocket channel

2013-12-13 Thread Nick Perez
Hey Guido,

I am the author of those modules. And yeah, they are broken and
experimental. I was attempting to create an unholy amalgamation of
MooseX::Declare and POE. It was an abomination that needed to be killed
with fire. I should make sure I clean up those modules. 

That said, I had started hacking on a replacement stack on top of
Reflex, but lost interest. You're welcome to pick it up and finish it
if that is your cup of tea.

http://nickandperla.net/gitweb/?p=reflexive-role-psgiserver.git

It is based on top of Reflexive::Role::TCPServer

https://metacpan.org/pod/Reflexive::Role::TCPServer

If you have any questions, feel free to give me a shout on
irc.perl.org/#poe or #reflex

You can also contact me via XMPP at this same address.


On Thu, 12 Dec 2013 09:23:54 +0100
Guido Brugnara g...@leader.it wrote:

 Il 12/12/2013 08:33, Konstantin Yakunin ha scritto:
  Hello,
 
  Try Plack::Builder
 
  use Plack::Builder;
 
  builder {
 
  }
 
 
 I like! Thanks.
 
 I tried to install POEx-Role-PSGIServer from CPAN but points out the 
 lack of the package POEx-Role-SessionInstantiation [1]
 Here ( https://rt.cpan.org/Public/Bug/Display.html?id=69745 ) the
 author of [1] warns you deleted the package from CPAN because it is
 no longer compatible with the latest versions of Moose :-(
 So, The POEx-... packages are all considered experimental/broken?
 What could I use as a PSGI server, along with POE in a single task?
 
 gdo
 
 
 
  2013/12/11 Guido Brugnara g...@leader.it mailto:g...@leader.it
 
  ===CUT===
  The target is to listen on the same port:
  http://myapp:8000/. and for websocket ws://myapp:8000/ws
 
  I tried to use Protocol::WebSocket with the TCP socket used by
  PoCo::Server::HTTP but my work is stalled.
 
  I saw on CPAN that would be available the following packages :
 
  POEx::Role::PSGIServer - Encapsulates core PSGI server behaviors
  ===CUT===
 
 
 



-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: poe and amqp/rabbitmq as a worker manager

2013-03-15 Thread Nick Perez
None of this sounds particularly difficult, just a SMOP. The
interesting bits aren't getting the job server up and running. What
will be interesting is scaling the server. Am I correct to assume that
the workers now directly pull from the queue? And then you would be
changing that to a single queue puller that will then redistribute to
worker processes? You may end up killing your over all capacity with an
artificial bottleneck. 

We ended up building a similar system (but using 0mq, which has been
both good and bad, but mostly bad, heh) at work with a very small/simple
broker written in C for speed distributing work to individual workers.
But instead of having complicated management, we just opted for a round
robin approach. And instead of querying the broker for stats, we setup
graphite and statsd and the worker processes themselves spit out
metrics in a non-blocking fashion (after sending off the reply) so we
can monitor things like request processing time, various counts on
request resolution, etc.

The workers themselves actually have a control channel to which we can
individually address to tell them to pause/resume/stop. This gives us
the flexibility to do rolling restarts of our workers when we are doing
a deployment of updated worker code.

And knowing that we can easily consume all of the cores on the machine,
our infrastructure is such that we have multiple of such machines and
do round-robin dns (with the ability to drop a host out for maintenance
if needed). 

In the end, I would shy away from monolithic systems, especially in
POE. POE is fast, especially with the right event loop, but ultimately,
it is still a single process. Any time spent processing your management
requests is time that it is not spending assigning work or
gathering results from a worker.

Some things to consider (and watch out for) if you decide to move
forward with this:

Inter-session communication is slow. Really slow. And the number of
sessions that the kernel must keep track of also has an impact on
performance (POE does a lot of book keeping). You'll need to figure out
some sort of serialization mechanism for framing your requests to the
workers. By default, POE::Filter::Reference uses Storable which is
really slow and also produces pretty bloated output. You will need to
possibly consider a different Filter module (I know of someone building
a Filter using Sereal). Also be prepared to manage timeouts and your
worker processes going away and what your master process will do in
those cases. You will likely end up writing more error handling code
than actual get-work-done code.

For what it is worth, I actually wrote our worker code using Reflex (a
better abstraction layer on top of POE). It basically spins up a
singleton session and completes as many operations within a timeslice
as possible to avoid going through the kernel as often. If latency in
your worker processes is a concern you might consider using Reflex.
There are various POE adaptors as well so they interoperate.

On Thu, 14 Mar 2013 18:23:24 -0700
Kevin Goess kgo...@bepress.com wrote:

 We currently use rabbitmq for message between our web application and
 asynchronous workers. The worker management is somewhat ad hoc, and
 we're looking for a way to get a better handle on them.
 
 It looks like POE has the components that I want, so it's finally
 time for me to learn about POE.  But there's an awful lot of POE
 material out there, and I'm afraid if I try to digest it all I'll
 have made a lot of false starts before I find the right path.  Can
 anybody tell me if I'm going in the right direction, or if there's
 already something out there that does this?
 
 I think I want to use POE as a job server driven by the AMQP POE
 client, with workers in separate child processes handled by something
 like POE::Component::Daemon (which has a scoreboard) or
 POE::Wheel::Run.
 
 I'd like to be able to query the server on a management port with
 questions like
 
- How many messages per queue are you receiving
- What's the completion time for jobs on each queue
- How idle/busy are your child workers?
 
 It should be able to take commands like add or drop these queues,
 and it should automatically take care of tasks like making sure no
 queue is being starved in favor of another queue.
 
 Is this the right idea? Is there a general direction for this that
 would be obvious to sketch out that would save me having to
 understand every example in the poe cookbook?
 
 Any pointers would be appreciated.  Thanks!


-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: alarm function under while loop

2012-11-02 Thread Nick Perez
On Fri, 2 Nov 2012 13:12:58 +0530
Gokul Prasad nhgokulpra...@gmail.com wrote:

 Hi,

snip_giant_mess/

Can you nopaste a complete (non)working test case? Trying to help you
debug this piece meal isn't working. Also, explain what it is you are
trying to achieve? Perhaps you do not need to do something so
complicated.  


-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: POE, log4perl and sqlite

2012-10-15 Thread Nick Perez
On Mon, 15 Oct 2012 10:11:32 +0300
Antti Linno antti.li...@gmail.com wrote:

 1) Do POE's sessions run in parallel? 

Not unless you are forking.

 2) Does POE::Component::Log4perl cure this problem?

Unknown. We need to see some code.


I could speculate on a number of things potentially causing this issue.
Are you spinning up more than one process? Do you have any children
processes that are running? Do you use any other mechanism to read from
the sqlite file? What does your database code look like? Are you using
alarm() (perl's alarm, not POE::Kernel's).

Anyhow without any code it is difficult to debug. Please nopaste some
code so we can help you.



-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: catching exceptions?

2012-04-18 Thread Nick Perez
On Wed, 18 Apr 2012 15:57:27 +0300
Gabor Szabo ga...@szabgab.com wrote:

 How am I supposed to catch exceptions?


Please see Exception Handling in POE::Kernel.

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: How to debug POE based app and find memory leak

2012-04-11 Thread Nick Perez
On Wed, 11 Apr 2012 11:33:53 +0300
Gabor Szabo ga...@szabgab.com wrote:

 Hi,
 
 I have written a small POE script fetching web pages but it is leaking
 a lot of memory.
 I wonder if you could give me advice how to track down this memory
 leak?
 
 In a more generic question, are there special tools to debug a program
 using POE ?
 
 regards
Gabor
 


It depends on where the leak might be. POE has fantastic facilities to
tracing its own inner workings including sessions that might be
sticking around. Take a look in POE::Kernel for turning on some of this
information. From my own experience on debugging memory leaks in POE
applications it is typically two places: sessions that don't get GC'd
(zombies), and the heaps in those sessions with ever growing
numbers of keys. After that, you might end up with a cyclic reference
somewhere that doesn't get cleaned up, so you can use Devel::Cycle.
Without looking the code, it is difficult to give you any more pointers.



-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: Multiple LWP::UserAgents at the same time

2012-04-03 Thread Nick Perez
On Tue, 3 Apr 2012 16:57:59 +0300
Gabor Szabo ga...@szabgab.com wrote:

   my $ua = LWP::UserAgent::POE-new(timeout = 10);
   my $response = $ua-get($url) ;


At first glance without reading the documentation to this module, I
would say that this is wrong. Fetching the $url should be a
non-blocking action that you give it a postback (or configured
session/event to post) to notify you when a response is ready for
reading. There is a proper HTTP client for POE that gives you this
ability (albeit with a bit more verbosity). Take a look at
POE::Component::Client::HTTP and see if it better fits the bill for
what you need.



-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
https://metacpan.org/author/NPEREZ
http://github.com/nperez


Re: Modules depending on different event loops in the same POE app?

2011-08-21 Thread Nick Perez
It would probably make sense to run the RCU in a child and have it push
events over the pipes of POE::Wheel::Run. Not as monolithic that way,
but then you could generalize what kind of interface those two pieces
use to chat. At that point you could then replace the RCU part with
anything else that also understands the interface.

On Sun, 21 Aug 2011 16:55:13 +0200
Gunnar Strand gurra.str...@gmail.com wrote:

 I'm working on a simple media control system and I am using POE with
 Tk. I found the RCU (remote control unit) perl module hierachy to
 use with my infrared remote control. RCU can be event-controlled, but
 it is using the Event event loop. Preferably I'd like to have
 everything controlled by the same event loop and not having to poll
 the RCU periodically. Is this doable?
 
 BR
 Gunnar


-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: POE::Session major bug.

2011-04-08 Thread Nick Perez
I do believe this is indeed a bug, but not in POE::Session. It seems
the GC semantics have changed somewhat and call() specifically invokes
a GC sweep in the cases where a return value is expected from an event.

I think this behavior is wrong (and I may have been the ultimate reason
this behavior exists at all [GC after call()], some long long time
ago sadly). For intra-session call()s, GC should not be called.
Effectively, the $kr_active_session is $session, meaning that we are
inside an event in $session that is current executing. GC should be
reserved for when that source event finishes, not in the middle of it.
So what I think is happening is this: his call invokes a GC sweep a
couple of times until it depletes the event_count at which point the GC
sweep will collect the session. But since kr_active_session is still
around, delay() has no problem enqueuing an event against it. Then when
the zombie session's state is invoked, Kernel happily dispatches even
when it can no longer resolve the session (for source_session), since
the reference is still valid. ASSERT_DEFAULT catches this, by the way. 

Recommendation: remove the _data_ses_gc_sweep() calls in call().

For what it is worth the tests seem to run fine on my machine with
these calls removed from call().


On Fri, 8 Apr 2011 11:57:18 +0800
flw su2ad...@gmail.com wrote:

 Sorry for my poor english, let me show it just by code.
 
 flw@waker:~/study$ perl -MPOE -le 'print $POE::VERSION
 $POE::Kernel::VERSION $POE::Session::VERSION'
 1.299 1.299 1.299
 flw@waker:~/study$ ./bug.pl
 start
 call bar 
 inner bar
 call bar 
 inner bar
 found bug.
 call bar 
 call bar 
 call bar 
 flw@waker:~/study$ cat bug.pl
 #!/usr/bin/perl
 use strict;
 use warnings;
 use POE;
 
 create POE::Session(
 package_states = [
 main = [qw( _start foo bar die_on_bug )],
 ],
 );
 
 run POE::Kernel();
 
 sub _start{
 print start\n;
 
 $_[KERNEL]-yield( 'foo' );
 }
 
 exit 0;
 
 my $found_bug;
 
 sub foo {
 my $sess = $_[KERNEL]-_resolve_session($_[SESSION]) || '';
 if ( $_[SESSION] ne $sess and not $found_bug ){
 $found_bug = 1;
 print found bug.\n;
 $_[KERNEL]-delay( die_on_bug = 3 );
 }
 
 print call bar \n;
 my $ret = $_[KERNEL]-call( $_[SESSION] = bar = 1 );# bad
 #$_[KERNEL]-call( $_[SESSION] = bar = 1 ) or 1; # bad
 too #my @ret = $_[KERNEL]-call( $_[SESSION] = bar = 1 );# bad
 too # $_[KERNEL]-call( $_[SESSION] = bar = 1 );  # good
 
 $_[KERNEL]-delay( foo = 1 );
 }
 
 sub bar {
 print inner bar\n;
 }
 
 sub die_on_bug {
 exit 0;
 }
 flw@waker:~/study$


-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: POE and DBI database question

2011-02-17 Thread Nick Perez
When the pre-packaged POE+DBI solutions don't work for you, you can
always spin up a child that talks to you via STDIN/STDOUT using
POE::Wheel::Run and performs the various DBI actions on your behalf.
Then define a simple command/reply interface using dumb hashes and
something like POE::Filter::Reference to transport between the child
and parent process.

And like Andy also said, you won't be able to deal with an ORM unless
you do some fancy footwork to serialize the data into a digestible
format and then reconstitute it across the process boundary. So you
could use DBIx::Class in the child to perform the specific queries for
you based on a set of parameterized Command objects you define. Then
use HashRefInflator on the results to build a Result object and send it
back down the wire.

Something like this:

Parent - Command - Filter - | - Filter - Result - Child
   |
process boundary


On Thu, 17 Feb 2011 21:07:40 +0100
Markus Jansen markus.jan...@ericsson.com wrote:

 Hi POE experts,
 
 is there someone who has used POE in an asynchronous way with DBI,
 without the necessity to reinvent the wheel, with some example or
 recipe at hand?
 
 To illustrate my problem:
 PoCo::SimpleDBI looks nice, but I am not too sure how well this
 behaves inside a forking environment (prefork server).
 DBIx::Connector claims to be great on the prefork matter, but I don't
 see an asynchronous POE example or recipe somewhere. DBIx::Class
 claims to be even greater for non-SQL addicts, and seems to have some
 code in common with DBIx::Connector, but again I fail how to
 integrate that best into a POE environment ...
 
 Any hints / comments are highly welcome!
 
 Best regards,
 Markus
 
 
 
 
 Markus Jansen
 
 Ericsson GmbH
 Eurolab RD
 Ericsson Allee 1
 52134 Herzogenrath, Germany
 Phone +49 2407 575 5157
 Fax +49 22407 575 150
 Mobile +49 172 2742003
 markus.jan...@ericsson.com
 www.ericsson.com
 
 
 
 Ericsson GmbH. Sitz: Düsseldorf. Registergericht: Amtsgericht
 Düsseldorf, HRB 33012. Geschäftsführer: Stefan Koetz (Vors.), Nils de
 Baar, Bernd Schmidt. Aufsichtsratsvorsitzender: Anders Runevad.
 
 This Communication is confidential. We only send and receive email on
 the basis of the terms set out at
 www.ericsson.com/email_disclaimerhttp://www.ericsson.com/email_disclaimer.
 
 


-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: Session lifetime issue (post on behalf of)

2010-03-09 Thread Nick Perez
On Tue, 9 Mar 2010 09:59:30 -0800
Zero Hero zeroh...@qoobly.com wrote:

 I'm trying to solve a common problem which occurs when I'm using
 PoCos. The crux of the issue is that a session doing a post to a
 PoCo, needs to stay alive for work done by a secondary post by that
 PoCo.
 
 Consider:
 1. Session A posts to Session B
 2. In Session B event handler, it posts to Session C on behalf of
 Session A.
 3. Session B exits event handler.
 4. Session A dies, because it's event was handled by B, but it
 has no way of knowing Session C is doing something for it.
 
 Since Session B typically belongs to the other persons PoCo (OPPC),
 I can't really get inside of
 it and change it.  So the solution to this problem must not alter the
 code for the OPPC.
 
 This seems to be a very common second order problem.
 
 Is there some standard technique for solving this?  I've looked at few
 PoCos for solutions, and
 searched for continuation like things (e.g.
 POE::Session::Yield::CC), but these don't seem to
 solve the problem.
 
 Thanks,
 
 Zerohero


Typically what you can do is in Session B, increment the reference
count for Session A (access via $_[+SENDER]) until after Session C
notifies Session B that it's work is complete. Then you can decrement
again. 

The other thing you could do is set up Session A to be
persistent in some fashion, such as polling a shared result queue,
where Session C will ultimately dump the result. 

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: Execute Jobs parallel using JobQueue

2009-12-03 Thread Nick Perez
On Thu, 3 Dec 2009 22:37:37 +0800
Ryan Chan ryanchan...@gmail.com wrote:

 On Wed, Dec 2, 2009 at 2:56 PM, Nick Perez n...@nickandperla.net
 wrote:
  On Wed, 2 Dec 2009 12:42:34 +0800
  Ryan Chan ryanchan...@gmail.com wrote:
 
  If I goes with the fork solution, any abstraction recommended?
 
 
  I don't want to scare you off, but I can also suggest
  POEx::WorkerPool.
 
  --
 
 unfortunately, make failed in CPAN in ubuntu 8.10
 

Can I get the failure output? What version of Perl? Also, why and
operating system so ancient?

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: Execute Jobs parallel using JobQueue

2009-12-01 Thread Nick Perez
On Wed, 2 Dec 2009 12:42:34 +0800
Ryan Chan ryanchan...@gmail.com wrote:

 If I goes with the fork solution, any abstraction recommended?


I don't want to scare you off, but I can also suggest POEx::WorkerPool.

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: run an interactive command using POE::Wheel?

2009-09-26 Thread Nick Perez
On Sun, 27 Sep 2009 10:59:48 +0800
woosley. xu. redic...@gmail.com wrote:

 $_[KERNEL]-sig_child($pid, got_child_signal);

This is your problem line. Remove '$pid,' from the double quotes.
-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: IKC bug for client spawn?

2009-05-05 Thread Nick Perez
On Tue, 5 May 2009 10:34:53 -0700
Josh803316 josh803...@gmail.com wrote:

 It appears that if you start an IKC server and then an ikc client
 connects to it from within the same POE::Kernel-run() then we get
 the following error:
 
 23289: Remote kernel 'host.domain-4a0076da5af9' already exists
 23289: Remote kernel 'host.domain-4a0076da5af9' already exists
 
 Single program flow:
 
 POE::Component::IKC::Server-spawn();
 POE::Component::IKC::Client-spawn();
 
 POE::Kernel-run();
 
 This is where we get the run time error from the client about the
 remote kernel already existing. The error doesn't seem to affect
 anything else but I assume this is either a bug or I'm doing
 something wrong.


Erm, you do realize that IKC is mostly for inter process communication
right? Running both within the same kernel (process) and it throwing
that warning is /exactly/ what it should be doing. 

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: IKC bug for client spawn?

2009-05-05 Thread Nick Perez
On Tue, 5 May 2009 15:54:13 -0700
Josh803316 josh803...@gmail.com wrote:

 Yes, thanks to some members of the list I have been taught that this
 is indeed correct and not a bug.  Makes more sense now.
 
 I was trying to spawn a worker child but wasn't spawning it correctly
 therefore the process was indeed inside the same kernel.  I'm now
 using a wheel::run to spawn the child process and then have the ikc
 client connect. I'm sure there is a more elegant way to do this but I
 need the portability of the clients spawning locally as different
 processes, or on remote machines that would connect back to the
 server.
 
 (Inside the worker template package)
 sub __spawn {
 my $class = shift;
 
 POE::Session-create(
inline_states = {
 _start = \create_ikc_client,
 worker_stdout = \worker_stdout,
 worker_stderr = \worker_stderr,
 worker_error  = \worker_error,
 
},
args = [ $class ]
 );
 
 }
 
 sub create_ikc_client{
 my ( $kernel, $heap, $class ) = @_[ KERNEL, HEAP, ARG0 ];
 
 my $child = POE::Wheel::Run-new(
 Program = sub{
 my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
 
 # Wipe the existing POE::Kernel clean.
 POE::Kernel-stop();
 print STDERR Worker forked\n;
 
 my $addr  = $class-IP   || '127.0.0.1';
 my $port  = $class-PORT || 5667;
 my $trace = $class-TRACE || 0;
 my $debug = $class-DEBUG || 0;
 
  POE::Component::IKC::Client-spawn(
  ip = $addr,
 port   = $port,
 name   = Client$$,
 on_connect = sub {
 
 POE::Session-create(
 package_states =
   ## extract all
 subroutines that don't start with __
   ## and allocate
 them as states:
   [
  (__PACKAGE__)
 = [ do {
 no
 strict 'refs';
 grep {
 !/^__/ and defined $_ } keys %{ __PACKAGE__ . :: };
   } ],
  ($class)
 = [ $class-SUBSCRIBE_METHODS ]
 
   ],
 ## pass args into
 _start:
 args = [$class],
 options =
 { trace = $trace, debug = $debug },
 
 );
 },
 on_error  = sub {
 my ( $kernel ) = $_[ KERNEL];
 print STDERR Dumper($kernel);
 }
 
 );
 
 # Run the new sessions.
 POE::Kernel-run();
 },
 ErrorEvent   = worker_error,
 StdoutEvent  = worker_stdout,
 StderrEvent  = worker_stderr,
 CloseEvent   = worker_close,
 
 ) or die $0: can't POE::Wheel::Run-new;
 
 $heap-{worker} = $child;
 
 return $child;
 }
 
 On Tue, May 5, 2009 at 3:41 PM, Nick Perez n...@nickandperla.net
 wrote:
 
  On Tue, 5 May 2009 10:34:53 -0700
  Josh803316 josh803...@gmail.com wrote:
 
   It appears that if you start an IKC server and then an ikc client
   connects to it from within the same POE::Kernel-run() then we get
   the following error:
  
   23289: Remote kernel 'host.domain-4a0076da5af9' already exists
   23289: Remote kernel 'host.domain-4a0076da5af9' already exists
  
   Single program flow:
  
   POE::Component::IKC::Server-spawn();
   POE::Component::IKC::Client-spawn();
  
   POE::Kernel-run();
  
   This is where we get the run time error from the client about the
   remote kernel already existing. The error doesn't seem to affect
   anything else but I assume this is either a bug or I'm doing
   something wrong.
 
 
  Erm, you do realize that IKC is mostly for inter process
  communication right? Running both within the same kernel (process)
  and it throwing that warning is /exactly/ what it should be doing.
 
  --
 
  Nicholas Perez
  XMPP/Email: n...@nickandperla.net
  http://search.cpan.org/~nperez/ http://search.cpan.org/%7Enperez/
  http://github.com/nperez
 


Wouldn't it be simpler to write the server, write

POE + Moose

2009-04-28 Thread Nick Perez
So I had some expectations out of EC's effort, but doesn't look like
the path being taken is one I necessarily want to follow. But it did
give me some ideas on integrating POE and Moose. 

So I spent some time looking through various POE::Session
implementations: strengths, weaknesses, and raw ideas. I really like
Philip Gwyn's ideas on rolling up the POE stuff (KERNEL, SESSION,
CALLER, etc) into a per-event object (POE::Session::PlainCall), for
example. I also took some time to look at Chris Prather's efforts,
which are very notable in that he appears to be wrapping POE::Session
wholesale.

But it seems to me that perhaps if a POE::Session implementation were
actually a Moose::Role, we could all get succinctness we want, plus the
mutability we need to redefine events at will. Apply the Role to any
object to get an instant session. 

That said, I've started writing a simple POE::Session implementation
(POE::Session::Moose: http://github.com/nperez/psm/tree/master).

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


Re: Application Configuration Across Sessions

2009-04-25 Thread Nick Perez
On Fri, 24 Apr 2009 19:32:11 -0500
johnr jo...@wowway.com wrote:

 Hello,
 
 What is the POE way of accessing application configuration across 
 sessions?   I was working with Config::General (storing config info
 in a session's heap).  However, that is not accessible by other
 sessions. What is the approach for dealing with this?
 
 Thanks,
 
 John
 

There are a couple of ways to do that. You could do some dependency
injection on the constructed sessions so that they get their config
info from the parent session. You could by convention, have each
session know that the config information is stored in the parent
session and therefore call $parent-get_heap(). You could have a
lexical hash that is available to all of the sessions. Etc. Etc.

I think you will find a myriad of ways that other people are doing it.
But I believe the dependency injection of configuration information is
the most common.

-- 

Nicholas Perez
XMPP/Email: n...@nickandperla.net
http://search.cpan.org/~nperez/
http://github.com/nperez


RE: Automating network testing with POE (web services IPC)

2009-04-20 Thread Nick Perez
It really sounds like you need to segregate the webapp from the actual
daemon. And with that, you do not need to run POE within mod_perl (not
that you could anyhow). But you obviously need POE communication
between the web server and the POE daemon. So I recommend using
POE::Component::IKC::ClientLite
(http://search.cpan.org/~gwyn/POE-Component-IKC-0.2003/IKC/ClientLite.pm).
As for worker/controller interaction, IKC can serve those needs too,
without having to involve a protocol layer beyond a TCP socket and the
serializer that IKC uses. 


Re: which http server to use

2004-09-14 Thread Nick Perez
Don't get me wrong, POE and perl in general is really fast considering 
that with a 800MHz Duron (I have ancient hardware, I know) I was able to 
manage 45+ requests per second, including streaming, against a database 
backend (SQLite) with my own home grown http server that incorporated 
HTML::Template::JIT, but it is still perl (even if bits wrap really 
tight C code).

That was a really really specific application. For CGI execution you are 
better off sticking to something that speaks proper CGI like apache 
unless you are wanting to have a stand alone perl application (to ship 
as a web interface for some other POE enabled code or whatever). And 
even then you are probably better off rewriting your CGI scripts to 
exist within a POE environment which completely kills the idea of the 
common gateway interface.

All in all it is going to end up being a lot of work without much gain 
(if any, comparatively for performance) if you already have a working 
solution under apache or something. The POE HTTP server solutions are 
only the bare essentials to manage a TCP connection and filter inbound 
data to build HTTP::Requests. You will need to write supporting code to 
get your CGI solutions integrated which may beyond the scope of your 
project.

-- Nick
Mathieu Longtin wrote:
Hi,
I'm trying to move a bunch of CGI scripts to a POE server,
mostly for performance.
Looking at CPAN, I see three different POE component HTTP
server:
POE::Component::Server::HTTP
POE::Component::Server::SimpleHTTP
POE::Component::Server::HTTPServer
All of which have been patched in the last six months.
So, I guess my questions are:
- What are the differences, beside the names?
- Which should I use?
Thanks
-Mathieu

		
___
Do you Yahoo!?
Express yourself with Y! Messenger! Free. Download now. 
http://messenger.yahoo.com


Re: POE::Component::Jabber shoud support MUC

2004-09-13 Thread Nick Perez
You are more than welcome to write an MUC module that makes use of the 
tools available in PCJ, but PCJ itself is only a transport mechanism. We 
are only building a connection broker. What you want to do with the 
connection after it is established is beyond the scope of the project.

joe jiang wrote:
i think the module should support MUC and have some good sample with it.
Some message sync related project need this feature and i had to use thread
instead of simple impletation of single stread.



Re: POE XML TCP Design

2004-09-05 Thread Nick Perez
You should definitely use POE::Filter::XML. This is a shameless plug for 
my own code, but it really solves the problem of implementing a push 
parser that gives you meaningful chunks of data 
(POE::Filter::XML::Nodes) from which you can process.

If you have any questions please let me know. Right now I am working on 
a new release and hope to have it on CPAN soon (the docs and the actual 
API are a teeny-tiny bit out of sync and I need to explain some 
behaviors a bit more), but what is out there right now is very stable 
and is in use by all all sorts of projects.

-- Nick
Lamb Joseph wrote:
I want to know what components or wheels I need to use
for  my project.
The project consist of simple IO::Socket(maybe POE
client in the future) client sending XML data to POE
Server. The Server parses the XML data and transforms
the data to a HTML template file. 

Thank you,
=
Joseph Lamb
		
__
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 


[Fwd: Re: [PATCH] sslpoe-sanity-patch]

2004-08-21 Thread Nick Perez
Oops. Reply went to Rocco but not the list: here it is.
-- Nick
---BeginMessage---
I guess I should have sent my changes upstream which are in fact the 
very same changes here. I use this in PoCo::Jabber::Client::XMPP and 
also in Server::XMPP but adapted it for my own uses. I am not offering 
to maintain it, but I will test it against my code and perhaps share 
notes on these changes and others with whomever does take up maintainership.

-- Nick
Rocco Caputo wrote:
On Sat, Aug 21, 2004 at 07:07:51PM -0400, Dylan William Hardison wrote:
Some changes to SslClient.pm in sslpoe:
Remove reference to $socket from %Filenum_Object.
Reason: It was keeping the tied filehandle from being DESTROYed.
In the READ method: Change die (handshake failed);
to $! = 104; return undef.
Reason: This makes POE handle it like a normal
error. Dying allowed someone to send garbage via netcat
and crash the program, thus adding a DoS to any server that
uses SSL. That's not good.
However, errno 104 is Connection reset by peer, and this is a lie.
Really the handshake failed... Perhaps some other value should be used 
for $!.

Added a DESTROY method that calls CLOSE,
as CLOSE is not called otherwise.
The patch is attached.

KTHXAPPLIED!

These changes are pretty trivial, and further
work needs to be done on SslClient.pm to make it more robust. Also
perhaps it should properly be named SSLSocketWraper or somesuch?
The name is most confusing.

I wouldn't mind that, but I don't do enough SSL work (as in ANY) to
have a good idea what to do here.  If you'd like, I'm ok with someone
adopting and developing the project a bit.  Preferably someone who
uses it.

---End Message---


Re: POE scalability vs. forking

2004-07-06 Thread Nick Perez
From my own experience using ithreads versus POE with Wheel::Run and 
without Wheel::Run with similar scripts that slam a server for requests 
with a uniprocessor machine, there isn't much difference other than POE 
provides a framework and some pretty slick pre-built components from the 
community that make very trivial work of writing load testers.

Not exactly what you are looking for, but I guess we need to know what 
kind of hardware the tester will be running on to really tell you which 
will be better.

nick
Corey Goldberg wrote:
POE can fork, look at the POE::Wheel::Run module or POE::Component::Child.  
These modules can do forking and management of those children.

Thanks for the reply.  But I am looking for the exclusive or ;) 
Either using forks (outside of POE), or using POE and making use of the event loop (without forking)

-Corey
 


---
 Corey Goldberg
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
 [EMAIL PROTECTED]
---



Re: Trouble with POE::Filter::XML

2004-05-06 Thread Nick Perez
Reply to me off list and I'll help you out :)
I am the author
Aaron Craig wrote:
Hi all.
I would desperately love to use POE.  All of the introductory material 
makes it sound  like just the sort of thing I need.

A bit of background.  I'm writing a simple IRC chatbot script as a favor 
to a friend, and as a learning experience.  The requirements are simple 
- get a bot into a channel and have it react appropriately to private 
messages.  Also, we want to be able to run more than one bot at a time.

Originally, I did a multi-threading script which works fairly well.  
However, I'm having trouble with keeping the bot up in the channel.  I'm 
currently using Net::IRC, which is no longer supported.  It has trouble 
connecting to a server, and drops connections after a few hours.  POE 
seems to have a thriving community, and my friend, after asking around 
on mailing lists and in IRC, got a lot of suggestions for 
POE::Component::IRC.

So: CPAN -- install POE, et al.
The limited documentation at CPAN (which is, according to poe.perl.org, 
the best place to look for documentation) was enough for me to get a 
simple script up and running.  The system seems fairly intuitive, and 
some copy and modifying of Randal Shwartz' example code helped to get me 
started.

Now, I want to be able to read in an XML configuration file for my 
bots.  CPAN -- install POE::Filter::XML.  Check out the POD.  To the 
author's credit, he does admit that the documentation is as clear as 
mud.  Does anyone have any working example code to get a document tree 
from an XML file with this module? :)  The example in the synopsis of 
the module's POD does not work, and an hour or so of playing around with 
it hasn't gotten me any closer.  I've tried to figure out what Wheels 
do, especially ReadWrite, mostly by poring through the source, but I 
just don't have my brain around the system enough to be able to figure 
it out.

Is there documentation out there that I'm missing?  I find it hard to 
believe that such a useful system could have so little documentation.  
I'm sure I've missed a link on poe.perl.org.  Could someone point me in 
the right direction.

Here's what I've got so far:
== 

use strict;
use warnings;
use POE qw(Component::IRC Filter::XML);
my $sConfigPath = shift || chatbot.xml;
POE::Session-new
   (
   main = [ qw(_start _stop input_event) ],
   );
POE::Kernel-run();
exit;
sub _start
   {
   print starting...\n;
   open(XML, $sConfigPath) || die(Can't open config file (looking for 
$sConfigPath): $!);

   my $fltXML = POE::Filter::XML-new();
   my $whlXML = POE::Wheel::ReadWrite-new
   (
   Handle= \*XML, # this isn't in POE::Filter::XML POD, 
but Wheel complains if it isn't here (which, after all makes sense, 
otherwise, what are you parsing?)
   Filter= $fltXML, # verbatim (almost) from 
Filter::XML
   InputEvent= 'input_event',  # verbatim (almost) from 
Filter::XML
   );

   close XML; # is this the place to do this?
   }
sub _stop
   {
   print done\n;
   }
sub input_event
   {
   print got an input event!; # assuming later we'll shift() 
interesting things off of @_ or something
   }

== 

Output from this script looks like this:
== 

C:\perlperl chatbot.pl
starting...
done
rc LOOP VECTOR LEAK: MODE_RD = 0001
!!! Leaked fileno: 3 (total refcnt=2)
!!! Read:
!!! refcnt  = 1
!!! ev cnt  = 0
!!! session = POE::Session=ARRAY(0x1ba1b88)
!!! handle  = GLOB(0x1a6b724)
!!! session = POE::Session=ARRAY(0x1ba1b88)
!!! event   = POE::Wheel::ReadWrite(2) - select read
!!! Write:
!!! refcnt  = 1
!!! ev cnt  = 0
!!! session = POE::Session=ARRAY(0x1ba1b88)
!!! handle  = GLOB(0x1a6b724)
!!! session = POE::Session=ARRAY(0x1ba1b88)
!!! event   = POE::Wheel::ReadWrite(2) - select write
!!! Exception:
!!! refcnt  = 0
!!! ev cnt  = 0
== 

It blocks after printing done
The !!! stuff gets printed after ctrl-C
Observant readers will now understand I'm on a Windows maching, 2k to be 
precise.  Perl is 5.8.3.  I won't include -V output here, but will send 
it later, if that seems necessary.

Ok, I think I've used enough bandwidth for now.
Thanks for the help.