paste the code first
import time
from tornado.gen import coroutine
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.web import Application, RequestHandler
class MainHandler(RequestHandler):
@coroutine
def get(self):
client = AsyncHTTPClient()
urls = ["http://www.baidu.com"] * 20
start = time.time()
yield [client.fetch(url) for url in urls]
print(time.time() - start)
def make_app():
return Application([(r"/", MainHandler), ])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
IOLoop.current().start()
I requested the same link 50 times in the http://localhost:8888/ get method through a browser, but found that the time it took was the sum of all the requests. Baidu found that requesting the same link would block, but did not find a solution.
tried to add different parameters to the link, but it was still blocked.
do you have a solution?