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
44.4k stars 6.22k forks source link

DIFY API [CRITICAL] WORKER TIMEOUT #6617

Open kk-kwok opened 1 month ago

kk-kwok commented 1 month ago

Self Checks

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

After the DIFY API is run, the following error log often appears, and the web page cannot be opened.

[2024-07-24 06:33:40 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:35) [2024-07-24 06:33:41 +0000] [1] [ERROR] Worker (pid:35) was sent SIGKILL! Perhaps out of memory? [2024-07-24 06:33:41 +0000] [39] [INFO] Booting worker with pid: 39

cpu and memory requests and limits

limits:
  cpu: 2
  memory: 8Gi
requests:
  cpu: 2
  memory: 8Gi

api server env

 GUNICORN_TIMEOUT=600  # I have tried setting 360, 600, 1200, and 3600, but all have problems.
 CELERY_WORKER_AMOUNT=1

api server cpu and memory monitor

dify-api-cpu dify-api-memory

api version

I have tried from 0.6.8 to the latest version 0.6.15 and still have the same problem.

✔️ Expected Behavior

To solve this problem, access diffify normally

❌ Actual Behavior

No response

dosubot[bot] commented 1 month ago

@kk-kwok Hello there! I'm a bot here to help you with any bugs, questions, or contributions you have for the DIFY API. Let's work together to solve the issue you're experiencing.

To resolve the worker timeout issue in the Dify API, you can try the following steps:

  1. Increase Gunicorn Workers and Threads:

    • Adjust the GUNICORN_WORKERS and GUNICORN_THREADS environment variables to better utilize your CPU cores. The recommended formula for GUNICORN_WORKERS is:
      number of cpu cores x 2 + 1
    • For GUNICORN_THREADS, you can start with a value like 4 and adjust based on your specific requirements.

    Example configuration:

    GUNICORN_WORKERS=5  # Assuming 2 CPU cores
    GUNICORN_THREADS=4
  2. Check for Memory Leaks:

    • Ensure there are no memory leaks in your application code that could be causing the worker processes to consume excessive memory over time.
  3. Optimize Celery Worker Configuration:

    • The default value for CELERY_WORKER_AMOUNT is 1, but you can increase it based on your workload and available resources.
  4. Enable Detailed Logging:

    • Use Dify's observability features to monitor and analyze application logs and performance. This can help you identify specific issues causing the timeouts.
  5. Review Resource Allocation:

    • Ensure that the resource requests and limits are appropriate for your workload. You might need to increase the memory limit if your application requires more memory.
  6. Update to the Latest Version:

    • Make sure you are using the latest version of Dify, as updates may include performance improvements and bug fixes.

By following these steps, you should be able to mitigate the worker timeout issue and improve the performance of your Dify API deployment [1][2].

To continue talking to Dosu, mention @dosu.