-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[boschshc] Cache mDNS-based bridge discovery results #16211
[boschshc] Cache mDNS-based bridge discovery results #16211
Conversation
The bridge discovery participant receives lots of mDNS events. Previously, all events that contained IP addresses of potential bridges were actively contacted using HTTP requests. On some systems eventually the long polling stops due to too many requests. With this change, we * only consider mDNS events where the name property starts with "Bosch SHC" * cache already discovered bridges so we don't have to contact them over and over again * make sure that this happens in a thread-safe manner because the mDNS events are handled in individual concurrently running threads Signed-off-by: David Pace <[email protected]>
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.
Caching these results is a smart way to workaround the performance issue, but is filtering on the name not allready enough? Maybe i'm wrong, but as these results are cached permanently, there is no way to fix an earlier cached entry.
For instance if you re-connect a bridge under an IP that is allready cached, one could only disable/enable the binding to get the cache cleared.
...rc/main/java/org/openhab/binding/boschshc/internal/discovery/BridgeDiscoveryParticipant.java
Outdated
Show resolved
Hide resolved
...rc/main/java/org/openhab/binding/boschshc/internal/discovery/BridgeDiscoveryParticipant.java
Show resolved
Hide resolved
The executed REST request for the Bosch SHC could cases issues - see related discussion.
We should mention this in the Binding ReadMe. |
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.
Caching works for my test environment.
Based on the traces I can also confirm that we avoid with the name check many other REST requests.
Signed-off-by: David Pace <[email protected]>
Signed-off-by: David Pace <[email protected]>
Hi all, quick update: without the excessive mDNS requests/discoveries my test PI2 is still working stable. Whatever the appropriate fix in the binding is, the amount auf discovery calls need to be drastically minimized. Caching might be a workaround but there might also be better solutions possible to manage that. I am wondering how other bindings handle that. Or is Bosch suddenly excessively sending mDNS announcements? As this cannot be controlled by any 3rd party, it needs to be managed.
Thanks for all your effort and time resolving the issue and maintaining the binding. Please let me know if I could support with any sort of testing. I am happy helping with the new generation II devices. I am really keen to get the Roller Shutter, Dimmer, and Relais supported. Have a great weekend! Cheers, Michael |
* use openHAB cache implementation with 10 minutes timeout * set TTL of openHAB discovery results to 10 minutes as well * remove obsolete parameter and member * enhance Javadocs * adapt/enhance unit tests Signed-off-by: David Pace <[email protected]>
Signed-off-by: David Pace <[email protected]>
Hi @mike-bike, thank you for your comments. To be honest I don't know why we get so many mDNS discovery events, and whether this could be a bug in an underlying implementation. But I think it is still a good idea to cache the results for a certain amount of time. Currently I get ~175 mDNS events in 5 minutes. I only see that they contain different combinations of IP addresses and metadata. Even if this is reduced to 100, 50 or 25 events in 5 minutes, I would still say we should not query the bridge for every event we receive. Once we discovered a bridge successfully, we should remember this result for a few minutes in my opinion. To answer your other questions:
However, your comments brought me to the conclusion that the Thing ID we propose by default for discovered bridges is not optimal. Currently it is the IP address with dashes, e.g. Thank you for your support and your valuable input ❤️ @GerdZanker @jlaur @wborn if you also agree that caching the discovered bridges for a few minutes is the right approach, this PR is ready to be reviewed and merged. Of course it still would be interesting whether you are aware of any changes/bugs in the underlying mDNS framework. Thank you all for reviewing the code 👍 |
Absolutely! The binding cannot control how many mDNS events will be triggered. It would be the responsibility of the binding to be sensitive to stress on the network and especially on the bridges. Would it be possible to define the TTL as a user attribute in the bridge binding?
That's good to know. Then mDNS rediscoveries could be significantly reduced without negative user experience.
I typically rely on the resolver and use DNS names rather than IP addresses. But this is my personal preference - even on static or fixed assigned addresses. If for whatever reason, I'd need to change network configuration, I'd just need to update the /etc/hosts or rely on the DHCP server to manage that. I think, that's why DNS and resolvers have been invented for😀
MAC address would be my second preferred option. I think the Bosch bridge announces itself with a unique name. Mine had
Thanks for your support! |
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.
Thank you @david-pace for your discovery improvements.
It will reduce a lot the REST requests. The SHC requests will happen only every 10 min with your ``ExpiringCacheMap``` and other mDNS entries will never be requested, because the name doesn't match!
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, LGTM
@david-pace and @jlaur is this something to consider for patching 4.1 ? |
If the benefits outweights the risk of regressions, feel free to cherry-pick into |
* [boschshc] Cache mDNS-based bridge discovery results The bridge discovery participant receives lots of mDNS events. Previously, all events that contained IP addresses of potential bridges were actively contacted using HTTP requests. On some systems eventually the long polling stops due to too many requests. With this change, we * only consider mDNS events where the name property starts with "Bosch SHC" * cache already discovered bridges so we don't have to contact them over and over again * make sure that this happens in a thread-safe manner because the mDNS events are handled in individual concurrently running threads Signed-off-by: David Pace <[email protected]> Signed-off-by: Andras Uhrin <[email protected]>
* [boschshc] Cache mDNS-based bridge discovery results The bridge discovery participant receives lots of mDNS events. Previously, all events that contained IP addresses of potential bridges were actively contacted using HTTP requests. On some systems eventually the long polling stops due to too many requests. With this change, we * only consider mDNS events where the name property starts with "Bosch SHC" * cache already discovered bridges so we don't have to contact them over and over again * make sure that this happens in a thread-safe manner because the mDNS events are handled in individual concurrently running threads Signed-off-by: David Pace <[email protected]> Signed-off-by: Jørgen Austvik <[email protected]>
* [boschshc] Cache mDNS-based bridge discovery results The bridge discovery participant receives lots of mDNS events. Previously, all events that contained IP addresses of potential bridges were actively contacted using HTTP requests. On some systems eventually the long polling stops due to too many requests. With this change, we * only consider mDNS events where the name property starts with "Bosch SHC" * cache already discovered bridges so we don't have to contact them over and over again * make sure that this happens in a thread-safe manner because the mDNS events are handled in individual concurrently running threads Signed-off-by: David Pace <[email protected]>
The bridge discovery participant receives lots of mDNS events. Previously, all events that contained IP addresses of potential bridges were actively contacted using HTTP requests. On some systems eventually the long polling stops due to too many requests.
With this change, we
closes #16174