aiosocks
aiosocks copied to clipboard
First socks request takes much more time when compared to other requests
I've noticed that the first request always takes much more time when compared to the later requests of the same session. Below is the code to reproduce this behaviour:
async def connect_aiosocks(session, url):
for i in range(10):
try:
start_time = time.time()
async with async_timeout.timeout(7):
async with session.get(url, proxy=f'socks4://72.11.148.222:56533') as response:
print(f'Request {i} {int(round((time.time() - start_time) * 1000))}ms')
except asyncio.TimeoutError:
continue
except Exception as ex:
print(ex)
continue
async def fetch_aiosocks():
conn = ProxyConnector(remote_resolve=False)
async with aiohttp.ClientSession(connector=conn, request_class=ProxyClientRequest) as session:
await connect_aiosocks(session, 'http://example.com')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch_aiosocks())
Output is the following:
Is this the intended behaviour?
I've tested this behaviour with the normal aiohttp library with http proxies, and it doesn't happen?