max_old_space_size设置为4gb,实际上限制为2GB

时间:2016-07-26 10:27:56

标签: node.js memory-limit

我在Gentoo Linux 64位下编写NodeJS 6.3.1应用程序。 在这台机器上,我通常拥有9GB的16GB可用内存和49GB的交换空间。

我使用以下代码来测试node.js应用程序的内存限制:

override func viewDidLoad() {
    super.viewDidLoad()
    self.setBottomBorder(self.textFieldEmailAddress, width: 0.4)
    self.setBottomBorder(self.textFieldPassword, width: 0.4)
    self.setBottomBorder(self.passwordBtn, width: 0.4)
}

func setBottomBorder(view: UIView, width: CGFloat) {

    let border = CALayer()
    border.name = "BottomBorder"
    border.borderColor = UIColor.blueColor().CGColor
    border.frame = CGRect(x: 0, y: view.frame.size.height - width,
        width: view.frame.size.width, height: width)
    border.borderWidth = width
    view.borderStyle = UITextBorderStyle.None
    view.layer.addSublayer(border)
    view.layer.masksToBounds = true
}

func removeBottomBorder(view: UIView) {
    if let sublayers = view.layer.sublayers {
        for layer: CALayer in sublayers  {
            if layer.name == "BottomBorder" {
                layer.removeFromSuperlayer()
                break
            }
        }
    }
}

func textFieldDidBeginEditing(textField: UITextField) {
    self.removeBottomBorder(textField)
    self.setBottomBorder(textField, width: 0.8)
    if (textFieldPassword == textField) {
        self.setBottomBorder(self.passwordBtn, width: 0.8)
    }
}

func textFieldDidEndEditing(textField: UITextField) {
    self.removeBottomBorder(textField)
    self.setBottomBorder(textField, width: 0.4)
    if (textFieldPassword == textField) {
        self.removeBottomBorder(self.passwordBtn)
        self.setBottomBorder(self.passwordBtn, width: 0.4)
    }
}

func textFieldShouldReturn(textField: UITextField) -> Bool {
    textField.resignFirstResponder()
    return true   
}

运行此脚本时没有额外的参数到节点,最后一个memoryUsage行是这样的:

var arr = []; 
var c=0;
while(arr.push('foo')) {if (++c%100000 == 0) {console.info(process.memoryUsage());}}

现在运行带有{ rss: 1032232960, heapTotal: 1015185408, heapUsed: 1008680024 } 的node.js,最后一个memoryUsage行是:

--max_old_space_size=4096

现在有8000限制:

{ rss: 2202341376, heapTotal: 2189082624, heapUsed: 2177311480 }

我错过了什么?如何将堆增加到4或8GB?

1 个答案:

答案 0 :(得分:1)

我认为这是V8的限制。它在64位计算机上不使用超过1.7 GB的RAM。引用常见问题解答:

  

目前,默认情况下,v8在32位上的内存限制为512mb   系统,以及64位系统上的1GB。可以通过设置来提高限制   --max-old-space-size最大为~1gb(32位)和~1.7gb(64位),但建议您拆分单个进程   如果你达到记忆限制,你可以分成几个工人。

相关问题