The RPC Worker Pool is a robust, multi-threaded Remote Procedure Call (RPC) server implemented in Node.js and TypeScript. It is designed to handle a high volume of tasks concurrently, leveraging the power of multi-core processors to improve performance for CPU-intensive or I/O-bound tasks. The project uses the JSON-RPC 2.0 protocol for communication between the main thread and worker threads, allowing for lightweight and easy-to-use remote procedure calls.
The RpcWorkerPool class, defined in RpcWorkerPool.ts
, manages a pool of worker threads. It provides methods to add tasks to the pool, execute them, and terminate the pool. This class is the core of the project, coordinating the execution of tasks and the management of worker threads.
The Worker class, defined in worker.ts
, is responsible for executing tasks in separate threads. Each worker runs on a separate CPU core, allowing the project to take full advantage of multi-core processors.
The project uses the JSON-RPC 2.0 protocol for communication between the main thread and worker threads. TypeScript type definitions for the JSON-RPC 2.0 specification are provided in the json-rpc-2.0
spec folder.
The RPC-serialise.ts
file provides functions for serializing and deserializing JSON-RPC messages. This is a crucial part of the system, enabling the conversion of complex data structures into a format that can be easily transmitted over a network or between threads.
The RPC-errors.ts
file defines classes for JSON-RPC errors. Each class corresponds to a specific error code in the JSON-RPC 2.0 specification. This robust error handling mechanism is essential for building reliable and resilient systems.
The commands.ts
file exports a map of command names to their corresponding functions. This design allows a worker to execute a task by simply providing the name of the command.
To get started with the RPC Worker Pool, clone the repository and install the dependencies:
git clone https://github.com/Luxcium/rpc-worker-pool.git
cd rpc-worker-pool
npm install
Then, you can run the project:
npm start
The project is written in TypeScript and uses several libraries, including:
- "chalk" for terminal string styling
- "node-fetch" for making HTTP requests
- "ws" for WebSocket communication
Contributions to the RPC Worker Pool are welcome. Please submit a pull request or open an issue to discuss your proposed changes.
The RPC Worker Pool is licensed under the MIT License.