我是靠谱客的博主 粗暴钢笔,最近开发中收集的这篇文章主要介绍高并发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

最后

以上就是粗暴钢笔为你收集整理的高并发Nodejs参数调整的全部内容,希望文章能够帮你解决高并发Nodejs参数调整所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部