aiodynamo icon indicating copy to clipboard operation
aiodynamo copied to clipboard

Why 24.7 is slower than 22.12 ?

Open d-nishchay opened this issue 1 year ago • 5 comments

We are using 22.12 since long and whenever we try to use 24.7 version, the same queries which takes 8 seconds to complete via older version are taking 40 seconds via new version.

We have tested this many times and still facing the same performance.

What are we missing ?

d-nishchay avatar Sep 07 '24 19:09 d-nishchay

Via 22.12 version: image

Via 24.7 version: image

Same code, only version upgraded via poetry.

d-nishchay avatar Sep 07 '24 19:09 d-nishchay

That’s probably too little to go on.

if you’ve got a local setup, perhaps you could run git bisect to narrow it down?

dimaqq avatar Sep 07 '24 23:09 dimaqq

Agree with dimaqq, this isn't enough information to go on.

  • Can you share the code used?
  • Are you sure that the aiodynamo version is the only thing changed (could it be a dependency of aiodynamo that got upgrade alongside it? did no other code/dependency change?)
  • As dimaqq said, a git bisect to narrow down which change in aiodynamo seems to have caused this would be useful, or if that's impossible, at least which version between 22.21 and 24.7?

As a side-note, if performance is a concern to you, there's a few things you can/should do:

  • Always re-use Credentials. Your app/script should only ever create a single Credentials instance.
  • Always re-use the HTTP client. All your aiodynamo clients should use the same HTTP client session.
  • Make sure your HTTP client is configured correctly. In one project where we use aiohttp as the HTTP client we doubled the per-host connection limit (the limit argument to TCPConnector and added logging (see tracing) to get warned if we hit that limit. httpx presumably has similar tuning options.

ojii avatar Sep 09 '24 09:09 ojii

Ok thanks for your responses, here's a sample code:

from aiodynamo.client import Client
from aiodynamo.credentials import Credentials
from aiodynamo.expressions import HashKey
from aiodynamo.http.aiohttp import AIOHTTP
from aiohttp import ClientSession

async def get_all_wars() -> list:
    """
    get_all_wars()
    """

    async with ClientSession() as session:
        client = Client(AIOHTTP(session), Credentials.auto(), "us-west-2")

        table = client.table("db_table_wars")
        all_wars = [record async for record in table.scan()]

        return all_wars

Now this code if run using 22.12 aiodynamo, would fetch me results in like 2 seconds (for example), but same if run via 24.7 (which is upgraded through poetry.toml file update) would fetch me results in like 8 seconds.

d-nishchay avatar Sep 09 '24 20:09 d-nishchay

@d-nishchay can you provide profile output for the two versions in your environment? Basically run your script using python -m cProfile -o output.prof scriptname.py then upload the "output.prof" files for inspection.

ojii avatar Sep 11 '24 02:09 ojii