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

标签 c++ v8 embedded-v8

我需要在 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/

相关文章:

c++ - 在 linux 的另一个线程中检测程序启动

javascript - 近期 Chrome/V8 版本中的对象描述符 getter/setter 性能

javascript - 如何使用 V8 引擎从 C++ 获取 javascript 字节码

c++ - 参数返回值的 V8 内存管理

x86 上的 Android NDK 和 STL 相关引用错误

javascript - 访问V8引擎的抽象语法树

c++ - last_insert_id 的返回总是正确的吗?

c++ - 如何在 C++ 中检查字符串相似度?

c++ - decltype(auto) 有哪些用途?

javascript - V8 快照二进制文件/调试规范