我正在通过Chrome的一个选项卡在运行数千个Https客户端,但是浏览器似乎达到了限制,在我检查任务管理器时,该选项卡的Chrome进程使用了高达897MB的内存,因此我认为存在某种限制(900MB〜)。
有没有Chrome巫师能够解释这个问题?如果我能够增加最大限制,那么在单个选项卡中运行更多的客户端将会是理想的。
我正在通过Chrome的一个选项卡在运行数千个Https客户端,但是浏览器似乎达到了限制,在我检查任务管理器时,该选项卡的Chrome进程使用了高达897MB的内存,因此我认为存在某种限制(900MB〜)。
有没有Chrome巫师能够解释这个问题?如果我能够增加最大限制,那么在单个选项卡中运行更多的客户端将会是理想的。
缺省情况下,32位系统上v8的内存限制为512MB,在64位系统上为1.4GB。可以通过将--max_old_space_size
设置为32位系统上最大1024 (1 GB),64位系统上最大4096(4GB)来提高限制。您应该能够在Linux shell中启动Chrome时设置此参数,或者在Windows快捷路径作为参数。
--js-flags
选项:open /Applications/Google\ Chrome.app --args --js-flags="--max_old_space_size=8192"
。请注意,这是命令行操作系统的指令。 - Luc--args
是如何将标志从OSX的open
命令传递给正在打开的进程的方法:https://brettterpstra.com/2014/08/06/shell-tricks-the-os-x-open-command/#other-handiness - ericsocomax_old_space_size
现在默认为 0。我测试了一个默认的 node v12.20.0 安装,它在大约 2GB 处无法分配内存。顺便说一下,我只是指每个选项卡/v8进程的最大内存使用量,而不是 window.performance.memory
的所有选项卡的总使用量。 - Mihai Tomescuchrome.exe --js-flags="--max_old_space_size=1024"
。 - Holistic Developer结合Mihai Tomescu的回答和其他资源进行汇总:
在运行x64 Windows操作系统时,每个标签页的最大内存似乎约为1.8GB,根据此回答
通过将Chrome链接地址从"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
"更改为"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --max_old_space_size=4096
,可以成功增加标签页内存
可以使用这张巨大的图片快速测试差异。该图片将在默认内存设置下使Chrome崩溃(“Google Chrome已耗尽内存,无法显示此网页”),但在增加内存限制后可以正常渲染。
--profile-directory="Profile 7"
。您可以通过访问chrome://version
并查找配置文件路径来获取配置文件目录。代码如下:"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --max_old_space_size=4096 --profile-directory="Profile 7"
。 - Salman看起来 --max_old_space_size 不再起作用了。 我在 Ubuntu 22.04 (版本 106.0.5249.119) 上测试过,它什么也没做,而且我在 Google 支持论坛上找到了 this thread,说它在 Chrome 104 中被移除了。
在 Ubuntu 23.04 上,它仍然不起作用,但至少在我的笔记本电脑上限制似乎超过了 4Gio。
以下是如何自行检查:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Author" content="Laurent LYAUDET">
<meta name="Publisher" content="Laurent LYAUDET">
<meta name="Description"
content="Check if Chrome still limits tab memory">
<meta name="Keywords"
content="debug Chrome">
<title>All your memory are belong to us! XD</title>
</head>
<body>
<h1>Check if Chrome still limits tab memory</h1>
<p>
Step 1: Open Chrome with command line in incognito mode
to avoid messing with your profile (adapt this line to your OS):
<pre>
/usr/bin/google-chrome-stable --incognito --max_old_space_size=4096
</pre>
</p>
<p>
Step 2: Open Chrome Task Manager to check your memory (Menu > More Tools > Task manager)
</p>
<p>
Step 3: Look at how much RAM used it crashes.
</p>
<p>
Step 4: Repeat from step 1 with --max_old_space_size=1024.
Currently "Version 112.0.5615.165 (Build officiel) (64 bits)",
max_old_space_size seems to do nothing.
Webpage loads fine with both if fine_tune_me = 400000.
Webpage crashes with both if fine_tune_me = 1000000.
</p>
<script>
// let fine_tune_me = 400000; // This value should be ok if you have enough RAM.
let fine_tune_me = 1000000; // This value should crash.
document.addEventListener("DOMContentLoaded", function () {
for(let i = 0; i < fine_tune_me; ++i){
let myTextArea = document.createElement("textarea");
myTextArea.textContent = "All your memory are belong to us!";
document.body.appendChild(myTextArea);
}
});
</script>
</body>
</html>
I don't believe electron has a hard limit of 4gb. That may be its default, but I've been able to get to 16gb by doing the following in main.js:
const { app } = require('electron'); app.commandLine.appendSwitch('js-flags', '--max-old-space-size=16384');
Unfortunately no such switch exists for the Chrome browser.
参考:
jsHeapSizeLimit
。我能够使用此命令减少堆大小限制,但无法增加其大小。 - z80crew