Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
poolifier
Advanced tools
Library on top of node js worker threads that implement various worker pools type
npm install @pioardi/node-thread-pool --save
You can implement a worker in a simple way , extending the class ThreadWorker :
'use strict'
const { ThreadWorker } = require('@pioardi/node-thread-pool')
function yourFunction (data) {
// this will be executed in the worker thread,
// the data will be received by using the execute method
return { ok: 1 }
}
class MyWorker extends ThreadWorker {
constructor () {
super(yourFunction, { maxInactiveTime: 1000 * 60})
}
}
module.exports = new MyWorker()
Instantiate your pool based on your needed :
'use strict'
const { FixedThreadPool, DynamicThreadPool } = require('@pioardi/node-thread-pool')
// a fixed thread pool
const pool = new FixedThreadPool(15,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
// or a dynamic thread pool
const pool = new DynamicThreadPool(10, 100,
'./yourWorker.js',
{ errorHandler: (e) => console.error(e), onlineHandler: () => console.log('worker is online') })
pool.emitter.on('FullPool', () => console.log('Pool is full'))
// the execute method signature is the same for both implementations,
// so you can easy switch from one to another
pool.execute({}).then(res => {
console.log(res)
}).catch ....
See examples folder for more details ( in particular if you want to use a pool for multiple functions ).
You can use node versions 12.x , 13.x
pool = new FixedThreadPool(numThreads, filePath, opts)
numThreads
(mandatory) Num of threads for this worker pool
filePath
(mandatory) Path to a file with a worker implementation
opts
(optional) An object with these properties :
errorHandler
- A function that will listen for error event on each worker threadonlineHandler
- A function that will listen for online event on each worker threadexitHandler
- A function that will listen for exit event on each worker threadmaxTasks
- This is just to avoid not useful warnings message, is used to set maxListeners on event emitters ( workers are event emitters)pool = new DynamicThreadPool(min, max, filePath, opts)
min
(mandatory) Same as FixedThreadPool numThreads , this number of threads will be always active
max
(mandatory) Max number of workers that this pool can contain, the new created threads will die after a threshold ( default is 1 minute , you can override it in your worker implementation).
filePath
(mandatory) Same as FixedThreadPool
opts
(optional) Same as FixedThreadPool
pool.execute(data)
Execute method is available on both pool implementations ( return type : Promise):
data
(mandatory) An object that you want to pass to your worker implementation
pool.destroy()
Destroy method is available on both pool implementations.
This method will call the terminate method on each worker.
class YourWorker extends ThreadWorker
fn
(mandatory) The function that you want to execute on the worker thread
opts
(optional) An object with these properties :
maxInactiveTime
- Max time to wait tasks to work on ( in ms) , after this period the new worker threads will die.See guidelines CONTRIBUTING
FAQs
Fast and small Node.js Worker_Threads and Cluster Worker Pool
The npm package poolifier receives a total of 21,781 weekly downloads. As such, poolifier popularity was classified as popular.
We found that poolifier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.