{"id":14108791,"url":"https://github.com/poolifier/poolifier","last_synced_at":"2025-04-10T04:52:56.492Z","repository":{"id":38380895,"uuid":"234525353","full_name":"poolifier/poolifier","owner":"poolifier","description":"Fast and small Node.js worker_threads and cluster worker pool","archived":false,"fork":false,"pushed_at":"2024-10-29T08:08:58.000Z","size":28872,"stargazers_count":364,"open_issues_count":17,"forks_count":13,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-29T09:24:59.062Z","etag":null,"topics":["computing","concurrency","cpu","eventloop","javascript","nodejs","parallelism","performance","scheduling","threadpool","typescript","worker-pool"],"latest_commit_sha":null,"homepage":"https://poolifier.github.io/poolifier/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poolifier.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"poolifier","github":"poolifier"}},"created_at":"2020-01-17T10:23:27.000Z","updated_at":"2024-10-29T08:07:33.000Z","dependencies_parsed_at":"2023-10-14T19:50:27.604Z","dependency_job_id":"1f160399-da00-4c61-b4e6-0dd3b2d75c8b","html_url":"https://github.com/poolifier/poolifier","commit_stats":{"total_commits":4910,"total_committers":15,"mean_commits":327.3333333333333,"dds":0.6733197556008146,"last_synced_commit":"8f8bebcae9c533f17fef20cd1ca2daa65616d1cf"},"previous_names":[],"tags_count":196,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poolifier%2Fpoolifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poolifier%2Fpoolifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poolifier%2Fpoolifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poolifier%2Fpoolifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poolifier","download_url":"https://codeload.github.com/poolifier/poolifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247417241,"owners_count":20935612,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computing","concurrency","cpu","eventloop","javascript","nodejs","parallelism","performance","scheduling","threadpool","typescript","worker-pool"],"created_at":"2024-08-14T10:01:47.190Z","updated_at":"2025-04-10T04:52:56.461Z","avatar_url":"https://github.com/poolifier.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"./images/logo.png\" width=\"340px\" height=\"266px\"/\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# Node.js Worker_Threads and Cluster Worker Pool\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![GitHub commit activity (master)](https://img.shields.io/github/commit-activity/m/poolifier/poolifier/master?color=brightgreen\u0026logo=github)](https://github.com/poolifier/poolifier/graphs/commit-activity)\n[![Npm Version](https://badgen.net/npm/v/poolifier?icon=npm)](https://www.npmjs.com/package/poolifier)\n[![JSR Version](https://jsr.io/badges/@poolifier/poolifier)](https://jsr.io/@poolifier/poolifier)\n[![CI Workflow](https://github.com/poolifier/poolifier/actions/workflows/ci.yml/badge.svg)](https://github.com/poolifier/poolifier/actions/workflows/ci.yml)\n[![Code Coverage](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n[![neostandard Javascript Code Style](\u003chttps://badgen.net/static/code style/neostandard/green\u003e)](https://github.com/neostandard/neostandard)\n[![Discord](https://badgen.net/discord/online-members/vXxZhyb3b6?icon=discord\u0026label=discord\u0026color=green)](https://discord.gg/vXxZhyb3b6)\n[![Open Collective](https://opencollective.com/poolifier/tiers/badge.svg)](https://opencollective.com/poolifier)\n[![PRs Welcome](https://badgen.net/static/PRs/welcome/green)](https://makeapullrequest.com)\n[![No Dependencies](\u003chttps://badgen.net/static/dependencies/no dependencies/green\u003e)](\u003chttps://badgen.net/static/dependencies/no dependencies/green\u003e)\n\n\u003c/div\u003e\n\n## Why Poolifier?\n\nPoolifier is used to perform CPU and/or I/O intensive tasks on Node.js servers, it implements worker pools using [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules.  \nWith poolifier you can improve your **performance** and resolve problems related to the event loop.  \nMoreover you can execute your tasks using an API designed to improve the **developer experience**.  \nPlease consult our [general guidelines](#general-guidelines).\n\n- Easy to use :white_check_mark:\n- Fixed and dynamic pool size :white_check_mark:\n- Easy switch from a pool type to another :white_check_mark:\n- Performance [benchmarks](./benchmarks/README.md) :white_check_mark:\n- No runtime dependencies :white_check_mark:\n- Proper integration with Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark:\n- Support for CommonJS, ESM and TypeScript :white_check_mark:\n- Support for [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules :white_check_mark:\n- Tasks distribution strategies :white_check_mark:\n- Lockless tasks queueing :white_check_mark:\n- Queued tasks rescheduling:\n  - Task stealing on idle :white_check_mark:\n  - Tasks stealing under back pressure :white_check_mark:\n  - Tasks redistribution on worker error :white_check_mark:\n- Support for sync and async task function :white_check_mark:\n- Support for multiple task functions with per task function queuing priority and tasks distribution strategy :white_check_mark:\n- Support for task functions [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations at runtime :white_check_mark:\n- General guidelines on pool choice :white_check_mark:\n- Error handling out of the box :white_check_mark:\n- Widely tested :white_check_mark:\n- Active community :white_check_mark:\n- Code quality [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=bugs)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n  [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n  [![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n  [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n  [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n  [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=sqale_index)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n- Code security [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=poolifier_poolifier) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=poolifier_poolifier\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=poolifier_poolifier)\n\n## Table of contents\n\n- [Overview](#overview)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Node.js versions](#nodejs-versions)\n- [API](#api)\n- [General guidelines](#general-guidelines)\n- [Worker choice strategies](#worker-choice-strategies)\n- [Contribute](#contribute)\n- [Team](#team)\n- [License](#license)\n\n## Overview\n\nPoolifier contains two [worker_threads](https://nodejs.org/api/worker_threads.html#class-worker)/[cluster](https://nodejs.org/api/cluster.html#cluster_class_worker) worker pool implementations, you don't have to deal with [worker_threads](https://nodejs.org/api/worker_threads.html)/[cluster](https://nodejs.org/api/cluster.html) complexity.  \nThe first implementation is a fixed worker pool, with a defined number of workers that are started at creation time and will be reused.  \nThe second implementation is a dynamic worker pool, with a number of worker started at creation time (these workers will be always active and reused) and other workers created when the load will increase (with an upper limit, these workers will be reused when active), the newly created workers will be stopped after a configurable period of inactivity.  \nYou have to implement your worker by extending the _ThreadWorker_ or _ClusterWorker_ class.\n\n## Installation\n\n### npmjs\n\n```shell\nnpm install poolifier --save\n```\n\n### JSR\n\n```shell\nnpx jsr add @poolifier/poolifier\n```\n\n## Usage\n\nYou can implement a poolifier [worker_threads](https://nodejs.org/api/worker_threads.html#class-worker) worker in a simple way by extending the class _ThreadWorker_:\n\n```js\nimport { ThreadWorker } from 'poolifier'\n\nfunction yourFunction(data) {\n  // this will be executed in the worker thread,\n  // the data will be received by using the execute method\n  return { ok: 1 }\n}\n\nexport default new ThreadWorker(yourFunction, {\n  maxInactiveTime: 60000,\n})\n```\n\nInstantiate your pool based on your needs :\n\n```js\nimport { DynamicThreadPool, FixedThreadPool, PoolEvents, availableParallelism } from 'poolifier'\n\n// a fixed worker_threads pool\nconst pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', {\n  onlineHandler: () =\u003e console.info('worker is online'),\n  errorHandler: e =\u003e console.error(e),\n})\n\npool.emitter?.on(PoolEvents.ready, () =\u003e console.info('Pool is ready'))\npool.emitter?.on(PoolEvents.busy, () =\u003e console.info('Pool is busy'))\n\n// or a dynamic worker_threads pool\nconst pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), './yourWorker.js', {\n  onlineHandler: () =\u003e console.info('worker is online'),\n  errorHandler: e =\u003e console.error(e),\n})\n\npool.emitter?.on(PoolEvents.full, () =\u003e console.info('Pool is full'))\npool.emitter?.on(PoolEvents.ready, () =\u003e console.info('Pool is ready'))\npool.emitter?.on(PoolEvents.busy, () =\u003e console.info('Pool is busy'))\n\n// the execute method signature is the same for both implementations,\n// so you can easily switch from one to another\ntry {\n  const res = await pool.execute()\n  console.info(res)\n} catch (err) {\n  console.error(err)\n}\n```\n\nYou can do the same with the classes _ClusterWorker_, _FixedClusterPool_ and _DynamicClusterPool_.\n\n**See [examples](./examples/) for more details**:\n\n- [Javascript](./examples/javascript/)\n- [Typescript](./examples/typescript/)\n  - [HTTP client pool](./examples/typescript/http-client-pool/)\n  - [SMTP client pool](./examples/typescript/smtp-client-pool/)\n  - [HTTP server pool](./examples/typescript/http-server-pool/)\n    - [Express worker_threads pool](./examples/typescript/http-server-pool/express-worker_threads/)\n    - [Express cluster pool](./examples/typescript/http-server-pool/express-cluster/)\n    - [Express hybrid pool](./examples/typescript/http-server-pool/express-hybrid/)\n    - [Fastify worker_threads pool](./examples/typescript/http-server-pool/fastify-worker_threads/)\n    - [Fastify cluster pool](./examples/typescript/http-server-pool/fastify-cluster/)\n    - [Fastify hybrid pool](./examples/typescript/http-server-pool/fastify-hybrid/)\n  - [WebSocket server pool](./examples/typescript/websocket-server-pool/)\n    - [ws worker_threads pool](./examples/typescript/websocket-server-pool/ws-worker_threads/)\n    - [ws cluster pool](./examples/typescript/websocket-server-pool/ws-cluster/)\n    - [ws hybrid pool](./examples/typescript/websocket-server-pool/ws-hybrid/)\n\nRemember that workers can only send and receive structured-cloneable data.\n\n## Node.js versions\n\nNode.js versions \u003e= 18.x.x are supported.\n\n## [API](./docs/api.md)\n\n## [General guidelines](./docs/general-guidelines.md)\n\n## [Worker choice strategies](./docs/worker-choice-strategies.md)\n\n## Contribute\n\nChoose your task [here](https://github.com/orgs/poolifier/projects/1), propose an idea, a fix, an improvement.\n\nSee [CONTRIBUTING](./CONTRIBUTING.md) guidelines.\n\n## Team\n\n**Creator/Owner:**\n\n- [**Alessandro Pio Ardizio**](https://github.com/pioardi)\n\n**Maintainers:**\n\n- [**Jérôme Benoit**](https://github.com/jerome-benoit)\n\n**Contributors:**\n\n- [**Shinigami92**](https://github.com/Shinigami92)\n\n## License\n\n[MIT](./LICENSE)\n","funding_links":["https://opencollective.com/poolifier","https://github.com/sponsors/poolifier"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoolifier%2Fpoolifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoolifier%2Fpoolifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoolifier%2Fpoolifier/lists"}