Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@


### Errors
- Need to fill Array object before passing, else recieve something like - `<2 empty items>` in console.
- Need to fill Array object before passing, else receive something like - `<2 empty items>` in console.
- Fixed relative path issues while exporting, use `__dirname` or other special variables like `__filename`
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- And the number of worker threads spawned is equal to the number of cores, to maximise output. If more spawned need to switch between threads, which takes time, if more spawned, cores underutilized.

## Worker Threads
- Javascript can handle I/O events easily, owing to EventLoop. Hence, Node can handle multiple HTTP requests pretty seamlessly.
- JavaScript can handle I/O events easily, owing to EventLoop. Hence, Node can handle multiple HTTP requests pretty seamlessly.
- But, if Node needs to do heavy computation, it cannot rely on EventLoop, since it runs on single-thread, and all the cores aren't optimally utilized. Here is when, `worker-thread` comes in.
- From the Worker-Thread Docs-
`Workers (threads) are useful for performing CPU-intensive JavaScript operations. They will not help much with I/O-intensive work. Node.js’s built-in asynchronous I/O operations are more efficient than Workers can be.`
Expand All @@ -18,9 +18,9 @@

## Data Structure
- For initialising a worker, passing data in workerData actually clones the data
- Whereas, for passing messages, using `worker.postMessage()`, data is passed either by cloning, transfering or sharing
- Whereas, for passing messages, using `worker.postMessage()`, data is passed either by cloning, transferring or sharing
- Cloning : `Arrays` are serialised then cloned, and desearialised. Since, the raw data segregation isn't know.
- Transfering : `ArrayBuffer` operate on this, since, they use `TypedArrays` such as `Uint8Array` as layer, owing to which, their raw segment sizes are known, and can be transfered easily.
- Transfering : `ArrayBuffer` operate on this, since, they use `TypedArrays` such as `Uint8Array` as layer, owing to which, their raw segment sizes are known, and can be transferred easily.
- Sharing : `SharedArrayBuffer` is similar to ArrayBuffer, where you need to wrap it using `TypedArrays`, but they can be shared. To maintain concurrency, `Atomics` library is used alongwith it, to perform concurrent opertations

### Links
Expand Down