in reply to Re: Using Net::Server::Multiplex and polling Spread
in thread Using Net::Server::Multiplex and polling Spread

So, does the request that the client sends in get re-sent via Spread and then the client sits and wiats for the response? If that's the case, Net::Server::Multiplex seems like a bad fit.

The client connections will be long lived. They will not be for a single request like say a HTTP request. The logic of the system is a state machine that changes based on input from the clients. When the state changes more than just the client who's input caused the change will be notified.

There will be many state machines in both instances and logic (eg groups of clients). I was going to allow them to be running process and have one network interface process to keep the client-server interface simple (also clean for firewalls).

Spread::Queue::Worker looks like it would be great for single requests but it still replies to the Spread system. (Reading a message from Spread blocks and the process should be able to deal with input from clients even if no Spread messages are ready. That's why it was going to poll Spread for messages while using the mutiplexing net I/O.)
  • Comment on Re^2: Using Net::Server::Multiplex and polling Spread

Replies are listed 'Best First'.
Re^3: Using Net::Server::Multiplex and polling Spread
by perrin (Chancellor) on Jul 04, 2004 at 14:50 UTC
    It does sound like you have to do your own event loop then, if you want to be able to catch Spread events even when there is no action to or from the clients. I don't see any obvious way to make this work with Net::Server::Multiplex. Maybe POE would be more appropriate.
      N:S:M doesn't have a hook function inside the loop. If it did I could just set a timer using Time::HiRes to send a SIGALRM which I think would break out of the select() call that the process is blocked on and let a hook function run. After the hook the flow would move around to the select() again.

      Well I do have the source for N:S:M so... I just overrode the loop() function in my own program with a copy of the function by just changing the following bit of code from
      $mux->loop(sub { my ($rdready, $wrready) = @_; &check_sigs(); $mux->endloop if $prop->{_HUP}; });
      to
      $mux->loop(sub { my ($rdready, $wrready) = @_; &check_sigs(); $self->inner_loop_hook; # user customizable hook $mux->endloop if $prop->{_HUP}; });
      All I did was add the line:
      $self->inner_loop_hook; # user customizable hook
      And then I just defined my own hook function as:
      sub inner_loop_hook { print "Dude! " , time , "\n"; }
      I haven't tested any of this with Spread yet which will take a while yet. Also I setup a timer with these lines at the top of the program.
      use Time::HiRes qw( setitimer getitimer ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ); setitimer(ITIMER_REAL, 3, 1); $SIG{ALRM} = sub { return };
      Which will wait 3 seconds before starting and then send a SIGALRM every 1 second after that.
        Sounds like it could work, if you implement your Spread polling inside the hook you added. I'm not sure what the alarm stuff is for. Isn't the whole point of select() that it doesn't block? Let us know how it works out.