> 1. Can I transfer an function object from script compiled in global
> context and main thread Isolate into the other thread's Isolate and
> execute there?

No. You have to serialize it somehow (e.g. JSON) in one isolate and
deserialize it in another one.

> 2. If not, Is what I am doing a valid v8 API usage at all? What could
> be other ways to trigger GC more often?

Seem valid to me. But I am a bit confused why forcing GC manually helps so much.

It's not completely clear though why do you need a separate context
for your task because the function you pass as value (not as source)
already has a context attached and will use it but not the context you
have created.

Another thing: do you use weak handles extensively? V8 might be
overflowed by weakly reachable objects. That might cost a lot
especially if those weakly reachable objects hold onto contexts which
you seem to allocate for each task.

--
Vyacheslav Egorov


On Thu, Sep 1, 2011 at 8:34 PM, Dennis H <gluck...@gmail.com> wrote:
> Hi Vyacheslav,
>
> I see your point.
>
> I don't use separate Isolate for each thread and all tasks use
> function objects compiled in the global Context/Isolate.
> This might be a trouble of course, but I was not sure there is a good
> way to create a function object
> in main Context and then transfer it to another Isolate/Context.
>
> Essentially I wanted to achieve following usage:
>
> // thread function
> function foo () {}
>
> // starts execution in a separate thread
> task(foo);
>
> I do make them run exclusively (at least I hope I do) by using
>
>    Locker locker;
>    Locker::StartPreemption(preemption_interval);
>    HandleScope scope;
>
>    context = Context::New();
>    context->Enter();
>
> The code is in a fork from nodejs.You can see the code here:
> https://github.com/bfrancojr/node/blob/node-task/src/node_task.cc
>
> The funny part is that if I create just a couple of threads the memory
> is stable, while I call V8::IdleNotification()  every 5 sec.
>
> If I increase the number of tasks to 100 it will start to grow and
> the process will run out memory. However If I start to call
> V8::IdleNotification() every 0.3 seconds it fixes it again.
>
> I've got a feeling the v8 treats the GC as one of the tasks, meaning
> that the more tasks I create the more time is allocated to 'garbage
> producers'
> and the smaller is a relative portion of time for GC. May be I am
> wrong.
>
> So the questions are:
>
> 1. Can I transfer an function object from script compiled in global
> context and main thread Isolate into the other thread's Isolate and
> execute there?
> 2. If not, Is what I am doing a valid v8 API usage at all? What could
> be other ways to trigger GC more often?
>
> Thanks,
> Dennis
>
> On Aug 31, 12:44 am, Vyacheslav Egorov <vego...@chromium.org> wrote:
>> Hi Dennis,
>>
>> V8's GC is stop-the-world type so you don't have to do anything
>> special to make it "keep up". If you are getting OOM that most
>> probably means you have a leak somewhere. Try tracing GC with
>> --trace-gc flag to see how heap grows.
>>
>> Also you can't run JavaScript in parallel on V8 unless you create
>> several isolates.
>>
>> If you are using a single isolate from many threads you have to ensure
>> that only one thread is executing JS at the given moment.
>>
>> --
>> Vyacheslav Egorov
>>
>> On Wed, Aug 31, 2011 at 2:28 AM, Dennis H <gluck...@gmail.com> wrote:
>> > Dear v8 Developers,
>>
>> > I am relatively new to v8 internals, but here is what I found:
>> > I tried to create an app which has multiple tasks running in parallel.
>> > The v8::internal::Thread API seems to work fine, the trouble is I
>> > didn't find a good way to make garbage collection to keep up.
>>
>> > I do call the V8::IdleNotification() in the main event loop
>> > periodically, but it doesn't scale if number of threads is getting
>> > bigger. Essentially If I create a lot of tasks, the process would
>> > reliably run out of memory pretty quick.
>>
>> > How is the garbage collection supposed to be handled correctly with
>> > multiple threads?
>>
>> > I used v3.4.14.
>>
>> > Thanks,
>> > Dennis
>>
>> > --
>> > v8-users mailing list
>> > v8-users@googlegroups.com
>> >http://groups.google.com/group/v8-users
>
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
>

-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users

Reply via email to