Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Worker #78

Open
willemneal opened this issue Jun 11, 2018 · 13 comments
Open

Service Worker #78

willemneal opened this issue Jun 11, 2018 · 13 comments

Comments

@willemneal
Copy link

I'm interested in making OrbitDB work in a Web Service Worker. This way:

  1. It would be in a different thread than the UI.
  2. One instance serves multiple tabs.
  3. It could redirect HTTP traffic so that you can respond with content in the database.

When I tried it briefly, I found that localStorage is not defined in the scope of the a Service Worker. I tried a hack of defining it myself, but ran into other issues and haven't returned. Has anyone else looked into this?

I think the transition could be painless from an API perspective since most calls are asynchronous you could just make them RPC's to the Service Worker.

@AlbertoElias
Copy link

+1 to this. Apart from service worker, it's great to run IPFS in workers, and it'd be great to run OrbitDB in a worker as well

@aphelionz aphelionz reopened this Feb 27, 2019
@hazae41
Copy link

hazae41 commented Feb 27, 2019

For now, Service Workers are not like this.
They always stop and start, you can't rely on them for doing long tasks.

I recommend you to read the following (about ServiceWorkers lifecycle)
https://developers.google.com/web/fundamentals/primers/service-workers/

I already tried putting an IPFS node on a service worker, it was very difficult and the result was a slowwwwww IPFS node always restarting, and rarely available to respond to requests or listen for PubSub messages.

Because they're not made for such kind of tasks.

You should rather open a popup window that runs an IPFS/OrbitDB node and tell the user to keep it open.

@AlbertoElias
Copy link

the js-ipfs site has an enable service worker function, so they are definitely pushing it.

But apart from that, making IPFS and OrbitDB run on a Web Worker will be extremely helpful for performance. OrbitDB is the blocker on this, and just by moving from localStorage to IndexedDB on the keychain should be enough to support this. Service Worker is just one kind of Worker

@aphelionz
Copy link
Member

aphelionz commented Feb 27, 2019

OrbitDB in a separate thread in a web worker is very compelling. You;d have to use messages heavily for computation but its certainly possible!

@AlbertoElias
Copy link

Yup! And there are many use cases for batching DB calls

@willemneal
Copy link
Author

I'm currently working with AssemblyScript to use WebAssembly and atomic memories to have faster web worker communication.

I'lve also been working on OrbitFS, which uses a mutable filesystem from IPFS and then commits root hashes to orbitdb. So in that system you'd only need to use orbitdb with bigger updates.

@aphelionz
Copy link
Member

@willemneal do you want to show this at the next community call on March 5?

@willemneal
Copy link
Author

@aphelionz I would like to, but it's not quite ready for demoing. But perhaps the next one. When is it?

@aphelionz
Copy link
Member

They're every two weeks on Tuesday morning EST. Info is posted as issues in this repo. For example: orbitdb-archive/welcome#51

@willemneal
Copy link
Author

Okay thanks! I'll aim for the next one!

@Schwartz10
Copy link

Hey, I'm using orbitDB inside an iframe with some strict sandbox security requirements aragon/client#702

If we ran orbit in a service worker, do people think this would solve the above issue as well? If not, do people see any alternatives to getting orbit to work in an iframe besides loosening sandbox restrictions? Thanks for any help!

@AlbertoElias
Copy link

I'm running orbitDB in an iframe, but the storage is taken care of from the domain itself, not from the page that loads the iframe, so it stores it in the specific indexeddb instance for that domain.

Do you want all your aragon apps which are in different iframe to access the indexeddb storage of the domain that loads those iframes? Maybe you can set up some kind of post message communication for that, but using workers won't be an option as they're domain specific as well I believe

@aphelionz
Copy link
Member

Moving to the Field Manual so we can document Web Worker usage

@aphelionz aphelionz transferred this issue from orbitdb/orbitdb Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants