You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Matt <dr...@gmail.com> on 2017/07/16 12:08:52 UTC

Compute Grid Questions

Hi all,

I want to run some code on a node based on an affinity key, for that I'm
using ignite.compute().affinityRunAsync(...) but I have a few questions
about this.

*1.* Is it possible to give every closure a name (kind of an id), so that
when I start a new client, I can somehow get the list of running closures
and stop/start them accordingly?

*2.* The closure I'm running never ends. I thought calling future.cancel()
would cancel it, but it's not the case, it keeps logging things on the
console. What's the proper way to stop the execution of a closure?

*3.* I've seen there's a ignite.compute().withName(...) and
ignite.compute().activeTaskFutures() method, but I've no idea how or when
to use them, specially since the futures doesn't have a name but a uuid.
Also, what exactly is a "task" in Ignite and how does it differs from a
closure (ie, IgniteRunnable)?

Cheers,
Matt

Re: Compute Grid Questions

Posted by Matt <dr...@gmail.com>.
Got it. Thank you.

Matt

On Tue, Jul 18, 2017 at 8:21 PM, vkulichenko <va...@gmail.com>
wrote:

> Matt,
>
> undeployTask method is about task deployment [1], it's unrelated to the
> discussion.
>
> [1] https://apacheignite.readme.io/docs/deployment-spi
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15091.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Compute Grid Questions

Posted by vkulichenko <va...@gmail.com>.
Matt,

undeployTask method is about task deployment [1], it's unrelated to the
discussion.

[1] https://apacheignite.readme.io/docs/deployment-spi

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15091.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Compute Grid Questions

Posted by Matt <dr...@gmail.com>.
Hi Slava,

I didn't know flags were cleared by *Thread.sleep()*, that makes sense now.

Approach 1 in the code below works fine, but the second approach still
won't interrupt a task with a given name. I'm surely missing something else.

Is *ignite.compute().undeployTask(...)* supposed to work like this?

https://gist.github.com/anonymous/3891dfedf26bfcf3314215004e67daa8

Thanks,
Matt

On Tue, Jul 18, 2017 at 8:50 AM, slava.koptilin <sl...@gmail.com>
wrote:

> Hi Matt,
>
> It seems that your code is not quite correct.
> In accordance with the spec Thread.sleep(long millis) clears the
> interrupted
> status in case of InterruptedException is raised.
> Could you try the following implementation of IgniteRunnable?
>
>     public static class MyTask implements IgniteRunnable {
>         @Override public void run() {
>             boolean isInterrupted = false;
>
>             while (!isInterrupted) {
>                 isInterrupted = Thread.currentThread().isInterrupted();
>
>                 try {
>                     Thread.sleep(3000);
>                 }
>                 catch (InterruptedException e) {
>                     isInterrupted = true;
>                 }
>
>                 System.out.println("isInterrupted: " + isInterrupted);
>             }
>         }
>     }
>
> Thanks,
> Slava.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15055.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Compute Grid Questions

Posted by "slava.koptilin" <sl...@gmail.com>.
Hi Matt,

It seems that your code is not quite correct.
In accordance with the spec Thread.sleep(long millis) clears the interrupted
status in case of InterruptedException is raised.
Could you try the following implementation of IgniteRunnable?

    public static class MyTask implements IgniteRunnable {
        @Override public void run() {
            boolean isInterrupted = false;

            while (!isInterrupted) {
                isInterrupted = Thread.currentThread().isInterrupted();

                try {
                    Thread.sleep(3000);
                }
                catch (InterruptedException e) {
                    isInterrupted = true;
                }

                System.out.println("isInterrupted: " + isInterrupted);
            }
        }
    }

Thanks,
Slava.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15055.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Compute Grid Questions

Posted by Matt <dr...@gmail.com>.
Hi Val,

I tried doing *future.cancel()* and *compute().undeployTask("foo")*, check
[1]. Are they equivalent in this case?

*Thread.interrupted()* is always false, so I'm guessing that's not the
correct flag I should be checking.

[1] https://gist.github.com/anonymous/0a8759e70eddab470f09dcb92644f3c7

Thanks,
Matt


On Mon, Jul 17, 2017 at 2:26 PM, vkulichenko <va...@gmail.com>
wrote:

> Hi Matt,
>
> 1. Each task or closure execution creates a session that has an ID. You can
> cast returned IgniteFuture to ComputeTaskFuture (unfortunately there is no
> other way now) and then use getTaskSession() method to get the session
> description. However, this information is available only on the node that
> executed the job, there is currently no way to cancel it from other client.
>
> 2. When job is cancelled, thread that is running it is interrupted. Job
> should check the interrupted flag and stop the execution if needed.
>
> 3. See #1. Having session ID, you can get a future for a task and then
> cancel it. But again, it's all local - this state is not shared across
> nodes.
>
> -Val
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15015.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Compute Grid Questions

Posted by vkulichenko <va...@gmail.com>.
Hi Matt,

1. Each task or closure execution creates a session that has an ID. You can
cast returned IgniteFuture to ComputeTaskFuture (unfortunately there is no
other way now) and then use getTaskSession() method to get the session
description. However, this information is available only on the node that
executed the job, there is currently no way to cancel it from other client.

2. When job is cancelled, thread that is running it is interrupted. Job
should check the interrupted flag and stop the execution if needed.

3. See #1. Having session ID, you can get a future for a task and then
cancel it. But again, it's all local - this state is not shared across
nodes.

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Compute-Grid-Questions-tp14980p15015.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.