Ali Node.js platform performance

I installed version

  • node - v10.15.2
  • agenthub - v2.0.1
  • tnvm - v1.x
  • alinode-v4.7.1

1. Create an application

Go Node.js performance platform console node.console.aliyun.com/ create a new application to enter an application name demo, record the App ID and App Secret, back to see the settings from the application interface settings

2. deploy Node.js server platform performance

a. mounting platform performance required components Node.js

View node corresponding version alinode version

# 安装版本管理工具 tnvm,安装过程出错参考:https://github.com/aliyun-node/tnvm
wget -O- https://raw.githubusercontent.com/aliyun-node/tnvm/master/install.sh | bash
source ~/.bashrc
# tnvm ls-remote alinode 查看需要的版本
tnvm install alinode-v4.7.1 # 安装需要的版本 因为我node是v10.15.2 所以我选择了 4.7.1
tnvm use alinode-v4.7.1 # 使用需要的版本
npm install @alicloud/agenthub -g # 安装 agenthub
复制代码
  • Verify the installation, you need to ensure which node and which agenthub path included .tnvm can.
root@ww:~# which node
/root/.tnvm/versions/alinode/v3.11.4/bin/node
root@ww:~# which agenthub 
/root/.tnvm/versions/alinode/v3.11.4/bin/agenthub
复制代码
  • We will create a new application obtained App ID and App Secret saved as config.json as follows.
{
  "appid": "12345",                          # 前面申请到的 appid,保存时删掉这条注释。
  "secret": "kflajglkajlgjalsgjlajdgfakjkgj" # 前面申请到的 secret,保存时删掉这条注释。
}

{
  "appid": "12345",                          # 前面申请到的 appid,保存时删掉这条注释。
  "secret": "kflajglkajlgjalsgjlajdgfakjkgj" # 前面申请到的 secret,保存时删掉这条注释。
  "logdir": "/tmp",
  "error_log": [
    "/agenthub/log/error"
  ],
  "packages": [
    "/ww/prod/server/package.json"
  ],
  "disks": [
    "/ww/prod/server"
  ]
}
复制代码
  • After the error_log configuration is complete, you can see the error log information after the regular performance on Node.js platform;
  • After the packages configuration is complete, you can see the version of the project dependencies, and the corresponding security risk warning;
  • disks need to monitor disk configuration, monitoring data can be monitored to see in the system;

b. Start agenthub

agenthub start yourconfig.json
# 通过 agenthub list 查看 agenthub 是否启动成功
# 通过 agenthub stop xxx 可以删除
# 如果没有 agenthub 实例,通过调试模式启动 agenthub:
# DEBUG=* agenthub start yourconfig.json
# ~/.agenthub.log 查看 agenthub 日志。
复制代码

c. Start the application

# 直接启动应用
ENABLE_NODE_LOG=YES node server.js
# 使用pm2管理的应用
ENABLE_NODE_LOG=YES pm2 start server.js
复制代码

note:

If the message appears Environment variable <NODE_LOG_DIR> not configured, </ tmp /> will be used to record node internal log. Show running log (non-application log) is stored in the default directory / tmp /.

III. By observing console monitoring data, perform diagnostic operations observe the various monitoring process data Node.js information see the process level data in the console

According to the above configuration can be done to Ali node platform to see whether the following options are ticked

If the version number is alinode process can be viewed at ✘

  • Verify the installation, you need to ensure which node and which agenthub path included .tnvm can.
root@ww:~# which node
/root/.tnvm/versions/alinode/v3.11.4/bin/node
root@ww:~# which agenthub 
/root/.tnvm/versions/alinode/v3.11.4/bin/agenthub
复制代码

If an error which node needs to execute the following command

tnvm use alinode-v4.7.1 # 使用需要的版本
再关闭 pm2 delete aaa
再打开 ENABLE_NODE_LOG=YES pm2 start server.js --name=aaa
一般就行了
复制代码

Everything is ready, ready to start debugging,

像我用这玩意的目的是因为我服务器的cpu会概率性爆掉,一直找不到原因

So I need to look up the cpu profile

Then the following

  • He will have three minutes to generate in the process, he will detect cpu period
  • In three minutes and quickly click on the app to trigger full cpu
  • Then analyze it, he'll tell you which line is which caused js

Figure flame, cpuprofile documents, find their own right.

Reproduced in: https: //juejin.im/post/5cef395fe51d45109725fe06

Guess you like

Origin blog.csdn.net/weixin_33757911/article/details/91421246