-
Notifications
You must be signed in to change notification settings - Fork 70
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
poll_pending_deposits concurrency #516
Comments
I tested with both SQLite and PostgreSQL. Both get a deadlock at
|
Maybe |
Hi @yuriescl I didn't find the exact reason why you're getting deadlock errors but I suspect it has to do with using rows locked in one connection in another. Django's docs mention that it creates a different DB connection per thread, but the connection that collects the
I've considered doing this, but felt that changing existing integration functions to be That doesn't mean that you cannot use async though. Polaris calls import asyncio
from django.db.models import QuerySet
from asgiref.sync import async_to_sync
def poll_pending_deposits(pending_deposits: QuerySet):
pending_deposits = list(pending_deposits) # execute query
poll_results = async_to_sync(poll_transactions)(pending_deposits)
return [deposit for deposit, idx in enumerate(pending_deposits) if poll_results[idx] is True]
async def poll_transactions(transactions: List[Transaction]) -> List[bool]:
return asyncio.gather(*[poll_transaction(t) for t in transactions], raise_exceptions=False)
async def poll_transaction(transaction: Transaction) -> bool:
<polling code>
return is_ready |
Ok, I appreciate the suggestion, will fiddle around with async and see if I can get more speed on the polling. Thanks! |
I'd like to poll deposits in parallel but it seems Polaris doesn't allow it.
I imagine that's the reason I get so many database is locked errors, but I have no concrete evidence yet.
Looking at this code section from
polaris/management/commands/process_pending_deposits.py
:I can see that Polaris selects the items for update, then uses an atomic block to pass the queryset.
Buy if I try, for example, to create multiple threads inside
rri.poll_pending_deposits
, one to poll each deposit, and dotransaction.save()
inside that thread, I get some kind of deadlock, code just freezes in thesave()
:I might be doing it wrong, maybe I shouldn't be using threads, but since it's a management command, it's not really inside a worker process so it doesn't affect the web server.
How should I poll deposits in parallel?
Thanks
The text was updated successfully, but these errors were encountered: