Skip to content
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

File for the cached Thing states is written after every change of the state #586

Closed
MennerM opened this issue Oct 18, 2022 · 2 comments
Closed

Comments

@MennerM
Copy link

MennerM commented Oct 18, 2022

The function storeThingState in ThingManagerImplementation writes every time after a cached thing is changed to the permanent storage.
The destructor destroys the settings object and any changes will be written to permanent storage.

pi@raspberrypi:/var/cache/nymea/thingstates# stat 68e376be-f482-4beb-b7dd-10c3add90d79.cache 
  File: 68e376be-f482-4beb-b7dd-10c3add90d79.cache
  Size: 1018      	Blocks: 8          IO Block: 4096   regular file
Device: b301h/45825d	Inode: 15165       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-10-18 19:36:05.307630844 +0200
Modify: 2022-10-18 19:36:05.307630844 +0200
Change: 2022-10-18 19:36:05.317631206 +0200
 Birth: -
pi@raspberrypi:/var/cache/nymea/thingstates# stat 68e376be-f482-4beb-b7dd-10c3add90d79.cache 
  File: 68e376be-f482-4beb-b7dd-10c3add90d79.cache
  Size: 1018      	Blocks: 8          IO Block: 4096   regular file
Device: b301h/45825d	Inode: 15165       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-10-18 19:36:06.337668135 +0200
Modify: 2022-10-18 19:36:06.337668135 +0200
Change: 2022-10-18 19:36:06.347668497 +0200
 Birth: -
pi@raspberrypi:/var/cache/nymea/thingstates# stat 68e376be-f482-4beb-b7dd-10c3add90d79.cache 
  File: 68e376be-f482-4beb-b7dd-10c3add90d79.cache
  Size: 1019      	Blocks: 8          IO Block: 4096   regular file
Device: b301h/45825d	Inode: 15165       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-10-18 19:36:16.308029197 +0200
Modify: 2022-10-18 19:36:16.308029197 +0200
Change: 2022-10-18 19:36:16.318029560 +0200
 Birth: -
@mzanetti
Copy link
Member

mzanetti commented Oct 18, 2022

What exactly is the issue here? I suppose this is about the frequent disk I/O?
So this is mainly done in order to deal with power losses as users tend to just cut the power cord on the devices running nymea.
I think there was a branch somewhere which would allow a configuration option to only cache on shutdown, but it never landed at this caused too many issues. I could still see a justification for such a config option though, for systems that cannot easily be unplugged and have more strict I/O limits.
In any case, plugin developers should use the caching feature with caution and disable it for states where caching is not needed. There's probably room for optimization in quite some plugins though. You can enable the ThingManager debug category and it will print a message whenever it caches something. That's useful to find states that are cached but should not be.

@MennerM
Copy link
Author

MennerM commented Oct 19, 2022

Yes it is frequent disk I/O.

When I wrote the issue, I was very deeply involved with the SMA Smart Meter Plugin, which reads data in a high frequency. In the worst case, the file was written 12 times within one second. And we also already have a brocken device where the SD card is damaged.

You are right that here the plugin developer must be very careful.
I think for values that change every second it makes no sense to cache them.
We will check all energy plugins and the hint that we enable the debug category for the ThingManager is very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants