terricain / aioboto3

Wrapper to use boto3 resources with the aiobotocore async backend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating session is taking more time than uploading the file

abhinavsp0730 opened this issue · comments

  • Async AWS SDK for Python version: aioboto3==9.6.0
  • Python version: 3.9
  • Operating System: mac

Description

I'm having a fastapi server where I upload file using aioboto3.
But Surprisingly the time taking to create the session and initialing the session client is more than the
the time to upload the file.
I have used line profiler to profile the code.

             Hits         Time  Per Hit   % Time  Line Contents
            1     26882.0  26882.0     26.5      session = aioboto3.Session()
            2      71569.0  35784.5     70.6      async with session.client(
            2       2709.0   1354.5      2.7          await s3.upload_fileobj(
  

@terrycain is there any way I can move session = aioboto3.Session() in the startup of the web application.
But I'm not able to move initialition of session.client to the startup of the web application.

Thanks

See here #279, yeah I definitely wouldn't recommend creating a session repeatedly

@terrycain just wanna confirm, is it safe to do so? Are there any risk of getting the connection closed?

In theory as long as you do async with on .client or .resource, that should suffice

I am also trying to do the same thing. My idea is to build a session and client factory and use it. Keeping the session ok, but keeping the client I still don't know if it's a good practice. do you know?

I've kept clients open in the past, especially when dealing with multiregion stuff, it should be fine to do so but I'd do a bit of stress testing with that as the internals of aiobotocore have changed a fair bit since I've been that deep in the code