Discussion:
[Twisted-Python] asynchronous response
Kevin Mcintyre
2015-12-17 00:11:36 UTC
Permalink
Hey - I'm confused, so nothing new :) ...but I'm running at this example
and I'm scratching my head.

http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html

I would've thought 2 requests could be served simultaneously, but when I
fire off 2 requests the first received gets it's response after 5 seconds,
while the second response takes 10 seconds.

I think I understand what's happening, but I don't know why...and I would
love an example where the subsequent request doesn't have to wait for the
first request to finish.

Thanks,
Kevin
Kevin Mcintyre
2015-12-17 07:58:00 UTC
Permalink
Just a follow-up with my own sanity check example.

http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html

My conclusion is that deferLater is a blocking method - am I wrong?
Post by Kevin Mcintyre
Hey - I'm confused, so nothing new :) ...but I'm running at this example
and I'm scratching my head.
http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
I would've thought 2 requests could be served simultaneously, but when I
fire off 2 requests the first received gets it's response after 5 seconds,
while the second response takes 10 seconds.
I think I understand what's happening, but I don't know why...and I would
love an example where the subsequent request doesn't have to wait for the
first request to finish.
Thanks,
Kevin
Amber "Hawkie" Brown
2015-12-17 08:09:42 UTC
Permalink
Hey - I'm confused, so nothing new :) ...but I'm running at this example and I'm scratching my head.
http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
I would've thought 2 requests could be served simultaneously, but when I fire off 2 requests the first received gets it's response after 5 seconds, while the second response takes 10 seconds.
I think I understand what's happening, but I don't know why...and I would love an example where the subsequent request doesn't have to wait for the first request to finish.
Thanks,
Kevin
I've ran into this before -- browsers sometimes rate-limit requests, and won't actually send the second request until the first is done, over the same connection, rather than making a second TCP connection -- try using cURL or wget, which has no such limitation, and see if it works any better.

- Amber
Kevin Mcintyre
2015-12-17 08:38:55 UTC
Permalink
holy moly - you're right! This fool will sleep so much better...a million
thanks.

On Thu, Dec 17, 2015 at 12:09 AM, Amber "Hawkie" Brown <
Post by Kevin Mcintyre
Post by Kevin Mcintyre
Hey - I'm confused, so nothing new :) ...but I'm running at this example
and I'm scratching my head.
http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
Post by Kevin Mcintyre
I would've thought 2 requests could be served simultaneously, but when I
fire off 2 requests the first received gets it's response after 5 seconds,
while the second response takes 10 seconds.
Post by Kevin Mcintyre
I think I understand what's happening, but I don't know why...and I
would love an example where the subsequent request doesn't have to wait for
the first request to finish.
Post by Kevin Mcintyre
Thanks,
Kevin
I've ran into this before -- browsers sometimes rate-limit requests, and
won't actually send the second request until the first is done, over the
same connection, rather than making a second TCP connection -- try using
cURL or wget, which has no such limitation, and see if it works any better.
- Amber
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Terry Jones
2015-12-17 10:24:54 UTC
Permalink
Hi Kevin

I found it extremely beneficial to read the Twisted sources, in particular
twisted.internet.defer. In your case, see
https://github.com/twisted/twisted/blob/trunk/twisted/internet/task.py#L821

One nice thing that happens when you read the source is that you see quite
a number of API methods (including deferLater, and also succeed, fail,
maybeDeferred, some of the Deferred class methods, DeferredList, and the
wonderful DeferredQueue) are actually just a few lines of code, doing
something quite simple with a deferred. I found that figuring out how they
all did what they did made my understanding of deferreds much better. I
really love deferreds :-) Here's a bit I wrote about them, using
DeferredQueue as the example
http://blogs.fluidinfo.com/terry/2010/07/23/asynchronous-data-structures-with-twisted-deferreds/

Hope that helps.

Terry
Post by Kevin Mcintyre
holy moly - you're right! This fool will sleep so much better...a million
thanks.
On Thu, Dec 17, 2015 at 12:09 AM, Amber "Hawkie" Brown <
Post by Kevin Mcintyre
Hey - I'm confused, so nothing new :) ...but I'm running at this
example and I'm scratching my head.
http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
Post by Kevin Mcintyre
I would've thought 2 requests could be served simultaneously, but when
I fire off 2 requests the first received gets it's response after 5
seconds, while the second response takes 10 seconds.
Post by Kevin Mcintyre
I think I understand what's happening, but I don't know why...and I
would love an example where the subsequent request doesn't have to wait for
the first request to finish.
Post by Kevin Mcintyre
Thanks,
Kevin
I've ran into this before -- browsers sometimes rate-limit requests, and
won't actually send the second request until the first is done, over the
same connection, rather than making a second TCP connection -- try using
cURL or wget, which has no such limitation, and see if it works any better.
- Amber
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________
Twisted-Python mailing list
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Marco Giusti
2015-12-18 15:08:45 UTC
Permalink
Post by Amber "Hawkie" Brown
Post by Kevin Mcintyre
Hey - I'm confused, so nothing new :) ...but I'm running at this
example and I'm scratching my head.
http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous-deferred.html
I would've thought 2 requests could be served simultaneously, but
when I fire off 2 requests the first received gets it's response
after 5 seconds, while the second response takes 10 seconds.
I think I understand what's happening, but I don't know why...and I
would love an example where the subsequent request doesn't have to
wait for the first request to finish.
Thanks,
Kevin
I've ran into this before -- browsers sometimes rate-limit requests,
and won't actually send the second request until the first is done,
over the same connection, rather than making a second TCP connection
-- try using cURL or wget, which has no such limitation, and see if it
works any better.
I don't think this is a limitation per se. For what I remember the http
1.1 specification says that the browser should wait for the first
response before they continue to send the other requests. Those can be
then sent in pipeline. So no limitation but specification.

I hope I did not misunderstood your respose.
Marco

Loading...