Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features
The tinypool npm package is a minimalistic thread pool implementation for Node.js. It allows you to offload tasks to worker threads, which can improve the performance of CPU-intensive operations in a Node.js application by taking advantage of multi-threading.
Creating a thread pool
This feature allows you to create a thread pool with a specified number of worker threads. The 'task' option points to a JavaScript file that will be executed in the worker threads.
const { StaticPool } = require('tinypool');
const pool = new StaticPool({
size: 4,
task: './worker.js'
});
Running tasks in the pool
Once a thread pool is created, you can run tasks by passing data to the 'run' method. The method returns a promise that resolves with the result of the task executed in the worker thread.
pool.run({ some: 'data' }).then(result => {
console.log(result);
});
Destroying the pool
When you are done with the thread pool, you can call the 'destroy' method to terminate all the worker threads and free up resources.
pool.destroy();
Workerpool is an npm package that offers a pool of workers to offload tasks. It provides a similar functionality to tinypool but with additional features such as automatic load balancing and the ability to directly pass functions and parameters to the pool without needing separate worker files.
Piscina is a modern thread pool implementation for Node.js. It is similar to tinypool but offers a more extensive API, including support for transferable objects, task cancellation, and more advanced configuration options.
Threads is a package for working with Web Workers and Node.js worker threads. It provides an abstraction over the native worker threads API, making it easier to work with. It offers a different approach compared to tinypool by focusing on the abstraction layer rather than just providing a thread pool.
Piscina: A fast, efficient Node.js Worker Thread Pool implementation
Tinypool is a fork of piscina. What we try to achieve in this library, is to eliminate some dependencies and features that our target users don't need (currently, our main user will be Vitest). Tinypool's install size (38KB) can then be smaller than Piscina's install size (6MB). If you need features like utilization or NAPI, Piscina is a better choice for you. We think that Piscina is an amazing library, and we may try to upstream some of the dependencies optimization in this fork.
✅ Smaller install size, 38KB
✅ Minimal
✅ No dependencies
✅ Physical cores instead of Logical cores with physical-cpu-count
❌ No utilization
❌ No NAPI
Written in TypeScript, and ESM support only. For Node.js 14.x and higher.
Read full docs on GitHub.
FAQs
A minimal and tiny Node.js Worker Thread Pool implementation, a fork of piscina, but with fewer features
The npm package tinypool receives a total of 4,952,526 weekly downloads. As such, tinypool popularity was classified as popular.
We found that tinypool demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.