from tornado import httpclient import time start = time.time() for x in range(1000): httpclient.AsyncHTTPClient().fetch("https://www.google.com", method="GET") print ('{0} seconds'.format(time.time() - start))
Result 1.11500000954 seconds
1.11500000954 seconds
I wrote this to find out how quickly I can send 1000 requests to any site (I chose google), and I don’t know why, but I feel like I did something wrong, and actually it’s not so fast. if I have something wrong, can someone point out my mistake?
Thank!
Well, yes, you allocated 1000 asynchronous requests to Google and timed it. However, you did not run into overhead by actually calling an HTTP call. This will require a callback-type handler.
, , fetch() - , , - , , . , , , ~ 1 , - , , . , , , , , / - , , - " ".
, , , , , , , .
, tornado . IOLoop. , . , ( async IO).
tornado
IOLoop
:
from tornado import httpclient, ioloop import time start = time.time() loop = ioloop.IOLoop.instance() N = 10 finished = 0 def callback(f): global finished finished += 1 print('%d requests finished' % finished) if finished >= N: loop.stop() print ('{0} seconds'.format(time.time() - start)) for x in range(N): f = httpclient.AsyncHTTPClient().fetch("https://www.google.com", method="GET") loop.add_future(f, callback) loop.start()
1000 (Future , .
Future
Source: https://habr.com/ru/post/1652734/More articles:ASP.NET core web application template does not exist on Visual Studio 15 - asp.net-coreWhat is the point of creating middleware in Coa? - koahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1652731/why-cant-a-function-called-inside-another-one-get-access-to-outer-functions-scope&usg=ALkJrhjlqehtDqpXqn_VO30wr0NlvzyZzQHow to remove numpy on MacOSX? - pythonsklearn "numpy.dtype is the wrong size, try recompiling" in both pycharm and terminal - pythonjQuery - nested or non-directional transitions and animation event handlers / listeners - javascriptHow to execute a function by an unknown number of parameters - javascriptArbitrary x86 codes arbitrary? - assemblyHow to set up a site using Angular 2 on Github pages - javascriptСоединение Https завершено с подключением, закрытым одноранговым узлом на Android 6.0 - javaAll Articles