鸬鹚洲 发表于 2017-2-22 08:43:27

nodejs生产环境配置及优化

1.清除多余包
npm prune --production
2.使用代码优化
a.grunt-contrib-uglify,精简代码
b.去掉所有console.*
c.使用grunt-contrib-jshint检测代码
3.尽可能使用strict mode
文件中使用'use strict'或者命令node --use_strict
4.内存优化、垃圾回收 v8-options
64位V8是1.5G内存上限,32位0.7G,通过下面参数可以修改
--max_new_space_size (max size of the new generation (in kBytes))
      type: intdefault: 0
--max_old_space_size (max size of the old generation (in Mbytes))
      type: intdefault: 0
--max_executable_size (max size of executable memory (in Mbytes))
      type: intdefault: 0
--gc_global (always perform global GCs)
      type: booldefault: false
--gc_interval (garbage collect after <n> allocations)
      type: intdefault: -1
node --use_strict --max_old_space_size=2000 --max_executable_size=2000 --gc_global --gc_interval=200 app.js
页: [1]
查看完整版本: nodejs生产环境配置及优化