Skip to content

Commit 2cdb95f

Browse files
committed
comment
1 parent f49fd84 commit 2cdb95f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

litellm/proxy/db/db_spend_update_writer.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,14 @@ async def _commit_spend_updates_to_db_without_redis_buffer(
528528
529529
This is the regular flow of committing to db without using a redis buffer
530530
531-
Note: This flow causes Deadlocks in production (1K RPS+). Use self._commit_spend_updates_to_db_with_redis() instead if you expect 1K+ RPS.
531+
Multi-rows writes to the database should ideally always be consistently sorted to minimize the likelihood of deadlocks:
532+
ideally the sorting order should be chosen so that writes to ALL indexes on a table happen in the same order across all
533+
concurrent transactions, as any out-of-order concurrent write to the table or ANY index increases the chances of deadlocks.
534+
Finding a single consistent order across multiple indexes is generally impossible, so we pick one to minimize the chance
535+
of transient deadlocks, and retry later if we are unlucky.
536+
537+
Note: This flow can cause deadlocks under high load. Use self._commit_spend_updates_to_db_with_redis() instead
538+
if you experience a high rate of deadlocks that the retry logic fails to handle.
532539
"""
533540

534541
# Aggregate all in memory spend updates (key, user, end_user, team, team_member, org) and commit to db

0 commit comments

Comments
 (0)