高并发Nodejs参数调整

来源:互联网 发布:金淘淘软件 编辑:程序博客网 时间:2024/05/22 03:21

关闭v8 空时通知机制

--nouse-idle-notification

修改http.Agent

官网说明:agent.maxSocketsBy 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
原创粉丝点击