100% CPU utilization #21987

Closed
opened 2026-02-21 20:15:09 -05:00 by yindo · 4 comments
Owner

Originally created by @guilee1 on GitHub (Jan 30, 2026).

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.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When using the Tongyi third-party plugin for speech-to-text, no audio input will make it stuck in an epoll loop with 100% CPU utilization. Our troubleshooting shows the problem doesn't lie with the third-party plugin, but with the underlying execution logic of the plugin-SDK.

Image

✔️ Expected Behavior

Normal CPU utilization

Actual Behavior

No response

Originally created by @guilee1 on GitHub (Jan 30, 2026). ### 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.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When using the Tongyi third-party plugin for speech-to-text, no audio input will make it stuck in an epoll loop with 100% CPU utilization. Our troubleshooting shows the problem doesn't lie with the third-party plugin, but with the underlying execution logic of the plugin-SDK. <img width="320" height="214" alt="Image" src="https://github.com/user-attachments/assets/e4a991a2-f0af-4a1e-9d23-ebc61b5ca5cb" /> ### ✔️ Expected Behavior Normal CPU utilization ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 20:15:09 -05:00
yindo closed this issue 2026-02-21 20:15:09 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jan 30, 2026):

This issue is already tracked as issue #1542 and is caused by the plugin-SDK execution logic, not the Tongyi plugin itself. The root cause is likely a tight loop in the streaming/event loop logic (see BasePluginClient in api/core/plugin/impl/base.py), which can cause 100% CPU usage when no audio input is present because the loop doesn't properly idle when the stream is empty citation.

There is no official fix yet, but similar issues in previous versions were mitigated by adding a short sleep after empty reads or switching from bytes concatenation to BytesIO for buffer management citation. Upgrading plugins to use the latest dify_plugin SDK (≥0.0.1b76) has also resolved related CPU spikes in other cases citation. You can also try tuning worker/server configuration and Docker resource limits, but these are general mitigations and do not address the underlying bug.

If you want to investigate or contribute a fix, focus on the streaming/event loop logic in the plugin SDK and how it handles idle states when no data is received. Profiling tools like py-spy or strace can help confirm the source of the high CPU usage.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 30, 2026): <!-- Answer --> This issue is already tracked as [issue #1542](https://github.com/langgenius/dify/issues/1542) and is caused by the plugin-SDK execution logic, not the Tongyi plugin itself. The root cause is likely a tight loop in the streaming/event loop logic (see `BasePluginClient` in `api/core/plugin/impl/base.py`), which can cause 100% CPU usage when no audio input is present because the loop doesn't properly idle when the stream is empty [citation](https://github.com/langgenius/dify/blob/d6a787497fb433783f125a3c6984a40d24452ad2/api/core/plugin/impl/base.py#L57-L364). There is no official fix yet, but similar issues in previous versions were mitigated by adding a short sleep after empty reads or switching from bytes concatenation to `BytesIO` for buffer management [citation](https://github.com/langgenius/dify/issues/25098). Upgrading plugins to use the latest `dify_plugin` SDK (≥0.0.1b76) has also resolved related CPU spikes in other cases [citation](https://github.com/langgenius/dify/issues/17442). You can also try tuning worker/server configuration and Docker resource limits, but these are general mitigations and do not address the underlying bug. If you want to investigate or contribute a fix, focus on the streaming/event loop logic in the plugin SDK and how it handles idle states when no data is received. Profiling tools like `py-spy` or `strace` can help confirm the source of the high CPU usage. <!-- 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/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/f32d1c8f-4e3d-4693-9094-db8e1cbe2d31?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20issue%20is%20already%20tracked%20as%20%5Bissue%20%231542%5D%28https%3A//github.com/langgenius/dify/issues/1542%29%20and%20is%20caused%20by%20the%20plugin-SDK%20execution%20logic%2C%20not%20the%20Tongyi%20plugin%20itself.%20The%20root%20cause%20is%20likely%20a%20tight%20loop%20in%20the%20streaming/event%20loop%20logic%20%28see%20%60BasePluginClient%60%20in%20%60api/core/plugin/impl/base.py%60%29%2C%20which%20can%20cause%20100%25%20CPU%20usage%20when%20no%20audio%20input%20is%20present%20because%20the%20loop%20doesn%27t%20properly%20idle%20when%20the%20stream%20is%20empty%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/blob/d6a787497fb433783f125a3c6984a40d24452ad2/api/core/plugin/impl/base.py%23L57-L364%29.%0A%0AThere%20is%20no%20official%20fix%20yet%2C%20but%20similar%20issues%20in%20previous%20versions%20were%20mitigated%20by%20adding%20a%20short%20sleep%20after%20empty%20reads%20or%20switching%20from%20bytes%20concatenation%20to%20%60BytesIO%60%20for%20buffer%20management%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/issues/25098%29.%20Upgrading%20plugins%20to%20use%20the%20latest%20%60dify_plugin%60%20SDK%20%28%E2%89%A50.0.1b76%29%20has%20also%20resolved%20related%20CPU%20spikes%20in%20other%20cases%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/issues/17442%29.%20You%20can%20also%20try%20tuning%20worker/server%20configuration%20and%20Docker%20resource%20limits%2C%20but%20these%20are%20general%20mitigations%20and%20do%20not%20address%20the%20underlying%20bug.%0A%0AIf%20you%20want%20to%20investigate%20or%20contribute%20a%20fix%2C%20focus%20on%20the%20streaming/event%20loop%20logic%20in%20the%20plugin%20SDK%20and%20how%20it%20handles%20idle%20states%20when%20no%20data%20is%20received.%20Profiling%20tools%20like%20%60py-spy%60%20or%20%60strace%60%20can%20help%20confirm%20the%20source%20of%20the%20high%20CPU%20usage.)&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/31740)
Author
Owner

@guilee1 commented on GitHub (Jan 30, 2026):

Since the monkey.patch_all(sys=True) call is placed in the init method, the sleep-based workaround fails to take effect —— as a result, the 100% CPU usage issue persists and remains unmitigated.@dosu

@guilee1 commented on GitHub (Jan 30, 2026): Since the monkey.patch_all(sys=True) call is placed in the __init__ method, the sleep-based workaround fails to take effect —— as a result, the 100% CPU usage issue persists and remains unmitigated.@dosu
Author
Owner

@dosubot[bot] commented on GitHub (Jan 30, 2026):

This happens because monkey.patch_all(sys=True) (usually from gevent) replaces time.sleep with gevent.sleep, which only yields to the gevent event loop. If the event loop isn't running as expected, or if the code structure doesn't cooperate with gevent's concurrency model, the sleep-based workaround (like time.sleep(0.001)) won't actually pause the loop or reduce CPU usage—it just spins, causing 100% CPU load.

To mitigate this, try explicitly using gevent.sleep (import gevent and call gevent.sleep(0.001)) in your idle/wait logic instead of time.sleep. This ensures the event loop yields properly. Also, make sure monkey.patch_all is called before any other imports that might use sockets or threads, as patching order is critical for correct behavior citation.

If you’re running under Gunicorn with the gevent worker (which is Dify’s default), manual monkey.patch_all is usually not needed—Gunicorn applies it automatically. Manual patching in init can cause subtle bugs or race conditions citation.

If you still see high CPU usage, review the event loop logic to ensure it’s not a tight loop and consider switching from bytes concatenation to BytesIO for buffer management, as this has resolved similar issues in the past citation.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Jan 30, 2026): <!-- Answer --> This happens because monkey.patch_all(sys=True) (usually from gevent) replaces time.sleep with gevent.sleep, which only yields to the gevent event loop. If the event loop isn't running as expected, or if the code structure doesn't cooperate with gevent's concurrency model, the sleep-based workaround (like time.sleep(0.001)) won't actually pause the loop or reduce CPU usage—it just spins, causing 100% CPU load. To mitigate this, try explicitly using gevent.sleep (import gevent and call gevent.sleep(0.001)) in your idle/wait logic instead of time.sleep. This ensures the event loop yields properly. Also, make sure monkey.patch_all is called before any other imports that might use sockets or threads, as patching order is critical for correct behavior [citation](https://github.com/langgenius/dify/pull/27611). If you’re running under Gunicorn with the gevent worker (which is Dify’s default), manual monkey.patch_all is usually not needed—Gunicorn applies it automatically. Manual patching in __init__ can cause subtle bugs or race conditions [citation](https://github.com/langgenius/dify/pull/27611). If you still see high CPU usage, review the event loop logic to ensure it’s not a tight loop and consider switching from bytes concatenation to BytesIO for buffer management, as this has resolved similar issues in the past [citation](https://github.com/langgenius/dify/issues/25098). <!-- 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/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/5702d55e-0df8-4016-b889-be7f1437f018?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20happens%20because%20monkey.patch_all%28sys%3DTrue%29%20%28usually%20from%20gevent%29%20replaces%20time.sleep%20with%20gevent.sleep%2C%20which%20only%20yields%20to%20the%20gevent%20event%20loop.%20If%20the%20event%20loop%20isn%27t%20running%20as%20expected%2C%20or%20if%20the%20code%20structure%20doesn%27t%20cooperate%20with%20gevent%27s%20concurrency%20model%2C%20the%20sleep-based%20workaround%20%28like%20time.sleep%280.001%29%29%20won%27t%20actually%20pause%20the%20loop%20or%20reduce%20CPU%20usage%E2%80%94it%20just%20spins%2C%20causing%20100%25%20CPU%20load.%0A%0ATo%20mitigate%20this%2C%20try%20explicitly%20using%20gevent.sleep%20%28import%20gevent%20and%20call%20gevent.sleep%280.001%29%29%20in%20your%20idle/wait%20logic%20instead%20of%20time.sleep.%20This%20ensures%20the%20event%20loop%20yields%20properly.%20Also%2C%20make%20sure%20monkey.patch_all%20is%20called%20before%20any%20other%20imports%20that%20might%20use%20sockets%20or%20threads%2C%20as%20patching%20order%20is%20critical%20for%20correct%20behavior%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/pull/27611%29.%0A%0AIf%20you%E2%80%99re%20running%20under%20Gunicorn%20with%20the%20gevent%20worker%20%28which%20is%20Dify%E2%80%99s%20default%29%2C%20manual%20monkey.patch_all%20is%20usually%20not%20needed%E2%80%94Gunicorn%20applies%20it%20automatically.%20Manual%20patching%20in%20__init__%20can%20cause%20subtle%20bugs%20or%20race%20conditions%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/pull/27611%29.%0A%0AIf%20you%20still%20see%20high%20CPU%20usage%2C%20review%20the%20event%20loop%20logic%20to%20ensure%20it%E2%80%99s%20not%20a%20tight%20loop%20and%20consider%20switching%20from%20bytes%20concatenation%20to%20BytesIO%20for%20buffer%20management%2C%20as%20this%20has%20resolved%20similar%20issues%20in%20the%20past%C2%A0%5Bcitation%5D%28https%3A//github.com/langgenius/dify/issues/25098%29.)&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/31740)
Author
Owner

@fatelei commented on GitHub (Jan 30, 2026):

Self Checks

  • I have read the Contributing Guide and Language Policy.[x] This is only for bug report, if you would like to ask a question, please head to Discussions.[x] I have searched for existing issues search for existing 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.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When using the Tongyi third-party plugin for speech-to-text, no audio input will make it stuck in an epoll loop with 100% CPU utilization. Our troubleshooting shows the problem doesn't lie with the third-party plugin, but with the underlying execution logic of the plugin-SDK.

Image ### ✔️ Expected Behavior Normal CPU utilization

Actual Behavior

No response

the python, full command is what

@fatelei commented on GitHub (Jan 30, 2026): > ### 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.11.1 > > ### Cloud or Self Hosted > Self Hosted (Docker) > > ### Steps to reproduce > When using the Tongyi third-party plugin for speech-to-text, no audio input will make it stuck in an epoll loop with 100% CPU utilization. Our troubleshooting shows the problem doesn't lie with the third-party plugin, but with the underlying execution logic of the plugin-SDK. > > <img alt="Image" width="320" height="214" src="https://private-user-images.githubusercontent.com/26862926/542653056-e4a991a2-f0af-4a1e-9d23-ebc61b5ca5cb.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njk3NTk1ODYsIm5iZiI6MTc2OTc1OTI4NiwicGF0aCI6Ii8yNjg2MjkyNi81NDI2NTMwNTYtZTRhOTkxYTItZjBhZi00YTFlLTlkMjMtZWJjNjFiNWNhNWNiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAxMzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMTMwVDA3NDgwNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2NGM1OGQ5ZGI5ZjFmYWM1YzE3ZWEzNDFlNmQwZmZhYmQ1NDIyNTcyMjQzNTliYzNiYjdlOWU0OTA1MjY2MGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.5r6tDBLfvz1Vah-upezMKuSKO0ZMay-jYPeIqJOHVwo"> > ### ✔️ Expected Behavior > Normal CPU utilization > > ### ❌ Actual Behavior > _No response_ the python, full command is what
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21987