-
Notifications
You must be signed in to change notification settings - Fork 2k
[aiohttp] - use fetchmany api #9865
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
[aiohttp] - use fetchmany api #9865
Conversation
|
@Dreamsorcerer please take a look and sorry for bothering you each time |
All good, I'm interested in any changes. |
|
@Reskov Have we tested with pypy yet? |
|
@Dreamsorcerer no, I am personally not interested in pypy3, but I can add a test if you want. Secondly, we may try to cythonize entire app code. Do you have any thoughts why update performance is much lower than fastapi app have.
|
Looks like FastAPI's fastest runs are on pypy3, so probably worth adding in. I think it's just a case of changing the docker image in the first line?
I think that's a step too far and no longer comparing frameworks. At some point, it'd be good to compile everything under mypyc though, which could easily be adopted to all frameworks (it's probably not quite mature enough yet to work on a general application though). |
|
Fastapi still seems to get better performance on the updates. I'm wondering if one or both of the sorted() calls actually speeds up the DB query? Pypy also seems to be slower for aiohttp for some reason.. |
|
Yeah, also interesting that nginx performs better only on update. So probably the problem is high concurrency and we face locks on the database P.S. about sort it is common technic I guess to avoid deadlock https://stackoverflow.com/questions/46366324/postgres-deadlocks-on-concurrent-upserts https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-DEADLOCKS
|
|
interestingly, looks like top performance framework are updating all rows at once. https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Rust/viz/src/db_pg.rs#L62 p.s. we can do even better i guess with unnest |
I assumed that's what we were doing already, but maybe I'm not familiar enough with the DB functions. |
|
@Dreamsorcerer not exactly I've prepared a draft here #9932 |

New asyncpg 0.30.0 fetchmany do the same stuff that we did in the queries test before, but much faster rather than calling fetchval in the loop. When queries count is low the results are the same, but when numbers of queries grow we can spot the difference.
After
Before