langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
39.63k stars 5.43k forks source link

requests overflow #6136

Open zhang001122 opened 2 weeks ago

zhang001122 commented 2 weeks ago

Self Checks

Dify version

0.6.13

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. self define a rag module in the workshop
  2. use the api v1/chat-messages to call the api
  3. request will return docker-db-1 requests overflow
  4. then the client cannot call after 5minuets
  5. dify-0.6.9 before the api funciton work well

✔️ Expected Behavior

api requests on dify0.6.13

❌ Actual Behavior

api requests fail after 30 requests

dosubot[bot] commented 2 weeks ago

Hello, @zhang001122! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let's work together to resolve this issue.

The "docker-db-1 requests overflow" error after 30 requests in Dify version 0.6.13 is likely due to the database connection pool size configuration. In the provided .env.example file, the SQLALCHEMY_POOL_SIZE is set to 30:

# The size of the database connection pool.
# The default is 30 connections, which can be appropriately increased.
SQLALCHEMY_POOL_SIZE=30

This means that the database connection pool can handle up to 30 connections simultaneously. If the number of API requests exceeds this limit, additional requests will be queued or fail, leading to the "requests overflow" error.

To resolve this, you can increase the SQLALCHEMY_POOL_SIZE value to a higher number to accommodate more simultaneous connections. For example:

SQLALCHEMY_POOL_SIZE=50

Additionally, you might want to check other related configurations in the docker-compose.yaml file, such as SQLALCHEMY_POOL_RECYCLE and SERVER_WORKER_AMOUNT, to ensure they are optimized for your use case. For example:

# Database connection pool recycling time, the default is 3600 seconds.
SQLALCHEMY_POOL_RECYCLE: ${SQLALCHEMY_POOL_RECYCLE}

# The number of API server workers, i.e., the number of gevent workers.
# Formula: number of cpu cores x 2 + 1
SERVER_WORKER_AMOUNT: ${SERVER_WORKER_AMOUNT}

This change should help mitigate the "requests overflow" error by allowing more concurrent database connections and optimizing the server worker configuration [1][2].

To continue talking to Dosu, mention @dosu.

zhang001122 commented 2 weeks ago

i have tried your method, while is not work well the error is IF YOUR SYSTEM treat each requests as a new connection to the database, this will cause a BIG BIG PROBLEM IN YOUR SYSTEM , please solve it ASAP

dosubot[bot] commented 2 weeks ago

@takatost, this one's a bit out of my wheelhouse, could you step in and provide your guidance?

To continue talking to Dosu, mention @dosu.