高并发Nodejs参数调整

关闭v8 空时通知机制

--nouse-idle-notification

修改http.Agent

官网说明:
agent.maxSockets
By default set to 5. Determines how many concurrent sockets the agent can have open per host.
(为了http请求能复用connection连接,Nodejshttp.Agent创建了一个默认大小为5的连接池)
修改后如下:
require("http").globalAgent.maxSockets = Infinity;

修改–max-old-space-size

--max-old-space-size=2048(根据自己情况,可以调大,单位是M
说明:v8 64位操作系统默认使用的max-old-space-size1.7G,大家可以通过:node --v8-options 查看V8参数

使用PM2管理

例如:
{
"apps" : [
    {
        "name": "comet-server-4000",
        "script": "server.js",
        "port": 4000,
        "args": "['-p4000','-t','plan']",
        "run-as-group" : "comet",
        "exec_mode": "cluster_mode",
        "node-args": "--nouse-idle-notification --gc_global --max-old-space-size=2048 --max-new-space-size=1024"
    },
    {
        "name": "comet-server-4001",
        "script": "server.js",
        "port": 4001,
        "run-as-group": "comet",
        "args": "['-p4001','-t','plan']",
        "exec_mode": "cluster_mode",
        "node-args": "--nouse-idle-notification --gc_global --max-old-space-size=2048 --max-new-space-size=10240"
    }
]
}

避免在socket.io实时推送项目中使用同步代码,推送项目应该是以中间件的身份出现的,只传输数据

高并发系统参数调整

以Linux为例子 调整文件句柄数

  1. 查看liunx 最大文件句柄数 cat /proc/sys/fs/file-max
  2. 查看进程使用的文件句柄数 ls /proc/pid/fd | wc -l
  3. 查看进程句柄数限制 cat /proc/pid/limits | grep “files”
  4. 修改/etc/sysctl.conf 添加 fs.file-max=1000000
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值