-
-
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
[rrd4j] Write asynchronously to database #14913
Conversation
Signed-off-by: Jan N. Klug <[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.
LGTM, thank you
I am using persistence (RRD4J) only for charts. |
Noone that could explain how I could test that ? |
Enabling DEBUG or TRACE logs should be probably a way to test that RRD4J is working as expected. |
Tested by checking the DEBUG logs. Seems to work perfectly. |
The only reason why I have/had doubts is the logic when an |
I see strange behaviour with chart rendering in BasicUI as if the chart was put in cache after its first rendering. Not sure it is related to this PR. I will come back to the official version to check if it is different. |
It is apparently identical with the current version of the persistence service, so not related to your changes. |
In fact, I can see that values are still stored in database when the item state is updated or every minute (I see the logs) but I have not checked if they are at the right time. I should probably check that with charts or maybe using the REST API to fetch persisted data. |
I was using sitemap visibility to switch between different charts. I believe Basic UI is just hiding/showing a chart when playing with the visibility. If the chart was already loaded, it is of course fast to show it. |
@J-N-K : in case of massive item state updates, it could lead to the creation of a massive number of threads. Is there no limit that we could reach quickly ? At least, I see we are using a dedicated thread pool. Previously the method |
Maybe. Another solution would be to have a queue of entries for each database (similar to what I did in influxdb). I'm just not sure if we can do batch updates in RRD4J. |
If I restore the unchanged version of rrd4j, suddenly the REST API is showing again updated values. |
But I don't see what could be wrong in your changed code... |
Signed-off-by: Jan N. Klug <[email protected]>
I have added the timestamps to the log message, maybe it helps to figure out what is going on. |
@J-N-K : to restore the previous behavior avoiding concurrent writings to database, you just need to move "synchronized" from method That's being said, this synchronized also avoids concurrent writings to different rrd files while it should be possible. Only concurrent writings to the same database should be avoided. Probably something to enhance in a separate PR (no real idea how to implement that). |
Signed-off-by: Jan N. Klug <[email protected]>
Probably we could add a per-name-lock for that. |
With your last version:
And the result of API GET request:
It looks like there is a factor 1000 between the logged timestamps and the time returned by REST API. Time 1683481427 and 1683481551 are not returned by the API. |
...ence.rrd4j/src/main/java/org/openhab/persistence/rrd4j/internal/RRD4jPersistenceService.java
Outdated
Show resolved
Hide resolved
Maybe it is normal as the API field is a I am going to erase my DB file to see if values are really written. |
Signed-off-by: Jan N. Klug <[email protected]>
Could it be that the returned values are the boundaries of the bins in the RRD? |
I tried again and I can confirm that values are stored in DB.
The result of REST API:
I would expect 7 values in DB but the API is returning 11 values ! All that looks very bad and I do not understand why. Let me try again the same scenario with the synchronous version. |
Look at the timestamps: They are exactly 60s apart, which is the bin size of the RRD database. Remember: RRD collects the values in bins, depending on the consolidation function the values are average, max, min, first, last of the values in the bin. My guess would be that we see the first and last value of each bin in this case, which is why we have two values for each timestamp. |
I thought the two values were due we stored two value with oen second diff:
Even with the unchanged version, the result of the API still looks strange to me (even if a little less), sometimes the last value does not match my current item state !!! My current persistence strategy:
My item is in group GParametres, so I would expect to have a new value stored only when the item state is updated (everyChange). I am really asking myself if the REST API and/or query method is working ! For me it is just unusable ! Is there another way to check the content of a rrd file ? Your code should work and I feel I am loosing my time testing it using the REST API ! |
Ok, maybe I am starting to understand. When adding a new value, in fact there is first a new value added for each minute before the old value and the new value, so it can be many values. When switching item from OFF to ON, this will generate OFF OFF OFF ... OFF ON |
I will limit my tests to the rendering of charts. |
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.
Code LGTM, thank you
Ok, my charts in Main UI and Basic UI look good, and they include apparently the last value. |
* [rrd4j] Write asynchronously to database * add timestamps to log message --------- Signed-off-by: Jan N. Klug <[email protected]> Signed-off-by: Thomas Burri <[email protected]>
* [rrd4j] Write asynchronously to database * add timestamps to log message --------- Signed-off-by: Jan N. Klug <[email protected]> Signed-off-by: Matt Myers <[email protected]>
* [rrd4j] Write asynchronously to database * add timestamps to log message --------- Signed-off-by: Jan N. Klug <[email protected]> Signed-off-by: Jørgen Austvik <[email protected]>
Related to #14888 #14900
This is completely untested.