Creating multiple Isolates

150 views
Skip to first unread message

Joris Wijnant

unread,
Apr 28, 2016, 10:25:09 AM4/28/16
to v8-users
Hi,

I need to create a total of 200-300 instances of v8::Isolate. 
each handling the input of a socket and they need to be strictly separated from each other.
However the V8 engine crashes after creating 50 of them.
Which is around 300MB.

The memory limit for v8 should be 700MB for 32 bit, but i don't even reach half of it.
so that seems strange to me.

I tried using --max-old-space-size=2000, but that did not change anything.

What do I need to do, to create those 200 instances of v8::Isolate?

kr,
joris

Jakob Kummerow

unread,
Apr 28, 2016, 10:47:47 AM4/28/16
to v8-users
How is it crashing? Without a backtrace or error message it's hard to help.

The heap size limit is per Isolate (because each Isolate has its own heap), so it shouldn't affect the number of Isolates you can create.

However 200 isolates on a 32-bit system with 2GB memory address space means only 10MB per Isolate, which won't allow you to do much of anything.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joris Wijnant

unread,
Apr 28, 2016, 11:29:02 AM4/28/16
to v8-users
For some reason can i go to 700MB, instead of the 300MB earlier, but i don't know what changed :s
I'm reaching 140 isolates, which is coming closer, but not enough.
Also each isolate only contains a few objects, so 10MB should be more than enough.

This time it crashes by raising a SIGABRT.

stacktrace at the moment of the crash

> VoxJavascriptTest.exe!v8::base::OS::Abort() Line 835 C++
  VoxJavascriptTest.exe!V8_Fatal(const char * file, int line, const char * format, ...) Line 117 C++
  VoxJavascriptTest.exe!v8::base::VirtualMemory::address() Line 308 C++
  VoxJavascriptTest.exe!v8::internal::MarkCompactCollector::EnsureMarkingDequeIsCommitted(unsigned int max_size) Line 1947 C++
  VoxJavascriptTest.exe!v8::internal::MarkCompactCollector::SetUp() Line 250 C++
  VoxJavascriptTest.exe!v8::internal::Heap::SetUp() Line 5242 C++
  VoxJavascriptTest.exe!v8::internal::Isolate::Init(v8::internal::Deserializer * des) Line 2217 C++
  VoxJavascriptTest.exe!v8::Isolate::New(const v8::Isolate::CreateParams & params) Line 7229 C++

Op donderdag 28 april 2016 16:25:09 UTC+2 schreef Joris Wijnant:

Jakob Kummerow

unread,
Apr 28, 2016, 12:51:50 PM4/28/16
to v8-users
That stack trace indicates you ran into DCHECK(IsReserved()); in VirtualMemory::address(). That check would fail if the previous mmap() call failed to reserve memory, which happens when the process's virtual memory address space is exhausted.
You didn't specify which V8 version you're using, but chances are it reserves 16MB of virtual address space for the "new space" part of the heap. You don't see this show up as consumed memory, because it's not actually used yet, it's just reserved for future use. Along with some other memory that's reserved or allocated on startup, I'd estimate about 20MB of address space per Isolate. 140 Isolates puts you at 2800MB of address space usage, so it's not surprising that you're running into the system's limits around that time.

--

Joris Wijnant

unread,
Apr 29, 2016, 8:03:36 AM4/29/16
to v8-users

What is the reason that is reserves 16 MB?
I know that reserving some extra space can be for performance, that way you don't need to request more if you ran out.
But what is the reason for 16 MB, why not less?

and can I possibly lower it, to lets say 5MB?


Jakob Kummerow

unread,
Apr 29, 2016, 8:40:25 AM4/29/16
to v8-users
On Fri, Apr 29, 2016 at 2:03 PM, Joris Wijnant <wijnan...@gmail.com> wrote:

What is the reason that is reserves 16 MB?
I know that reserving some extra space can be for performance, that way you don't need to request more if you ran out.
But what is the reason for 16 MB, why not less?

AFAIK that's what NewSpace could dynamically grow to, and it needed to be in a contiguous address range. The only way to guarantee that is to reserve the range up front.
 
and can I possibly lower it, to lets say 5MB?

The current master branch as of the past few weeks should behave differently.

However, as you can see from this example, V8 isn't designed to run with so little address space, nor is that scenario tested or supported by us. It's very likely that even if you work around this particular issue and manage to instantiate all your Isolates, something else will blow up. At the very least, I would suggest running all this on a 64-bit system; or even better reconsider whether you really need hundreds of Isolates at the same time to accomplish your goal.

Joris Wijnant

unread,
Apr 29, 2016, 9:35:07 AM4/29/16
to v8-users

maybe an alternative idea: i've read that it is possible to create multiple contexts within one isolate.
so instead of multiple isolates, i could create only one, and create multiple contexts.

Are those context separated from, or can they interfere with eachother?
and what are the traps you need to look out for when creating multple contexts?

Ryan Ingram

unread,
May 12, 2016, 9:04:37 PM5/12/16
to v8-users
I'm not a V8 expert, but I'll try to answer this.

* Each Isolate can only be entered by a single thread at a time.
* However, Isolates can be migrated between threads.  For example, Node.js only uses a single Context, but has multithreading of background (non-script) code like I/O.  This is similar to Python's Global Interpreter Lock.
* So if you want scripts to run multithreaded, you need to create at least one Isolate per thread.
* Each Context only exists in a single Isolate; you can't migrate a Context from one Isolate to another.
* Each Context has a security token.  If a context somehow manages to get a reference to another context's object, it can still only interact with that object if the security tokens match, or you write a policy to allow that interaction (here is where my knowledge gets fuzzy).

In general, contexts are designed to be independent and non-interfering, as long as there's no aggressive behavior happening such as denial-of-service (one context allocating all the memory in the system, or running an infinite loop).  Consider multiple IFrames on a single web page, each pointing at a different domain--the scripts on those pages can't spy on each other's objects.

So it depends what you mean by "interfere with each other".
Reply all
Reply to author
Forward
0 new messages