Re: Ignite.NET how to cancel tasks

2018-08-21 Thread slava.koptilin
Hello Maksym,

Sorry for the delay. I'll try the modified example.

I am not an expert in C#/.Net, so I cannot guarantee that the following
topic will be helpful, but
please take a look at
https://apacheignite-net.readme.io/v2.6/docs/asynchronous-support#section-async-continuations

Thanks,
S.




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Re: Ignite.NET how to cancel tasks

2018-08-12 Thread Maksym Ieremenko
Hello Slava,


please try an modified version of 
https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs,

change CancellationTest+Job.Execute method to:

public int Execute()
{
while (CancelCount == 0)
{
Thread.Sleep(50);
}

return 1;
}


Thanks,
Max


Re: Ignite.NET how to cancel tasks

2018-08-07 Thread Вячеслав Коптилин
Hello,

Have you checked Ignite log files? Do they contain anything suspicious?
I just checked TeamCity and it seems that CancellationTest (that I
mentioned above) is OK.

Thanks,
S.


вт, 7 авг. 2018 г. в 9:47, Maksym Ieremenko :

> Hi Slava,
>
>
>
> >> > using (var ignite = Ignition.Start())
>
> >> Is it possible that Ignite node was closed before the cancellation
> request was processed by an instance of SimpleJob? Could you please check
> that fact?
>
> No.
>
>
>
> I double cheeked: the main thread hangs on
>
> cts.Cancel(); // CancellationTokenSource.Cancel()
>
>
>
> so, the next lines of code will never be reached, stack:
>
>
>
>
> Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.Jni.Env.CallLongMethod
>
> [Managed to Native Transition]
>
> Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.Jni.Env.CallLongMethod(Apache.Ignite.Core.Impl.Unmanaged.Jni.GlobalRef
> obj, System.IntPtr methodId, long* argsPtr)
>
> Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils.TargetInLongOutLong(Apache.Ignite.Core.Impl.Unmanaged.Jni.GlobalRef
> target, int opType, long memPtr)
>
> Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.PlatformJniTarget.InLongOutLong(int
> type, long val)
>
>
> Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Common.Future.OnTokenCancel()
>
> mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
> mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
> mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state)
>
> mscorlib.dll!System.Threading.CancellationCallbackInfo.ExecuteCallback()
>
> mscorlib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool
> throwOnFirstException = false)
>
> mscorlib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool
> throwOnFirstException)
>
> mscorlib.dll!System.Threading.CancellationTokenSource.Cancel()
>
> CancellationDemo.exe!CancellationDemo.Program.RunAsync() Line 49
>
> [Resuming Async Method]
>
> mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
> mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
>
> mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
>
>
> mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
>
>
> mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
>
> mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action
> action, bool allowInlining, ref System.Threading.Tasks.Task currentTask =
> null)
>
> mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
>
> mscorlib.dll!System.Threading.Tasks.Task.TrySetResult(System.Threading.Tasks.VoidTaskResult
> result)
>
> mscorlib.dll!System.Threading.Tasks.Task.DelayPromise.Complete()
>
> mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
> mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
> executionContext, System.Threading.ContextCallback callback, object state,
> bool preserveSyncCtx)
>
> mscorlib.dll!System.Threading.TimerQueueTimer.CallCallback()
>
> mscorlib.dll!System.Threading.TimerQueueTimer.Fire()
>
> mscorlib.dll!System.Threading.TimerQueue.FireNextTimers()
>
>
>
> Best regards,
>
> Max
>


RE: Ignite.NET how to cancel tasks

2018-08-07 Thread Maksym Ieremenko
Hi Slava,

>> > using (var ignite = Ignition.Start())
>> Is it possible that Ignite node was closed before the cancellation request 
>> was processed by an instance of SimpleJob? Could you please check that fact?
No.

I double cheeked: the main thread hangs on
cts.Cancel(); // CancellationTokenSource.Cancel()

so, the next lines of code will never be reached, stack:

Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.Jni.Env.CallLongMethod
[Managed to Native Transition]
Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.Jni.Env.CallLongMethod(Apache.Ignite.Core.Impl.Unmanaged.Jni.GlobalRef
 obj, System.IntPtr methodId, long* argsPtr)
Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Unmanaged.UnmanagedUtils.TargetInLongOutLong(Apache.Ignite.Core.Impl.Unmanaged.Jni.GlobalRef
 target, int opType, long memPtr)
Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.PlatformJniTarget.InLongOutLong(int
 type, long val)
Apache.Ignite.Core.dll!Apache.Ignite.Core.Impl.Common.Future.OnTokenCancel()
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state)
mscorlib.dll!System.Threading.CancellationCallbackInfo.ExecuteCallback()
mscorlib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool
 throwOnFirstException = false)
mscorlib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool 
throwOnFirstException)
mscorlib.dll!System.Threading.CancellationTokenSource.Cancel()
CancellationDemo.exe!CancellationDemo.Program.RunAsync() Line 49
[Resuming Async Method]
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.MoveNextRunner.Run()
mscorlib.dll!System.Runtime.CompilerServices.AsyncMethodBuilderCore.OutputAsyncCausalityEvents.AnonymousMethod__0()
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__0()
mscorlib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action
 action, bool allowInlining, ref System.Threading.Tasks.Task currentTask = null)
mscorlib.dll!System.Threading.Tasks.Task.FinishContinuations()
mscorlib.dll!System.Threading.Tasks.Task.TrySetResult(System.Threading.Tasks.VoidTaskResult
 result)
mscorlib.dll!System.Threading.Tasks.Task.DelayPromise.Complete()
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
 executionContext, System.Threading.ContextCallback callback, object state, 
bool preserveSyncCtx)
mscorlib.dll!System.Threading.TimerQueueTimer.CallCallback()
mscorlib.dll!System.Threading.TimerQueueTimer.Fire()
mscorlib.dll!System.Threading.TimerQueue.FireNextTimers()

Best regards,
Max


Re: Ignite.NET how to cancel tasks

2018-08-06 Thread Вячеслав Коптилин
Hi Max,

> using (var ignite = Ignition.Start())
Is it possible that Ignite node was closed before the cancellation request
was processed by an instance of SimpleJob? Could you please check that fact?
Perhaps you need to modify your code as follows:

var task = ignite.GetCompute().ExecuteAsync(new SimpleTask(), 3, cts.Token);
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
cts.Cancel();

// check that cancellation flag is raised.
Console.WriteLine("status: {0}", task.IsCanceled);

// allow the cluster to handle the cancellation request request
Thread.Sleep(TimeSpan.FromSeconds(10));

Thanks,
S.

вс, 5 авг. 2018 г. в 19:15, Maksym Ieremenko :

> Hello Slava,
>
> Unfortunately demo does not work for me: IComputeJob.Cancel is never
> called.
> In my case an execution of job may take few minutes and I want to receive
> an notification about cancellation.
>
> Please check the following code, SimpleJob will never finish, because
> IComputeJob.Cancel is never called:
>
> using (var ignite = Ignition.Start())
> using (var cts = new CancellationTokenSource())
> {
> var task = ignite.GetCompute().ExecuteAsync(new
> SimpleTask(), 3, cts.Token);
>
> await
> Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
>
> cts.Cancel();
>
> await task.ConfigureAwait(false);
> }
>
> public class SimpleTask : IComputeTask
> {
> public IDictionary, IClusterNode>
> Map(IList subGrid, int jobsPerGridCount)
> {
> return Enumerable
> .Range(1, jobsPerGridCount)
> .SelectMany(i => subGrid)
> .ToDictionary(i => (IComputeJob)new SimpleJob(), i =>
> i);
> }
>
> public ComputeJobResultPolicy OnResult(IComputeJobResult res,
> IList> rcvd)
> {
> return ComputeJobResultPolicy.Wait;
> }
>
> public int Reduce(IList> results)
> {
> return 1;
> }
> }
>
> public class SimpleJob : IComputeJob
> {
> private bool _isCancelled;
>
> public int Execute()
> {
> Console.WriteLine("execute task");
>
> while (!Volatile.Read(ref _isCancelled))
> {
> Thread.Sleep(TimeSpan.FromSeconds(1));
> }
>
> return 1;
> }
>
> public void Cancel()
> {
> // never happens !!!
> Console.WriteLine("cancel task");
>     Volatile.Write(ref _isCancelled, true);
> }
> }
>
> Thanks,
> Max
>
> -Original Message-
> From: slava.koptilin [mailto:slava.kopti...@gmail.com]
> Sent: Donnerstag, 2. August 2018 17:56
> To: user@ignite.apache.org
> Subject: Re: Ignite.NET how to cancel tasks
>
> Hello Maksym,
>
> It seems that you need to call Cancel() method.
> something like as follows:
>
> var cts = new CancellationTokenSource(); var task =
> Compute.ExecuteJavaTaskAsync(ComputeApiTest.BroadcastTask, null,
> cts.Token); cts.Cancel();
>
> Please take a look at this example:
>
> https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs
>
> Thanks,
> Slava.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>


RE: Ignite.NET how to cancel tasks

2018-08-05 Thread Maksym Ieremenko
Hello Slava,

Unfortunately demo does not work for me: IComputeJob.Cancel is never called.
In my case an execution of job may take few minutes and I want to receive an 
notification about cancellation.

Please check the following code, SimpleJob will never finish, because 
IComputeJob.Cancel is never called:

using (var ignite = Ignition.Start())
using (var cts = new CancellationTokenSource())
{
var task = ignite.GetCompute().ExecuteAsync(new SimpleTask(), 
3, cts.Token);

await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);

cts.Cancel();

await task.ConfigureAwait(false);
}

public class SimpleTask : IComputeTask
{
public IDictionary, IClusterNode> 
Map(IList subGrid, int jobsPerGridCount)
{
return Enumerable
.Range(1, jobsPerGridCount)
.SelectMany(i => subGrid)
.ToDictionary(i => (IComputeJob)new SimpleJob(), i => i);
}

public ComputeJobResultPolicy OnResult(IComputeJobResult res, 
IList> rcvd)
{
return ComputeJobResultPolicy.Wait;
}

public int Reduce(IList> results)
{
return 1;
}
}

public class SimpleJob : IComputeJob
{
private bool _isCancelled;

public int Execute()
{
Console.WriteLine("execute task");

while (!Volatile.Read(ref _isCancelled))
{
Thread.Sleep(TimeSpan.FromSeconds(1));
}

return 1;
}

public void Cancel()
{
// never happens !!!
Console.WriteLine("cancel task");
Volatile.Write(ref _isCancelled, true);
}
}

Thanks,
Max

-Original Message-
From: slava.koptilin [mailto:slava.kopti...@gmail.com] 
Sent: Donnerstag, 2. August 2018 17:56
To: user@ignite.apache.org
Subject: Re: Ignite.NET how to cancel tasks

Hello Maksym,

It seems that you need to call Cancel() method.
something like as follows:

var cts = new CancellationTokenSource(); var task = 
Compute.ExecuteJavaTaskAsync(ComputeApiTest.BroadcastTask, null, cts.Token); 
cts.Cancel();

Please take a look at this example:
https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Re: Ignite.NET how to cancel tasks

2018-08-02 Thread slava.koptilin
Hello Maksym,

It seems that you need to call Cancel() method.
something like as follows:

var cts = new CancellationTokenSource();
var task = Compute.ExecuteJavaTaskAsync(ComputeApiTest.BroadcastTask, null,
cts.Token);
cts.Cancel();

Please take a look at this example:
https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/CancellationTest.cs

Thanks,
Slava.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/


Ignite.NET how to cancel tasks

2018-08-02 Thread Maksym Ieremenko
Hi,

How I cancel running tasks on the grid with Ignite.NET?