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

Move SHA1 hashing to another process/worker #235

Closed
feross opened this issue Jan 4, 2015 · 18 comments
Closed

Move SHA1 hashing to another process/worker #235

feross opened this issue Jan 4, 2015 · 18 comments

Comments

@feross
Copy link
Member

@feross feross commented Jan 4, 2015

Creating SHA1 hashes for large multi-gigabyte files can take up a lot of CPU time.

  • In the browser, we should investigate moving this work to a web worker with transferrable objects.
  • In node, we should investigate spawning worker processes to do hashing.
@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Jan 4, 2015

Transferrable objects worked well for Bitford:

You're always welcome to copy my code for groundwork. We're implementing file-sharing here anyway. :-)

@astro

This comment has been minimized.

Copy link
Contributor

@astro astro commented Jan 5, 2015

It is not clear to me how to integrate this into the browserify process. Maybe with workerify?

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Jan 5, 2015

Managed to make client.seed much faster by skipping the piece verification in storage.js. It's unnecessary since we're the first seeder of a new file.

Before:

createTorrent.parseInput: 0.598ms
index.js:206 createTorrent: 6654.848ms
index.js:211 add: 186.781ms
index.js:220 tasks (storage.load): 6906.296ms
index.js:224 seed: 13752.465ms

After:

createTorrent.parseInput: 0.626ms
index.js:209 createTorrent: 6656.904ms
index.js:214 add: 419.079ms
index.js:223 tasks (storage.load): 256.499ms
index.js:227 seed: 7337.118ms

Total time for 250MB file almost cut in half. 13s to 7s.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Jan 5, 2015

With this PR (michaelrhodes/simple-sha1#1) to simple-sha1, the time to prepare a 250MB file is only 2 seconds.

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Jan 5, 2015

Aaaand, using the web crypto API gets us down to <1 second to seed a 250MB file!

PR out: michaelrhodes/simple-sha1#3

We're now officially in the territory of C speeds. We probably can punt on web workers for a while. This is so much faster than it was before (13.7 seconds).

feross added a commit to webtorrent/parse-torrent-file that referenced this issue Jan 5, 2015
feross added a commit to webtorrent/create-torrent that referenced this issue Jan 5, 2015
@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Jan 5, 2015

Released 0.22.0 using simple-sha1 for MUCH faster perf in the browser.

feross referenced this issue in webtorrent/ut_metadata Jan 5, 2015
@Svenskunganka

This comment has been minimized.

Copy link

@Svenskunganka Svenskunganka commented Jan 5, 2015

@FerrOS This is amazing! Really needed! We should try to push the larger BitTorrent client developers to implement WebRTC as WebTorrent is revolutionary to BitTorrent!

@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented Jan 5, 2015

@Svenskunganka Yep, we need to apply pressure and/or send them pull requests that add WebRTC support. Do you know any client developers?

@Svenskunganka

This comment has been minimized.

Copy link

@Svenskunganka Svenskunganka commented Jan 5, 2015

@FerrOS Unfortunately not. As for µTorrent, it seems the only thing we can do there is to make a feature request on their forums...

@alberto-esposito

This comment has been minimized.

Copy link

@alberto-esposito alberto-esposito commented Jan 12, 2015

we could also try the other way around: create a desktop and mobile app with node.js/Meteor. Like Atom.io did. It's not very difficult.

Being desktop based, I could create a bridge between the standard torrent protocol and webtorrent, using Unix Pipes on linux.

@Svenskunganka

This comment has been minimized.

Copy link

@Svenskunganka Svenskunganka commented Jan 12, 2015

@servermeta that won't cut it in the long run as people are still going to use µTorrent, Transmission, Vuze and all the other large BitTorrent clients. The only way to get to the large audience is if those clients adds support for WebRTC. I imagine only seedbox users would be interested in using a bridge.

@alberto-esposito

This comment has been minimized.

Copy link

@alberto-esposito alberto-esposito commented Jan 12, 2015

the idea is to substitute them (exaggerated expectation). We could have the momentum, as webtorrent is firewall proof.

@MzHub

This comment has been minimized.

Copy link

@MzHub MzHub commented Jan 16, 2015

As for µTorrent, it seems the only thing we can do there is to make a feature request on their forums...

They seem to be quite active with the responses though, so I believe they are reading the requests. A while ago I was already writing a request there, but then I hesitated, since I don't know if that is on the agenda at this point. I thought it might be better to wait for the BEP and other such things that might persuade them, or help with integrating WebRTC (examples?) that are still pending. What do you think?

@Svenskunganka

This comment has been minimized.

Copy link

@Svenskunganka Svenskunganka commented Jan 17, 2015

@MzHub maybe we can open their eyes with Feross awesome presentation from JSConf Asia? https://www.youtube.com/watch?v=kxHRATfvnlw

It's very educational and really brings forth the weight and importance of WebRTC support!

This was referenced Jan 21, 2015
@cmawhorter

This comment has been minimized.

Copy link

@cmawhorter cmawhorter commented Mar 8, 2015

just passing through but npm webworker-threads might be of interest

@arestov

This comment has been minimized.

Copy link

@arestov arestov commented Mar 30, 2016

@josephfrazier

This comment has been minimized.

Copy link
Member

@josephfrazier josephfrazier commented Apr 23, 2016

It looks like threads.js (npm install threads) has most of what is needed here:

However, it doesn't provide the ability to use require in the browser, but that appears to be an upcoming feature. I wonder if webworkify could help out with that.

@feross feross added accepted and removed accepted labels May 3, 2018
@feross feross added accepted and removed accepted labels May 3, 2018
@feross

This comment has been minimized.

Copy link
Member Author

@feross feross commented May 4, 2018

Closing this. See: #1233 (comment) for reasoning.

@feross feross closed this May 4, 2018
@feross feross added stale and removed accepted labels May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants
You can’t perform that action at this time.