New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modbus performance and logging improvements #4304
Conversation
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
This was introduced to get high-level split down for each operation Example log statement: Modbus operation ended, timing info: {total: 476 ms, connection: 15, transaction=4, callback=412} [operation ID 2379c461-b4bc-473f-96f0-0c23987f3250] Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
ac511e9
to
e0678ed
Compare
} | ||
} | ||
} | ||
Exception exception = lastError.get(); | ||
if (exception != null) { | ||
// All retries failed with some error | ||
if (callback != null) { | ||
callbackThreadPool.execute(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to run in some thread right away, similar to other callbacks. Thus, removing call to ExecutorService.execute and invoking the callback directly.
Should have spotted this already in https://github.com/openhab/openhab2-addons/pull/4158
return Optional.empty(); | ||
} | ||
if (!connection.isPresent()) { | ||
logger.warn("Could not connect to endpoint {} -- aborting request {} [operation ID {}]", endpoint, request, | ||
operationId); | ||
if (callback != null) { | ||
callbackPool.execute(() -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to run in some thread right away, similar to other callbacks. Thus, removing call to ExecutorService.execute and invoking the callback directly.
Should have spotted this already in https://github.com/openhab/openhab2-addons/pull/4158
DateTimeType now = new DateTimeType(); | ||
updateStatus(ThingStatus.ONLINE); | ||
updateState(ModbusBindingConstantsInternal.CHANNEL_LAST_WRITE_SUCCESS, now); | ||
if (getThing().getStatus() != ThingStatus.ONLINE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaikreuzer do we want to optimize such things as this one and line 765
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or should the framework be optimized better, @ssalonen how expensive was this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's expensive enough to show up in my profiling studies... Modbus is a tough case since some users have very high poll rates..
Haven't looked into the framework if there is any obvious optimizations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general suggestion is to throttle it in the binding this way if there are status updates every few seconds. I guess that's the case for modbus, so this optimisation is fine. We could also think about moving something like that to the framework, but having it transparent in the binding is imho not bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LIFX binding had a similar issue which was addressed with eclipse-archived/smarthome#3816. It sends the same update at most once a second. That way it can still be used for the "last seen online" feature that will be there some day. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Signed-off-by: Sami Salonen <ssalonen@gmail.com>
Even "last successful read" will not get an update if it is not linked Signed-off-by: Sami Salonen <ssalonen@gmail.com>
0e4e05a
to
5bd5883
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/many-100-modbus-pollers-is-it-slowing-down-the-binding/53496/22 |
* Cache ChannelUID creation for no reason * Timing information for modbus operations This was introduced to get high-level split down for each operation Example log statement: Modbus operation ended, timing info: {total: 476 ms, connection: 15, transaction=4, callback=412} [operation ID 2379c461-b4bc-473f-96f0-0c23987f3250] * Avoid creating DateTimeType for no reason * Throttle ONLINE updates to 1 second Signed-off-by: Sami Salonen <ssalonen@gmail.com>
* Cache ChannelUID creation for no reason * Timing information for modbus operations This was introduced to get high-level split down for each operation Example log statement: Modbus operation ended, timing info: {total: 476 ms, connection: 15, transaction=4, callback=412} [operation ID 2379c461-b4bc-473f-96f0-0c23987f3250] * Avoid creating DateTimeType for no reason * Throttle ONLINE updates to 1 second Signed-off-by: Sami Salonen <ssalonen@gmail.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/modbus-binding-with-wago-controller/60642/21 |
Regression introduced in PR openhab#4304: the thing status description is not passed to thing status updates. Signed-off-by: Sami Salonen <ssalonen@gmail.com>
* [modbus] data thing: update thing status including description Regression introduced in PR #4304: the thing status description is not passed to thing status updates. Signed-off-by: Sami Salonen <ssalonen@gmail.com>
* Cache ChannelUID creation for no reason * Timing information for modbus operations This was introduced to get high-level split down for each operation Example log statement: Modbus operation ended, timing info: {total: 476 ms, connection: 15, transaction=4, callback=412} [operation ID 2379c461-b4bc-473f-96f0-0c23987f3250] * Avoid creating DateTimeType for no reason * Throttle ONLINE updates to 1 second Signed-off-by: Sami Salonen <ssalonen@gmail.com> Signed-off-by: Pascal Larin <plarin@gmail.com>
* [modbus] data thing: update thing status including description Regression introduced in PR openhab#4304: the thing status description is not passed to thing status updates. Signed-off-by: Sami Salonen <ssalonen@gmail.com> Signed-off-by: Pascal Larin <plarin@gmail.com>
* Cache ChannelUID creation for no reason * Timing information for modbus operations This was introduced to get high-level split down for each operation Example log statement: Modbus operation ended, timing info: {total: 476 ms, connection: 15, transaction=4, callback=412} [operation ID 2379c461-b4bc-473f-96f0-0c23987f3250] * Avoid creating DateTimeType for no reason * Throttle ONLINE updates to 1 second Signed-off-by: Sami Salonen <ssalonen@gmail.com> Signed-off-by: Maximilian Hess <mail@ne0h.de>
* [modbus] data thing: update thing status including description Regression introduced in PR openhab#4304: the thing status description is not passed to thing status updates. Signed-off-by: Sami Salonen <ssalonen@gmail.com> Signed-off-by: Maximilian Hess <mail@ne0h.de>
Some small performance improvements identified using JProfiler:
Furthermore, logging improved to give clear outline of bottle necks (from raspberry pi 3B):
(currently most of the time is spent in the binding.modbus when data has been already received from the slave)