Re: Service Grid launching Compute Tasks

2018-03-22 Thread aealexsandrov
Hi Neeraj,

Generally you can launch compute tasks from execute method because they will
use separated thread pools executors. Also according documentation you can
be in execute method until cancel method will not called:

https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/services/Service.html

"Starts execution of this service. This method is automatically invoked
whenever an instance of the service is deployed on a grid node. Note that
service is considered deployed even after it exits the execute method and
can be cancelled (or undeployed) only by calling any of the cancel methods
on IgniteServices API. Also note that service is not required to exit from
execute method until cancel(ServiceContext) method was called."

Also if you will take a look at implementation of the GridServiceProcessor
you can see next:

// Start service in its own thread.
final ExecutorService exe = svcCtx.executor();

exe.execute(new Runnable() {
@Override public void run() {
try {
svc.execute(svcCtx);
}
catch (InterruptedException |
IgniteInterruptedCheckedException ignore) {
if (log.isDebugEnabled())
log.debug("Service thread was interrupted
[name=" + svcCtx.name() + ", execId=" +
svcCtx.executionId() + ']');
}
catch (IgniteException e) {
if (e.hasCause(InterruptedException.class) ||
   
e.hasCause(IgniteInterruptedCheckedException.class)) {
if (log.isDebugEnabled())
log.debug("Service thread was interrupted
[name=" + svcCtx.name() +
", execId=" + svcCtx.executionId() +
']');
}
else {
U.error(log, "Service execution stopped with
error [name=" + svcCtx.name() +
", execId=" + svcCtx.executionId() + ']',
e);
}
}
catch (Throwable e) {
log.error("Service execution stopped with error
[name=" + svcCtx.name() +
", execId=" + svcCtx.executionId() + ']', e);

if (e instanceof Error)
throw (Error)e;
}
finally {
// Suicide.
exe.shutdownNow();
}
}
});

It means that you should manage your exceptions (e.g SocketTimeoutException
for tcp connection) and possible deadlocks.

If you have any problems with it then please send the example for
reproducing.

Thank you,
Andrei



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


Service Grid launching Compute Tasks

2018-03-21 Thread Neeraj Vaidya
Hi,
Is it advisable to launch compute tasks from the execute method of a Service 
implementation task ? Are there any shortcomings ?
The service execute methods are long running back ground method waiting for 
data arrival in queues/pipes, tcp connections, file system folders,  etc.

Regards,
Neeraj