gpt4 book ai didi

c++ - 我可以创建多少个 v8 isolate?

转载 作者:太空宇宙 更新时间:2023-11-04 13:08:43 26 4
gpt4 key购买 nike

我需要在 V8 中有数千个隔离物。但是当我有一些空闲 RAM 时,我遇到了奇怪的内存问题,但是 v8 抛出了 OOM 错误消息。

例如,

enter image description here

在这种特殊情况下,您可以看到当 V8 抛出此错误时我们仍然有一些 RAM。编号 2047 - 迭代器编号。所以基本上代码看起来像:

for(int i = 0; i < 3000; i++) {
std::cout << i << std::endl;
new Isolate(params);
}

也许我需要增加堆栈大小限制。我已经将它设置为 16Mb。而且还是有这个问题。htop 仅显示该进程的 4 个线程。所以我不认为线程有问题。

我做的 v8 类内部

  this->_maxRAMAvailable = 8; // 8Gb in my case
int maxOldSpaceMb = this->_maxRAMAvailable * 1024;
int maxSemiSpaceMb = 512;
int maxExecutableSizeMb = 512;

v8::V8::InitializeICUDefaultLocation(argv[0]);
v8::V8::InitializeExternalStartupData(argv[0]);
this->_platform = v8::platform::CreateDefaultPlatform();
this->_create_params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();

const uint64_t physical_memory = this->_maxRAMAvailable * 1024 * 1024 * 1024;
const uint64_t virtual_memory_limit = 0;
this->_create_params.constraints.ConfigureDefaults(physical_memory, virtual_memory_limit);

this->_create_params.constraints.set_max_old_space_size(maxOldSpaceMb);
this->_create_params.constraints.set_max_semi_space_size(maxSemiSpaceMb);

this->_create_params.constraints.set_max_executable_size(maxExecutableSizeMb);

  v8::V8::InitializePlatform(this->_platform);
v8::V8::Initialize();

非常感谢!

最佳答案

这里的信息有限,但让我们记住每个 Isolate 都需要自己的线程,(大概还有另一个线程用于 GC?)

所以 1723 Isolates 将意味着 ~3400 个线程...

每个线程将需要(正常默认值)1MB 的堆栈。

所以那里分配了 3.4GB 的内存。

关于c++ - 我可以创建多少个 v8 isolate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40936084/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com