> > we are currently using V8 in a kind of server-side scripting engine.
> > Javascript is used for implementing business-level logic. V8 is nice,
> > really! It is fast and well structured. But... Suppose we want to run
> > a 1000+ small scripts simultaneosly. How can we achieve this? Run
> > 1000+ processes like Chrome do? Well, not a smart idea. So we have a
> > single process with 1000+ V8 contexts and there can be only one script
> > running in V8 at the moment. If it is somehow slow we are stuck,
> > others are waiting.
>
> I appreciate this is annoying, but it's not actually that easy.  The
> contexts are not really independent at the VM level.  The
> single-threaded assumption is in 1000 undocumented places in the code.
>

Well, isn't that a great adventure - find them all?! Build a better
structured code? :-)

Ok, just kidding, I understand your point but I was thinking of...
well...
Of not 1000 very-local-locks, but 10 not-so-global locks.
Locks that lock big parts but anyway allow to keep running several
scripts. All we need is not stopping others forever.

If threads would spend 10% their time waiting
on those not-so-global-locks that's okay anyway, because they now
run on 4 CPU instead of 1 (for example).

> Let me suggest some workarounds.  I am guessing that you don't have
> 1000 CPUs.  So it might be possible to have one or two V8 processes
> per CPU, then a load balancer that distributes incoming requests to V8
> proceses.  If you run with preemption support you can switch between
> V8 threads if one thread gets into a long calculation.  If your V8
> threads are hanging because they are doing long-running IO then you
> can use the v8::Unlocker class to free up the V8 lock while IO takes
> place.

Well, several processes is a some sort of solution. But it's not an
easy solution.
IPC comes in place, load balancing, something else. It's a solution if
nothing else helps :-)


You are saying that I can do V8::unlock inside the C++ function that
was called from JS if this C++ function not interfere with V8? Hmm...

That's interesting. I use SQLITE embedded in V8 script and if I can
run V8 while SQLITE is doing his job it's some sort of optimization...

What if this C++ function has to call another V8 function in turn (so
the stack is JS-function C++-function JS-function)?
I need to V8::Lock again before javascript-function call?


void foo()
{
   v8::Locker locker;
   some_code.Run(); // this javascript code calls cpp_foo ()
//  release lock on destructor call
}

Handle<Value> cpp_foo(const Arguments& args) // called from V8
{
   string abc = to_string(args[0]);


   {
 // okay, since this moment let's forget about V8
      v8::Unlocker unlocker;
      sqlengine.execute(abc);
   } // release unlock on destructor call

// now I can again use V8?  And I can run another javascript code?

  some_else_code.Run();

}

Is this right?


Thanks for your help and fast reply, anyway.


--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to