realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.61k stars 558 forks source link

Multi-threaded support for Electron / NodeJS #6584

Open bimusiek opened 3 weeks ago

bimusiek commented 3 weeks ago

Problem

Hey, we are looking into offloading some of the workloads of our app to separate thread in NodeJS (Electron specifically). I remember there was some example with sync: true config, that utilised separate BrowserWindow, but I cannot remember where it was located.

Electron supports WebWorkers, however it is discouraged to import NativeModules inside the worker due to lack of support from libraries. Do you know if Realm supports multi-threading for NodeJS Workers though? https://www.electronjs.org/docs/latest/tutorial/multithreading#native-nodejs-modules

I found this issue, so it looks like workers are not yet supported? Maybe you have workaround for Electron case though? Like spawning 2 browser windows, which would theoretically have 2 separate event loops?

Can it be done? And can both threads use the same Sync configuration and can both write to the Realm? Or one has to be read-only? Or maybe it is not possible at all?

Solution

No response

Alternatives

No response

How important is this improvement for you?

Would be a major improvement

Feature would mainly be used with

Atlas Device Sync

sync-by-unito[bot] commented 3 weeks ago

➤ PM Bot commented:

Jira ticket: RJS-2787

kneth commented 3 weeks ago

@bimusiek It is correct that we don't support web workers or nodejs workers.

We are working on multi-process support for Atlas Device Sync; unfortunately it is too early to give you a release date. The sync: true is currently the best option.

The async transactions as discussed in #1099 might be a future feature to add. Some Atlas Device SDKs have implemented async transactions (for example Realm Swift). I wonder if async transactions will meet your requirements better.

elle-j commented 2 weeks ago

@bimusiek, our current Electron example uses one BrowserWindow.

P.S. that example does not use sync: true (which btw is now moved to an internal config prop openSyncedRealmLocally: true), but opens the Realm as usual.