API service and the DB database service has been continuously increasing. #15653

Closed
opened 2026-02-21 19:22:44 -05:00 by yindo · 3 comments
Owner

Originally created by @seal1995 on GitHub (Jul 24, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.4.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

After conducting tests with 50 different users, the memory usage of the API service and the DB database service has been continuously increasing. Even after the calls have ended, it still doesn't drop. Why is this happening?
When the service is just started:
Image
After multiple calls, upon the completion of the calls:
Image

✔️ Expected Behavior

The memory occupied by the service should be reclaimed and should not keep increasing.

Actual Behavior

The memory occupied by the service has been continuously increasing.

Originally created by @seal1995 on GitHub (Jul 24, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.4.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce After conducting tests with 50 different users, the memory usage of the API service and the DB database service has been continuously increasing. Even after the calls have ended, it still doesn't drop. Why is this happening? When the service is just started: <img width="1318" height="387" alt="Image" src="https://github.com/user-attachments/assets/3296aa06-48cb-41d3-9c21-c2b955905d16" /> After multiple calls, upon the completion of the calls: <img width="668" height="195" alt="Image" src="https://github.com/user-attachments/assets/4a5b696c-81ae-48c1-9c68-878337cc5893" /> ### ✔️ Expected Behavior The memory occupied by the service should be reclaimed and should not keep increasing. ### ❌ Actual Behavior The memory occupied by the service has been continuously increasing.
yindo added the 🐞 bugoutdated labels 2026-02-21 19:22:44 -05:00
yindo closed this issue 2026-02-21 19:22:44 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 24, 2025):

Hi @seal1995! I'm Dosu and I’m helping the dify team.

This kind of continuous memory increase in both the API and DB services can happen if threads or resources aren't being properly cleaned up after requests. Dify's API service creates a new thread for each user/task request, and while DB sessions are closed at the end of each thread, there isn't centralized management for thread cleanup or explicit garbage collection. Under heavy load, orphaned threads or lingering references can cause memory to be retained even after requests finish.

Recent pull requests have addressed related issues: a fix for Celery worker memory leaks was included in v1.4.2, and another PR improved ThreadPool cleanup to prevent leaks in long-running scenarios. There have also been changes to caching logic that could impact memory usage, so it's worth ensuring your deployment includes these fixes (Celery worker leak fix, ThreadPool cleanup, caching changes).

For further investigation, monitor the number of active threads and memory usage over time (using tools like htop, docker stats, or Python memory profilers). Check for orphaned threads or unreleased resources. You might also try limiting the number of concurrent threads, enabling periodic garbage collection, or tuning DB connection pool settings to see if that helps reclaim memory.

Could you clarify which database backend you're using (PostgreSQL, MySQL, etc.)? That can help narrow down DB-specific tuning or known issues.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Jul 24, 2025): <!-- Greeting --> Hi @seal1995! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> This kind of continuous memory increase in both the API and DB services can happen if threads or resources aren't being properly cleaned up after requests. Dify's API service creates a new thread for each user/task request, and while DB sessions are closed at the end of each thread, there isn't centralized management for thread cleanup or explicit garbage collection. Under heavy load, orphaned threads or lingering references can cause memory to be retained even after requests finish. Recent pull requests have addressed related issues: a fix for Celery worker memory leaks was included in v1.4.2, and another PR improved ThreadPool cleanup to prevent leaks in long-running scenarios. There have also been changes to caching logic that could impact memory usage, so it's worth ensuring your deployment includes these fixes ([Celery worker leak fix](https://github.com/langgenius/dify/pull/20897), [ThreadPool cleanup](https://github.com/langgenius/dify/pull/22169), [caching changes](https://github.com/langgenius/dify/pull/22597)). For further investigation, monitor the number of active threads and memory usage over time (using tools like `htop`, `docker stats`, or Python memory profilers). Check for orphaned threads or unreleased resources. You might also try limiting the number of concurrent threads, enabling periodic garbage collection, or tuning DB connection pool settings to see if that helps reclaim memory. Could you clarify which database backend you're using (PostgreSQL, MySQL, etc.)? That can help narrow down DB-specific tuning or known issues. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/6e426f93-957d-4f8e-b3a3-2264365a8e39?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/22939)
Author
Owner

@seal1995 commented on GitHub (Jul 24, 2025):

这是来自QQ邮箱的假期自动回复邮件。 收到啦收到啦,我会尽快看的咯,亲

@seal1995 commented on GitHub (Jul 24, 2025): 这是来自QQ邮箱的假期自动回复邮件。 收到啦收到啦,我会尽快看的咯,亲
Author
Owner

@crazywoola commented on GitHub (Jul 24, 2025):

Please upgrade to latest version, we have several fixes related to this issue.

@crazywoola commented on GitHub (Jul 24, 2025): Please upgrade to latest version, we have several fixes related to this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#15653