BerriAI / litellm

Python SDK, Proxy Server (LLM Gateway) to call 100+ LLM APIs in OpenAI format - [Bedrock, Azure, OpenAI, VertexAI, Cohere, Anthropic, Sagemaker, HuggingFace, Replicate, Groq]
https://docs.litellm.ai/docs/
Other
13.64k stars 1.6k forks source link

[Bug - Investigation]: Redis url is 25 rps vs. using redis_port, redis_host, etc. (100 rps) #3188

Open krrishdholakia opened 6 months ago

krrishdholakia commented 6 months ago

What happened?

When using the redis async client for usage-based-routing-v2, when initializing the redis cache via 'redis_url' it's significantly slower than using redis_port, host, etc.

router_settings:
  routing_strategy: usage-based-routing-v2 
  # redis_url: "os.environ/REDIS_URL"
  redis_host: os.environ/REDIS_HOST
  redis_port: os.environ/REDIS_PORT
  redis_password: os.environ/REDIS_PASSWORD
  usage-based-routing-v2 w/ redis ssl usage-based-routing-v2 w/ redis host name, port, etc. simple-shuffle w/ no redis
RPS 25.4 109.7 161.6

Relevant log output

No response

Twitter / LinkedIn details

No response

krrishdholakia commented 6 months ago

there's no perf impact caused b/c of ssl: Just tested with redis ssl as a env param vs. in the url

ishaan-jaff commented 6 months ago

We see this on our load testing too - the last stable version for using redis url was https://github.com/BerriAI/litellm/releases/tag/v1.35.15

jkolx commented 5 months ago

Possible reason: connection_pool not set properly

REDIS: ignoring argument: connection_pool. Not an allowed async_redis.Redis.from_url arg.

krrishdholakia commented 5 months ago

@jkolx what would the correct way to pass connection pool be? redis doesn't seem to support it with from_url

jkolx commented 5 months ago

Exactly that, you can't. The classmethod creates it's own pool in Redis client. However, you can forward pool creation arguments via the **kwargs.

krrishdholakia commented 5 months ago

worth testing - do you have code for how we should set this instead @jkolx

jkolx commented 5 months ago

Right off the bat I see the pool behavior is different, depending solely on how we instantiate the client. In redis-server --loglevel debug logs:

I haven't found the exact args needed to replicate the pool setup yet. Maybe this is something you can investigate further.

krrishdholakia commented 5 months ago

Curious - how're you using litellm today? @jkolx

matthew-walters commented 4 months ago

Using redis.Redis.from_url() creates a client with a ConnectionPool, whereas using redis.Redis() creates a client with a BlockingConnectionPool