-
DescriptionI have 10 text sql queries (each take 1 second to execute) that I would like to submit to AWS PostgreSQL to run in parallel. Currently I am doing a I would like to submit all queries at once so that the total time is roughly equal to the longest query time any of the queries. This seems like a simple request, but I think something in Gino is only allowing the connections one at a time possibly? What I DidI tried to do a multi threaded version using a futures and ThreadPoolExecutor, but this caused the queries to take 3 times a long (30 seconds). (The following code segment's
I have a version that runs all 10 SQL queries in serial (with async/awalt), but this still takes 10 seconds to run 10 queries that take 1 second a piece:
So to make a long story, how can I submit queries to PostgreSQL using Gino in parallel? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In your particular case, using threads is not making much sense.
|
Beta Was this translation helpful? Give feedback.
In your particular case, using threads is not making much sense.
asyncio.create_task()
is the correct method, but you may want to check the following:asyncio.Task
. This depends on how you establish the connections and use them:db = Gino()
andawait db.set_bind()
would create a connection pool of up to 10 connections.asyncio.create_task()
will inherit the connection from the caller's context if any.async with db.acquire():
block to ensure it's ex…