Skip to content

Apply timeout logging to scheduled executor service - #4948

Merged
holgerfriedrich merged 3 commits into
openhab:mainfrom
andrewfg:log-scheduler
Aug 11, 2025
Merged

Apply timeout logging to scheduled executor service#4948
holgerfriedrich merged 3 commits into
openhab:mainfrom
andrewfg:log-scheduler

Conversation

@andrewfg

@andrewfg andrewfg commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

If scheduled tasks take longer than a certain period of time to complete, and the log level is debug, then a message is output in the log together with the stack trace showing where the task was created.

Resolves #4947

One would activate the logging via

log:set DEBUG org.openhab.core.internal.common.WrappedScheduledExecutorService

Signed-off-by: Andrew Fiddian-Green software@whitebear.ch

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg
andrewfg requested a review from a team as a code owner August 9, 2025 17:43
Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@Nadahar

Nadahar commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

@andrewfg FYI: You can retrieve and inspect the queue, and some basic info like the number of running threads from the thread pools themselves. That might be "a less involved way" to monitor them than to send "test tasks" through the pipeline regularly.

@andrewfg

andrewfg commented Aug 9, 2025

Copy link
Copy Markdown
Contributor Author

I am trying to avoid adding an extra monitor task to monitor the other tasks. So I just want to let each task monitor itself.

@Nadahar

Nadahar commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

But don't you need a task to inject the monitoring tasks?

@wborn
wborn requested a review from Copilot August 9, 2025 19:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds timeout logging functionality to the task scheduler to monitor long-running scheduled tasks. If a scheduled task exceeds 5 seconds, it logs a debug message with the stack trace showing where the task was originally created.

  • Implements timing wrapper classes for Runnable and Callable objects
  • Overrides all schedule methods to wrap tasks with timeout monitoring
  • Captures stack traces at task creation time for debugging purposes

@Nadahar

Nadahar commented Aug 9, 2025

Copy link
Copy Markdown
Contributor

If the idea is to wrap all tasks in a wrapper that measures timing, I'm pretty sure this will much more expensive than having a monitoring thread keeping an eye on the pools. I thought you were only planning on sending "probing tasks" through the pool at intervals.

The ability to grab the stack trace probably requires some form of wrapping, but is it really worth the extra cost and complexity?

@andrewfg

andrewfg commented Aug 9, 2025

Copy link
Copy Markdown
Contributor Author

don't you need a task to inject the monitoring tasks?

No.

Signed-off-by: Andrew Fiddian-Green <software@whitebear.ch>
@andrewfg

andrewfg commented Aug 9, 2025

Copy link
Copy Markdown
Contributor Author

ability to grab the stack trace probably requires some form of wrapping, but is it really worth the extra cost and complexity?

I modified it so we only wrap the tasks if logger.isDebugEnabled() .. and otherwise just pass through..

@holgerfriedrich holgerfriedrich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.
Interesting approach.

@holgerfriedrich
holgerfriedrich merged commit 13ffa1c into openhab:main Aug 11, 2025
4 checks passed
@holgerfriedrich holgerfriedrich added the enhancement An enhancement or new feature of the Core label Aug 11, 2025
@holgerfriedrich holgerfriedrich added this to the 5.1 milestone Aug 11, 2025
@openhab-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-0-release-discussion/165032/237

@openhab-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-0-release-discussion/165032/244

@andrewfg andrewfg changed the title Apply timeout logging to the task scheduler Apply timeout logging to scheduled executor service Aug 24, 2025
@openhab-bot

Copy link
Copy Markdown
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-1-milestone-discussion/166385/55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement An enhancement or new feature of the Core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[threadpool] Add logging of slow tasks

5 participants