将 Node.js 应用程序扩展到 10 到 1000 个同时连接 [英] Scaling a Node.js application to 10s of 1000s of simultaneous connections

查看:61
本文介绍了将 Node.js 应用程序扩展到 10 到 1000 个同时连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在一款应用上做了一些工作,让人们可以通过互联网发射棒球.

We did some work on an app that lets people fire baseballs over the internet.

它完全存在于亚马逊的 AWS 生态系统中,我们正在为一个新项目构建它.堆栈包括:

It lives entirely within Amazon's AWS ecosystem, and we're building off that for a new project. The stack includes:

-专用的 MongoDB 和 Redis 服务器- 三组不同的 nodejs 服务器- 此外,我们正在使用 Amazon 的 API 进行服务器配置和自动缩放

-Dedicated MongoDB and Redis servers -three different groups of nodejs servers -additionally, we're making use of Amazon's API for server configuration and autoscaling

我们面临的问题是我们无法模拟每个实例超过 15000 个并发用户(websocket 连接).我们应该得到更多;我们认为成千上万.服务器CPU使用率只有40%.

The issue we're facing is that we haven't been able to simulate more than about 15000 concurrent users (websocket connections) per instance. We should be getting considerably more; we think 10s of thousands. The server CPU usage is only at 40%.

关于如何扩展 node.js 应用程序以使其能够同时连接到单个服务器的任何想法?

Any thoughts on how to scale a node.js app to enable it to have many more simultaneous connections to a single server?

推荐答案

每个 tcp 连接都有一个在文件操作系统中打开的文件描述符.将限制设置为高于您需要的数字非常重要.

Every tcp connection has a file descriptor open in file operating system. It is important to set the limit to a number above what you need.

例如在 ubuntu 中你可以通过命令看到这个限制:

For example, in ubuntu you can see this limit by commands:

$ulimit -a
$ulimit -n

要在 Ubuntu 中永久设置此限制,您需要更改文件/etc/security/limits.conf 并在这些行中添加您想要的数字:

To set this limit permanently in Ubuntu, you need to change the file /etc/security/limits.conf and add these lines with the number you want:

* soft nofile 100000
* hard nofile 100000

然后重启:

$sudo reboot

这篇关于将 Node.js 应用程序扩展到 10 到 1000 个同时连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆