-
-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Very slow client initialization times #970
Comments
this must be something with your machine, here's my test case: import asyncio
import aiobotocore.session
import botocore.session
import time
async def _boto_client():
client = botocore.session.get_session().create_client('s3')
client.close()
async def _aioboto_client():
async with aiobotocore.session.AioSession().create_client('s3'):
pass
async def main():
reps = 200
# warm-up
await _boto_client()
await _aioboto_client()
start = time.time()
for _ in range(reps):
await _boto_client()
elapsed = time.time() - start
print(f'boto elapsed: {elapsed} per call: {elapsed/reps}')
start = time.time()
for _ in range(reps):
await _aioboto_client()
elapsed = time.time() - start
print(f'aioboto elapsed: {elapsed} per call: {elapsed/reps}')
if __name__ == '__main__':
asyncio.run(main()) results
fundamentally the only thing different between the two is we use aiohttp and botocore uses urllib3 |
I looked at the perf graphs between the two didn't seem too different. btw fixed above code and results. |
I am also getting similar times. Tangentially related: Is there a best practice on how to pass around just the same client for the duration of your server? |
i don't see that from the docs, it does multiple calls with the same client. you should keep your client at the "app" level. i like keeping wrapped it in an async exit stack. |
note aiobotocore is no more heavy weight than botocore (in terms of design, each client holds onto a connection pool, and creating a session has a heavy start-up cost as it reads the service jsons), so you'd have the same issues there. |
Describe the bug
Initializing a client in aiobotocore on my laptop takes on the order of ~200ms.
Initializing a client in botocore takes ~50ms.
Checklist
pip check
passes without errorspip freeze
resultsReproduction
pip freeze results
Environment:
Python 3.10.4
Additional context
A quick profile shows the bulk of time loading SSL certs multiple times?
The text was updated successfully, but these errors were encountered: