Skip to content

Demonstrative of the power of worker_threads in Node.js with three algorithms: using worker threads pool, a raw implementation, and a imperative code. Detailed benchmarks compare performance.

Notifications You must be signed in to change notification settings

italoservio/nodejs_worker_threads

Repository files navigation

NodeJS Worker Threads

The "nodejs_worker_threads" repository showcases three distinct algorithms implemented in Node.js, each highlighting different approaches to leveraging the "worker_threads" module for efficient concurrent processing. The repository provides a comprehensive benchmark analysis of these algorithms and includes a README.md file with detailed results.


🟢 Status: Concluded


😍 How to use

npm i
npm run start:thread
npm run start:thread_pool
npm run start:imperative

📈 Benchmark result

- Intel Core i5 11400F 2.6~4.40GHz (6 Cores / 12 Threads)
- 32GB DDR4 3200MHz

Using thread without thread pool and forcing 5 workers

# npm run start:thread

> node index_thread.js

Total programs: 900005
Worker 1, verified 180001 items and found 1 matches
Worker 2, verified 180001 items and found 0 matches
Worker 3, verified 180001 items and found 0 matches
Worker 4, verified 180001 items and found 0 matches
Worker 5, verified 180001 items and found 1 matches
[
  { title: 'Folks!', releaseYear: '1992' },
  { title: 'Folks', releaseYear: '1992' }
]
Elapsed: 5.867s

Using thread with thread pool and using the number of available threads

# npm run start:thread_pool

> node index_thread_pool.js

Total programs: 900005
Worker 1, verified 75001 items and found 1 matches
Worker 2, verified 75001 items and found 0 matches
Worker 3, verified 75001 items and found 0 matches
Worker 6, verified 75001 items and found 0 matches
Worker 4, verified 75001 items and found 0 matches
Worker 5, verified 75001 items and found 0 matches
Worker 10, verified 75001 items and found 0 matches
Worker 12, verified 74994 items and found 1 matches
Worker 8, verified 75001 items and found 0 matches
Worker 9, verified 75001 items and found 0 matches
Worker 7, verified 75001 items and found 0 matches
Worker 11, verified 75001 items and found 0 matches
[
  { title: 'Folks!', releaseYear: '1992' },
  { title: 'Folks', releaseYear: '1992' }
]
Elapsed: 6.354s

Without threads in a normal imperative code

# npm run start:imperative

> node index_imperative.js

Total programs: 900005
Verified 900005 items and found 2 matches
[
  { title: 'Folks!', releaseYear: '1992' },
  { title: 'Folks', releaseYear: '1992' }
]
Elapsed: 22.135s

🎨 Contributor(s)

Profile
Ítalo Sérvio

About

Demonstrative of the power of worker_threads in Node.js with three algorithms: using worker threads pool, a raw implementation, and a imperative code. Detailed benchmarks compare performance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published