https://github.com/zedd45/multithreading-web-workers-example
Web Workers for Node JS, based on Digital Ocean Tutorial
https://github.com/zedd45/multithreading-web-workers-example
multithreading webworkers
Last synced: about 1 year ago
JSON representation
Web Workers for Node JS, based on Digital Ocean Tutorial
- Host: GitHub
- URL: https://github.com/zedd45/multithreading-web-workers-example
- Owner: zedd45
- License: mit
- Created: 2022-08-31T02:47:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-01T22:51:48.000Z (almost 4 years ago)
- Last Synced: 2025-02-03T09:43:00.886Z (over 1 year ago)
- Topics: multithreading, webworkers
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multithreading Example
This is an implementation of Digital Ocean's tutorial on [Multithreading using Webworkers in Node](https://www.digitalocean.com/community/tutorials/how-to-use-multithreading-in-node-js).
I followed the tutorial, but made some changes, including using obtaining the number of threads from the machine's info, rather than assuming 4.
The multi-core server runs on port 3001 to prevent confusion, but I wouldn't recommending running both servers at the same time, as it will tamper with the results if you make requests to both.
To get the time for a blocking request, run:
```shell
# single core
time curl --get http://localhost:3000/blocking
# multi-core
time curl --get http://localhost:3001/blocking
```
The difference in results on a 2019 MBP (8 core i9 with HyperThreading) were pretty impressive:
```shell
# Single Core
$ time curl --get http://localhost:3000/blocking
result is 20000000000
________________________________________________________
Executed in 20.57 secs fish external
usr time 4.83 millis 130.00 micros 4.70 millis
sys time 7.94 millis 900.00 micros 7.04 millis
# Multi-Core
$ time curl --get http://localhost:3001/blocking
result is 20000000000
________________________________________________________
Executed in 799.82 millis fish external
usr time 4.15 millis 107.00 micros 4.05 millis
sys time 7.00 millis 895.00 micros 6.11 millis
```