Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: A server that has a fool as its client: itself

by ikegami (Patriarch)
on Feb 10, 2011 at 19:22 UTC ( [id://887524]=note: print w/replies, xml ) Need Help??


in reply to A server that has a fool as its client: itself

First, it's necessary to understand the data flow.

The purpose is to take information it learns as a client and in turn repeat it to as a server to its clients.

So the flow is unidirectional?

sub run { for (;;) { my $msg = $connection_to_server->get(); $_->send($msg) for @connections_to_clients; } }

To get parallelism, send simply needs to hand off the work to a thread of some sort (including a separate process).

# Client class sub send { my ($self, $msg) = @_; $self->{work_queue}->enqueue($msg); } sub worker { my ($self) = @_; my $q = $self->{work_queue}; for (;;) { my $msg = $q->dequeue(); ... send $msg ... } }

Whether you use Coro, threads, forks or something else seems very incidental.

You could also use polling, but select loops tend to be complicated. The first I'd want to do is give the select loop the above enqueue/dequeue interface shown above. Might as well just use Coro to save the work.

Replies are listed 'Best First'.
Re^2: A server that has a fool as its client: itself
by Anonymous Monk on Feb 10, 2011 at 19:33 UTC
    So the flow is unidirectional?

    Ah, it's bidirectional. I should have clarified, my bad

    Think of these daemons acting as beacons relaying information to one another. Eventually, all the participants in the network of daemons in different places will have the same information.

Re^2: A server that has a fool as its client: itself
by Anonymous Monk on Feb 11, 2011 at 13:57 UTC

    Wow! thanks for that, it does give me a clue into doing this.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://887524]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 12:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found