Python 3.x python aiohttp响应时间慢
我正在使用aiohttp客户端会话异步检索网页Python 3.x python aiohttp响应时间慢,python-3.x,python-asyncio,aiohttp,Python 3.x,Python Asyncio,Aiohttp,我正在使用aiohttp客户端会话异步检索网页 async def fetch(session, url): #async with session.get(url) as response: async with getattr(session,"get")(url) as response: return await response.text() async with aiohttp.ClientSession() as session: # cal
async def fetch(session, url):
#async with session.get(url) as response:
async with getattr(session,"get")(url) as response:
return await response.text()
async with aiohttp.ClientSession() as session: # call 5
html = await fetch(session, 'http://localhost:8081')
还有其他异步方法来准备数据和处理数据
反应很慢。已启用异步日志记录。它表明:
正在获取地址信息localhost:8081,键入=
取5016.262 ms:[(,,
,6
为什么需要5016ms?尝试
$pip安装aiodns
尝试使用请求发出请求
或urlib3
。结果相同吗?@MikhailGerasimov单个请求的速度要快得多。但问题是,如果加载不足,速度会慢一些。尝试$pip安装aiodns
尝试使用请求发出请求ts
或urllib3
。结果是一样的吗?@MikhailGerasimov一次请求的速度要快得多。但问题是,如果它处于负载下,速度会变慢。