remotestorage / remotestorage.js

⬡ JavaScript client library for integrating remoteStorage in apps
https://remotestoragejs.readthedocs.io
MIT License
2.31k stars 141 forks source link

Sync latency #863

Closed lewisl9029 closed 9 years ago

lewisl9029 commented 9 years ago

I was trying out the example project at https://myfavoritedrinks.5apps.com with a 5apps.com remotestorage account.

I did a few quick unscientific tests of adding and removing drinks on one browser and counting how long it would take for changes to be reflected in another browser logged into the same account.

This resulted in some wildly inconsistent results, ranging from almost immediate to upwards of 10 seconds of delay, the higher end of which seemed a bit high to me. (My internet is fairly decent at 25/10 mbps up/down, and my ping to 5apps.com was a fairly consistent 150 ms without any packet loss.)

If these results are representative of what most people are seeing with respect to remotestorage sync performance, I feel it might be worthwhile to try to optimize this aspect of remotestorage if at all possible. I know this is easier said than done, and I'd like to help but I'm not familiar enough with the codebase yet to know where to start looking.

Lower latency would offer client apps a better user experience, reduce frequency of conflicts, and possibly even open up some novel use cases such as using remotestorage as a kind of a central message queue for serverless apps.

raucao commented 9 years ago

This is by design, and the latency is just from receiving updates, not from publishing them to the storage.

Publishing is immediate, if you're online, or will happen later, when you're offline, of course.

Retrieving updates cannot be real-time with HTTP which is what the remoteStorage protocol is based on. There is a 10-second default sync interval in this library, which can be changed by the developer, both in general and on the fly, and which also changes e.g. to 60 seconds, when the app is not in the foreground. That means it takes anywhere between 1 and 10 seconds for the other clients to check for updates, after they're published to the storage from an app.

In real life this is not an issue, as 10 seconds is a very short amount of time, and 10 seconds turned out to be a reasonable default in actual usage so far. But as I said, if it's not reasonable for any given app, the developer can change the sync interval (both for foreground and background) anytime by using these functions: https://remotestorage.io/doc/code/files/sync-js.html#RemoteStorage.Sync.setSyncInterval

I just noticed that the functions are not visible in the docs for the remoteStorage class. I added an issue for fixing the documentation: #864

Hope this helps.

lewisl9029 commented 9 years ago

Thanks! That clears things up. =)