node-persist
node-persist copied to clipboard
node-persist in cluster mode
Hi, I run nodejs on ubuntu with pm2 (in cluster mode); When I persist data (probably on one cluster). I can't access it (probably trying to access it from the other cluster) I know node-persist don't write the data instantly in disk. But I wait 10s, 30s, 1mn+ and i can't read the data. But if I reload both cluster, every data are accessible.
So my guess is that when node start, node-persist write in RAM all the files in .node-persist/storage/ which explain why it works when I restart.
Is this the intended behaviour when running node-persist in cluster mode ? if so, is there option/work around for this ?
thank you for your help :)
Pattern of node-persist is RAM+FileIO, which not designed for the "concurrent" requirement. So, an standalone writter service for appilcations which in PM2 mode is highly recommended.
P.S. similar solution is also work for node-sqlite3 ....
thanks for your answer. What do you means by "standalone writter" ?
@microSoftware For mine scenario (Some small tools that run in PM2 that have many read actions which I don't want to introduce redis or mysql or mongodb etc), I found no better solution to solve the concurrent conflicts than make a small js-program that listen to a socket to wait for the write command, exec it and return the result. that turns it into a socket-writer-micro-service.... It amazingly works for me... hope my answer satify you, let me know if not ;)
@wanjochan Thank you for the complete answer. It's crystal clear now 👍