@_tom What openHAB version do you use?
Version 2.2.0 addressed all my CPU overload issues which were:
- Browsers that get disconnected overload Basic UI while trying to reconnect (ESH PR #3449)
- LIFX communication threads ending up in endless loops (ESH issue #4665)
If you’re already on that version you can use the Console see how much CPU time is consumed per thread with: threads --list
It’ll print something like:
Id │ Name │ State │ CPU time │ Usr time
───────┼──────────────────────────────────────────────────────────────────────────────────────────────┼───────────────┼──────────┼─────────
1 │ main │ WAITING │ 2932 │ 2790
2 │ Reference Handler │ WAITING │ 6022 │ 3560
3 │ Finalizer │ WAITING │ 18524 │ 13070
4 │ Signal Dispatcher │ RUNNABLE │ 0 │ 0
8 │ Active Thread: Equinox Container: 3846a7c1-4f25-419f-bb6a-16aee382c1b4 │ TIMED_WAITING │ 790218 │ 619640
10 │ Framework Event Dispatcher: org.eclipse.osgi.internal.framework.EquinoxEventPublisher@569dba │ WAITING │ 98 │ 90
11 │ Start Level: Equinox Container: 3846a7c1-4f25-419f-bb6a-16aee382c1b4 │ WAITING │ 19287 │ 18310
12 │ Karaf Lock Monitor Thread │ TIMED_WAITING │ 1430303 │ 861960
13 │ Karaf Shutdown Socket Thread │ RUNNABLE │ 1 │ 0
25 │ CM Configuration Updater │ WAITING │ 1459 │ 1400
26 │ CM Event Dispatcher │ WAITING │ 0 │ 0
27 │ fileinstall-/openhab/userdata/etc │ TIMED_WAITING │ 1465415 │ 1259490
28 │ Thread-11 │ RUNNABLE │ 2 │ 0
31 │ Thread-14 │ WAITING │ 3630774 │ 3324000
...
The “CPU time” and “Usr time” columns at the right should give an indication how much CPU time a thread has consumed. The higher the number, the more CPU time has been consumed by a thread.
When you’ve found a thread that has gone amok you can acquire stack traces to pin point the code location with either:
-
threads
Listing stack traces for all threads. -
threads <id>
Listing stack trace for a certain thread, where you replace<id>
with the id of the thread.
The stack traces show which instructions a thread is executing. It will print the exact file and line number, e.g. something like:
"CM Configuration Updater" Id=25 in WAITING on lock=java.util.LinkedList@2bf61c
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:83)
at java.lang.Thread.run(Thread.java:748)
"CM Event Dispatcher" Id=26 in WAITING on lock=java.util.LinkedList@1b1975c
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:83)
at java.lang.Thread.run(Thread.java:748)
"fileinstall-/openhab/addons" Id=38 in TIMED_WAITING on lock=org.apache.felix.fileinstall.internal.DirectoryWatcher@ea6bf5
at java.lang.Object.wait(Native Method)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316)
If you can’t access the Console because openHAB no longer responds (due to the high CPU usage), you could create a cronjob that periodically saves all this thread info to a file.
E.g. by executing a command:
/usr/share/openhab2/runtime/bin/client -p habopen "threads --list && threads" > /var/log/openhab2/thread-info-$(date +"%Y-%m-%d_%H-%M-%S")