Mapdb and frequent changes on rpi - wrong?

Is the mapdb the wrong solution for persisting an item which changes frequently - every second.

This is running on an RPi still on SD card (RPi4).

looking at glances I can see seem to be a lot more writes to disk than before :frowning:
Previousl solution was to mysql on another ssd-based RPi.

If you use mapdb you likely don’t persist for reporting or graphing purposes but solely to persist states across OH restarts.
You in fact don’t need to persist every change. Just make it everyMinute or everyHour.

And if you run openHABian use menu option 6A to move persistence storage into RAM, that’ll avoid SD wearout and you can continue persisting every second (I can hardly think of a reasonable use case for that but if you want to, you can do).

True. For the most part, the states don’t change often as they’re config. I also have them save once a night.
However, the item I am talking about is the total electric used. I resync that manually with the actual meter and then keep it in sync with the pulses. Any restart of OH will cause this to go out of sync.

I guess there are two things -

  1. I don’t really restart OH that often and when it does restart it only misses a few pulses, it’s not the end of the world.
  2. Any form of persistence will, by it’s very nature, cause IO. I was less worried when it was mysql as that was on a ssd.

If I changed the persistence to 1 minute it only actually writes tthe items that have changed so nothing really to worry about. That would be quite lightweight wouldn’t it?

I’ll live with this until RPi4 supports USB boot and then I won’t care :slight_smile:

I assume that it copies it out of RAM to the SD periodically? If not it kind of kills the point of restoreOnStartup, doesn’t it?

No, it persists all configured Items once a minute whether they changed or not.

Not really. While it probably would work, online sync is not supported by the author of the underlying tools.
It’ll only sync whenever you shutdown the service (which means to unmount dirs so it can only be done when you shutdown the box). But then again as it mustn’t sync every update (which would be pointless in the face of what it’s meant to do) you’ll be losing some ticks anyway on restarts.
You should backup the persistence files.
Ok, so Zero RTO is a different story as we would need to go back to last backup but this is home automation not a bank’s data center.
And the only event that in fact would make you lose past recordings is a HW or power failure.

Is that contrary to this?


I wouldn’t think so, it’s probably the internal time mapdb ‘collects’ data to be synced in order to execute it as a batch.

I can’t think about a reason to persist a power meter with mapdb at all.
Be aware that mapdb will only store the current value of the item, you can’t get any historical data other than when did mapdb store the last time.
mapdb is only to restore an item at startup, but as it’s very likely that the stored value is not the correct current value (a openHAB restart will take some minutes even on fast computers), there is no benefit at all.
If you want to get data about power consumption over time, you will need to use something like influxdb, rrd4j or jdbc.

Only to resume counting after a reboot. I also log to the mysql for history and graphs.

I think I’ll set up a another persistence to log this to mysql and restore and only use it on select items such as this