我需要在V8中有一千个分离物。 但是我遇到了内存奇怪的问题,当我有一些可用的RAM,但V8引发OOM错误消息。我可以创建多少个v8菌株?
例如,
在这种特殊情况下,你可以看到,我们还是有一定的RAM,当V8抛出这个错误。编号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);
本 - > _ create_params.constraints.set_max_executable_size(maxExecutableSizeMb);
v8::V8::InitializePlatform(this->_platform);
v8::V8::Initialize();
非常感谢!
恐怕我们无法猜测您的代码。也不是你的意图。 – Ven
成像我只是做自动隔离= V8 ::隔离::新(这 - > _ create_params);在一个循环中。即使我拥有20%的内存,它也会失败。为什么? –