Re: Re: Twisted PB: returning result as soon as ready

2009-09-28 Thread exarkun

On 06:06 am, jacopo.pe...@gmail.com wrote:

Jean-Paul, thanks a lot for your patient.
I have read most of a the  1CThe Twisted Documentation 1D which I think is 
very good for Deferred and ok for PB but it is really lacking on the 
Reactor. In my case it looks like this is key to achieve what I have in 
mind. I've also just received  1CTwisted network programming essential 1D 
but I don't expect too much from this book. Would you be able to 
suggest me a reference to understand the Reactors? I need to be aware 
of when this is blocked and how to avoid it.


I have a very simple objective in mind. I want to distribute some 
processing to different severs and collect and process results from a 
client as soon as they are ready. To achieve true parallelism it looks 
more complex than expected.


It would probably be best to move to the twisted-python mailing list. 
There are a lot more people there who can help out.


Jean-Pal
--
http://mail.python.org/mailman/listinfo/python-list


Re: Twisted PB: returning result as soon as ready

2009-09-28 Thread exarkun

On 25 Sep, 01:25 pm, jacopo.pe...@gmail.com wrote:

In the following chunk of code the CLIENT receives both the results
from  1Ccompute 1D at the same time (i.e. when the second one has
finished). This way it cannot start  1CelaborateResult 1D on the first
result while the SERVER is still running the second  1Ccompute 1D.
How could I get the first result as soon as ready and therefore
parallelize things?
thanks, Jacopo

SERVER:

fibo=Fibonacci()
fact=pb.PBServerFactory(fibo)
reactor.listenTCP(port,  fact)
reactor.run()

CLIENT:

fact=pb.PBClientFactory()
reactor.connectTCP(host, port,   fact)
d=fact.getRootObject()
n1=1
d.addCallback(lambda obj: obj.callRemote("compute", n1))
d.addCallback(elaborateResult)

d2=fact.getRootObject()
n2=1
d2.addCallback(lambda obj: obj.callRemote("compute",  n2))
d2.addCallback(elaborateResult)

reactor.run()


"elaborateResult" will be called the first time as soon as the Deferred 
returned by the first "compute" call fires.  This will happen as soon as 
the client receives the response from the server.


If you're seeing the first call of "elaborateResult" not happen until 
after the server has responded to the second "compute" call's Deferred 
fires, then it's probably because the two Deferreds are firing at almost 
exactly the same time, which means the server is returning the results 
at almost exactly the same time.


Considering your questions in another thread, my suspicion is that your 
Fibonacci calculator is blocking the reactor with its operation, and so 
even though it finishes doing the first calculation long before it 
finishes the second, it cannot actually *send* the result of the first 
calculation because the second calculation blocks it from doing so. 
Once the second calculation completes, nothing is blocking the reactor 
and both results are sent to the client.


Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Twisted PB: returning result as soon as ready

2009-09-27 Thread jacopo . pecci

Jean-Paul, thanks a lot for your patient.
I have read most of a the “The Twisted Documentation” which I think is very  
good for Deferred and ok for PB but it is really lacking on the Reactor. In  
my case it looks like this is key to achieve what I have in mind. I've also  
just received “Twisted network programming essential” but I don't expect  
too much from this book. Would you be able to suggest me a reference to  
understand the Reactors? I need to be aware of when this is blocked and how  
to avoid it.


I have a very simple objective in mind. I want to distribute some  
processing to different severs and collect and process results from a  
client as soon as they are ready. To achieve true parallelism it looks more  
complex than expected.


Many thank,
Jacopo
-- 
http://mail.python.org/mailman/listinfo/python-list


Twisted PB: returning result as soon as ready

2009-09-25 Thread jacopo
In the following chunk of code the CLIENT receives both the results
from “compute” at the same time (i.e. when the second one has
finished). This way it cannot start “elaborateResult” on the first
result while the SERVER is still running the second “compute”.
How could I get the first result as soon as ready and therefore
parallelize things?
thanks, Jacopo

SERVER:

fibo=Fibonacci()
fact=pb.PBServerFactory(fibo)
reactor.listenTCP(port,  fact)
reactor.run()

CLIENT:

fact=pb.PBClientFactory()
reactor.connectTCP(host, port,   fact)
d=fact.getRootObject()
n1=1
d.addCallback(lambda obj: obj.callRemote("compute", n1))
d.addCallback(elaborateResult)

d2=fact.getRootObject()
n2=1
d2.addCallback(lambda obj: obj.callRemote("compute",  n2))
d2.addCallback(elaborateResult)

reactor.run()
-- 
http://mail.python.org/mailman/listinfo/python-list