mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
docs new deadlock fixing architecture
This commit is contained in:
parent
0519c0c507
commit
19914aad11
5 changed files with 58 additions and 1 deletions
48
docs/my-website/docs/proxy/db_deadlocks.md
Normal file
48
docs/my-website/docs/proxy/db_deadlocks.md
Normal file
|
@ -0,0 +1,48 @@
|
|||
import Image from '@theme/IdealImage';
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# High Availability Setup (Resolve DB Deadlocks)
|
||||
|
||||
Resolve any Database Deadlocks you see in high traffic by using this setup
|
||||
|
||||
## What causes the problem?
|
||||
|
||||
LiteLLM writes `UPDATE` and `UPSERT` queries to the DB. When using 10+ pods of LiteLLM, these queries can cause deadlocks since each pod could simultaneously attempt to update the same `user_id`, `team_id`, `key` etc.
|
||||
|
||||
## How the high availability setup fixes the problem
|
||||
- All pods will write to a Redis queue instead of the DB.
|
||||
- A single pod will acquire a lock on the DB and flush the redis queue to the DB.
|
||||
|
||||
|
||||
## How it works
|
||||
|
||||
### Stage 1. Each pod writes updates to redis
|
||||
|
||||
Each pod will accumlate the spend updates for a key, user, team, etc and write the updates to a redis queue.
|
||||
|
||||
<Image img={require('../../img/deadlock_fix_1.png')} style={{ width: '900px', height: 'auto' }} />
|
||||
|
||||
|
||||
### Stage 2. A single pod flushes the redis queue to the DB
|
||||
|
||||
A single pod will acquire a lock on the DB and flush all elements in the redis queue to the DB.
|
||||
|
||||
|
||||
<Image img={require('../../img/deadlock_fix_2.png')} style={{ width: '900px', height: 'auto' }} />
|
||||
|
||||
|
||||
## Setup
|
||||
- Redis
|
||||
- Postgres
|
||||
|
||||
```yaml showLineNumbers title="litellm proxy_config.yaml"
|
||||
general_settings:
|
||||
use_redis_transaction_buffer: true
|
||||
|
||||
litellm_settings:
|
||||
cache: True
|
||||
cache_params:
|
||||
type: redis
|
||||
supported_call_types: []
|
||||
```
|
BIN
docs/my-website/img/deadlock_fix_1.png
Normal file
BIN
docs/my-website/img/deadlock_fix_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
BIN
docs/my-website/img/deadlock_fix_2.png
Normal file
BIN
docs/my-website/img/deadlock_fix_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
|
@ -53,7 +53,7 @@ const sidebars = {
|
|||
{
|
||||
type: "category",
|
||||
label: "Architecture",
|
||||
items: ["proxy/architecture", "proxy/db_info", "router_architecture", "proxy/user_management_heirarchy", "proxy/jwt_auth_arch", "proxy/image_handling"],
|
||||
items: ["proxy/architecture", "proxy/db_info", "proxy/db_deadlocks", "router_architecture", "proxy/user_management_heirarchy", "proxy/jwt_auth_arch", "proxy/image_handling"],
|
||||
},
|
||||
{
|
||||
type: "link",
|
||||
|
|
|
@ -4,3 +4,12 @@ model_list:
|
|||
model: openai/fake
|
||||
api_key: fake-key
|
||||
api_base: https://exampleopenaiendpoint-production.up.railway.app/
|
||||
|
||||
general_settings:
|
||||
use_redis_transaction_buffer: true
|
||||
|
||||
litellm_settings:
|
||||
cache: True
|
||||
cache_params:
|
||||
type: redis
|
||||
supported_call_types: []
|
Loading…
Add table
Add a link
Reference in a new issue