Persistent global variables

Hi,

I have a certain amount of global variable saved in the localfilesystem. I have seen that the variables are saved in .node-red/context/global/global.json, but there is something weird: not all the variables are in that file, and their state is not synchronized in real time. In other words, if a variable passes from state "true" to state "false", in that file it stays "true" for a while (about a minute), before changing state.

Is there some doc where I can study how this mechanism works?

Thanks

lots of info on the forum (search persistent context )

e.g...

If you want more control, there are contrib nodes that can read/write to JSON in a very similar fasion to persistent storage e.g...

2 Likes

Context stored to a file is only done every 30 seconds - see Working with context : Node-RED

There might be a setting in settings.us that can change the value. It was setup that way because of wear on SD cards

1 Like

@zenofmud thank you. On a Raspberry, do you suggest to extend it to 1 minute or so?

Note that it only writes if a value has changed. If you monitor /var/log/syslog you will see that writing the context out at that rate will not be an issue unless you have a large amount of data.

Hi Colin,

indeed, I was looking at the syslog this morning, but didn’t find any entry related to saving context. Just starting/stopping flows while deploying...

I didn't mean there was anything related to context, just that there is continual background chatter there, making saving context every 30 seconds irrelevant, unless you have a very lightly loaded pi, in which case you don't need to worry anyway.
I just did ls -al /var/log/ on my main pi, which is a pi3 (B?) to see how much there is and realise that pihole is logging about 25MB/day and has been doing that for years on the same card without issue. I think I might look how to turn that down a bit though, it is a bit excessive.

1 Like

Understand. You're right.
Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.