并行运行node.js的多个实例

时间:2021-07-02 21:34:13

I was thinking about using a reverse proxy to distribute API requests to multiple node.js instances of a REST API. Like this it should be possible to achieve much better overall performance since multiprocessor systems can perfectly run multiple instances on one core each (or similar).

我正在考虑使用反向代理将API请求分发给REST API的多个node.js实例。像这样,应该可以实现更好的整体性能,因为多处理器系统可以在每个(或类似)核心上完美地运行多个实例。

What are common solutions for such a distribution of requests onto multiple node instances and what are important points to take in mind?

在多个节点实例上分配请求的常见解决方案是什么?需要注意哪些重点?

1 个解决方案

#1


7  

First and foremost, you can use the cluster module for running many instances of the same server application. It's important to remember to correctly handle shared state, such as storing sessions in a common database.

首先,您可以使用群集模块运行同一服务器应用程序的许多实例。记住正确处理共享状态非常重要,例如在通用数据库中存储会话。

This works standalone and you can let your users connect directly to that server, or use e.g. nginx, HAProxy, Varnish or lighttpd in front of your server.

这可以独立使用,您可以让您的用户直接连接到该服务器,或者使用例如服务器前面的nginx,HAProxy,Varnish或lighttpd。

#1


7  

First and foremost, you can use the cluster module for running many instances of the same server application. It's important to remember to correctly handle shared state, such as storing sessions in a common database.

首先,您可以使用群集模块运行同一服务器应用程序的许多实例。记住正确处理共享状态非常重要,例如在通用数据库中存储会话。

This works standalone and you can let your users connect directly to that server, or use e.g. nginx, HAProxy, Varnish or lighttpd in front of your server.

这可以独立使用,您可以让您的用户直接连接到该服务器,或者使用例如服务器前面的nginx,HAProxy,Varnish或lighttpd。