- Notifications
You must be signed in to change notification settings - Fork83
New demos for OPFS access handle#84
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
There are a couple new demos showing off a synthesis of two ideas that have their own discussion threads:
Combining these ideas makes possible an OPFS-backed database service that:
The new demos are really just copies of existing demos, except using a shared connection to AccessHandlePoolVFS for database queries:
Both of these demos use the same SharedService name, so you can open multiple browser tabs of both and they all will share a single database connection. That means, for example, that after running a contention test you can compose SQL to dig deeper into the results, say to see if the same tab ever gets consecutive transactions. Note that these demos are implemented with ES6 module Worker (because I'm too lazy to bundle them), which is enabled by default in Firefox nightly. You can run on Firefox beta and stable by enabling Early (and possibly premature) conclusions from these demos:
Shared AHP contention results on my 2014 Mac mini on various browsers for 1, 8, and 32 (!) browser tabs:
|
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
Replies: 2 comments 7 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I went down a rabbit hole trying to figure this out. First I wrote amicro-benchmark to time a bunch of OPFS writes and flushes to verify that was indeed where the difference was. Then I went on a long internet journey, and found that Chrome has a special flush implementation on Apple devices. Instead of calling if (!HANDLE_EINTR(fcntl(file_.get(),F_FULLFSYNC))) return true; What does F_FULLFSYNC do? Basically itdoes what
I haven't been able to confirm how Firefox and Safari do syncing, but I strongly suspect that they aren't using F_FULLFSYNC. That would obviously be a serious bug, right? Maybe not. At one time, the lack of using F_FULLFSYNC on Mac was actually filed as aFirefox bug, but it was eventually marked WONTFIX. One of the commenters on the bug is Dr. Richard Hipp, the author of SQLite:
So even Apple doesn't use F_FULLFSYNC and the SQLite folks don't recommend it (at least not back in 2008); it can be enabled in SQLite (on a native Apple build) with apragma, but the default is off. ThisSQLite forum message reports that interrupting SQLite connections not using F_FULLFSYNC could affect durability but did not find any database corruption with the specific devices and software versions tested. It appears that all the browsers are making an informed decision about the risks and rewards here and have arrived at different conclusions, and that's the reason why Chrome is dramatically slower on OPFS flush (and therefore on OPFS VFS write transactions) on macOS and iOS. Application developers considering an OPFS VFS should be aware that:
|
BetaWas this translation helpful?Give feedback.
All reactions
👍 7
-
Is the Chrome team aware of the problem? I wonder how much of an intentional choice it was on their part to use |
BetaWas this translation helpful?Give feedback.
All reactions
-
@tantaman I filed achromium issue, but there seem to be differing opinions on whether and what to do about it. They asked for input from the SQLite folks but there was no public response (maybe there was a private response). The last comment on the issue references more discussion in another chromium issue which used to be publicly visible but no longer is. IIRC that issue involved occasional corruption in a SQLite DB and they were looking at ways to detect and log that, which might also be useful in running an experiment to see if dropping F_FULLFSYNC made corruption any more likely. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Does this meanall OPFS file writes on chromium browser on Mac OS are affected, not just SQLite related? And they will be up to 10x slower? If this is not fixed then I wonder if OPFS will actually be usable in any write-heavy real world applications as Chrome users on Mac OS seem to be a pretty important demographic of users. I looked through the thread, it looks like the chromium devs last recommendation is to raise an issue with the standards body athttps://github.com/WICG/file-system-access/issues? EDIT: Just tried running the wa-sqlite benchmarks on my Mac in various browsers. Saw that for Test 1 AccessHandlePool is extremely fast on Firefox and Safari but extremely slow on Chrome. Even using locking_mode=EXCLUSIVE barely helps Another observation is AccessHandlePool in Firefox and Safari on Mac OS alot faster than on Firefox and Chrome on Windows. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The problem is not exactly with writes but with flushes. It does apply to all pages that use OPFS on macOS, but it especially affects applications that need to write atomically and durably, like databases, because they require more flushes.
You can write at high rates. You just can't flush at high rates. I don't think users will notice; it's developers who will run up against it and not write apps that do that. I believe it's unfortunate and unnecessary but I think I've done all I can do. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
First of all: I really appreciate your fantastic work on all of this! Looks like you've recently shipped v1.0 (congrats!) and as part of the preparations deleted the above-mentioned ahp demos as part of#174. Are there any plans to bring those back?@rhashimoto |
BetaWas this translation helpful?Give feedback.
All reactions
-
@schickling I don't have any plans to restore those demos. I was thinking that most applications that would previously have used AccessHandlePoolVFS would now instead use OPFSCoopSyncVFS, which issimilar but supports multiple connections. The SharedService implementations and simple demos showing the basic concept of sharing a Worker (without SQLite) are still around. Did you have a particular interest in one or both of those demos? |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Thanks a lot for that additional context. For now I'll use the deleted demo scripts as a reference to use SQLite from a SharedWorker. (🤞 that one day OPFS will be supported in a SharedWorker natively) |
BetaWas this translation helpful?Give feedback.
All reactions
-
@schickling Just so you're aware, there are some newer VFS options now that can address some of the motivations to share a dedicated Worker, in addition to OPFSCoopSyncVFS. You can actually use OPFS in a shared worker, just not the synchronous access handles that optimize performance.OPFSAnyContextVFS implements such a VFS without context restrictions. It may be suitable if slow write performance can be tolerated. IndexedDB is available in a shared worker, so IDBBatchAtomicVFS is always an option. IndexedDB has slower I/O than OPFS, but that is offset by not needing message passing to a Worker. And if performance is critical, the newIDBMirrorVFS is even faster than OPFS (with the limitation that your database fits in available memory). |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 2