Permalink
Browse files

MB-7467: use un-lock-ful javascript task termination

I've found that V8's own preemption is not really effective. When we
wanted to terminate mapreduce task we needed to grab isolate
lock. Thus we depended not only on v8's preemption (which I've
confirmed via source code) periodically unlocks isolate and does
sched_yield, but also on somewhat fair mutex locking.

What I've observed in practice is that sched_yield was apparently not
enough to give terminateTask thread chance to grab isolate lock in
time.

Luckily for us, V8 has terminate API that doesn't require locking
isolate and using it doesn't depend on preemption at all.

Because we don't need taskId anymore I've removed this field. And
because we don't need preemption anymore (which is costly to setup
(i.e. spawns thread)), I've removed it too.

Change-Id: I1e194211c477c5fa1ef78d07e1a3cc05b06fa24e
Reviewed-on: http://review.couchbase.org/23580
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Volker Mische <volker.mische@gmail.com>
Reviewed-on: http://review.couchbase.org/24951
  • Loading branch information...
1 parent aa2c26f commit 88cc07da63b638988632f4bde1f3e58e692a805a Aliaksey Kandratsenka committed with fdmanana Dec 27, 2012
Showing with 1 addition and 13 deletions.
  1. +1 −12 src/mapreduce/mapreduce.cc
  2. +0 −1 src/mapreduce/mapreduce.h
View
@@ -135,7 +135,6 @@ void doInitContext(map_reduce_ctx_t *ctx, const function_sources_list_t &funs)
ctx->isolate = Isolate::New();
Locker locker(ctx->isolate);
Isolate::Scope isolateScope(ctx->isolate);
- Locker::StartPreemption(20);
HandleScope handleScope;
ctx->jsContext = createJsContext(ctx);
@@ -156,7 +155,6 @@ void doInitContext(map_reduce_ctx_t *ctx, const function_sources_list_t &funs)
ctx->isolate->SetData(isoData);
ctx->taskStartTime = -1;
- ctx->taskId = -1;
}
@@ -360,7 +358,6 @@ void destroyContext(map_reduce_ctx_t *ctx)
{
Locker locker(ctx->isolate);
Isolate::Scope isolateScope(ctx->isolate);
- Locker::StopPreemption();
HandleScope handleScope;
Context::Scope contextScope(ctx->jsContext);
@@ -552,7 +549,6 @@ isolate_data_t *getIsolateData()
void taskStarted(map_reduce_ctx_t *ctx)
{
- ctx->taskId = V8::GetCurrentThreadId();
ctx->taskStartTime = static_cast<long>((clock() / CLOCKS_PER_SEC) * 1000);
ctx->kvs = NULL;
}
@@ -561,19 +557,12 @@ void taskStarted(map_reduce_ctx_t *ctx)
void taskFinished(map_reduce_ctx_t *ctx)
{
ctx->taskStartTime = -1;
- ctx->taskId = -1;
}
void terminateTask(map_reduce_ctx_t *ctx)
{
- Locker locker(ctx->isolate);
- Isolate::Scope isolateScope(ctx->isolate);
-
- if (ctx->taskId != -1) {
- V8::TerminateExecution(ctx->taskId);
- taskFinished(ctx);
- }
+ V8::TerminateExecution(ctx->isolate);
}
@@ -69,7 +69,6 @@ typedef struct {
kv_pair_list_t *kvs;
unsigned int key;
ErlNifEnv *env;
- volatile int taskId;
volatile long taskStartTime;
} map_reduce_ctx_t;

0 comments on commit 88cc07d

Please sign in to comment.