JPPF, java, parallel computing, distributed computing, grid computing, parallel, distributed, cluster, grid, cloud, open source, android, .net
JPPF

The open source
grid computing
solution

 Home   About   Features   Download   Documentation   On Github   Forums 
October 22, 2020, 10:26:21 PM *
Welcome,
Please login or register.

Login with username, password and session length
Advanced search  
News: New users, please read this message. Thank you!
  Home Help Search Login Register  
Pages: [1]   Go Down

Author Topic: JPPFExecutorService & exceptions  (Read 2243 times)

row_perfect

  • Guest
JPPFExecutorService & exceptions
« on: September 06, 2012, 07:34:56 AM »

Hi,

I have the following in my NodeLifeCycleListener.jobStarted():

catch (final Throwable t) {
         log.error("Infrastructural error for jobId=" + job.getUuid(), t);
         try {
            final JMXNodeConnectionWrapper jmx = new JMXNodeConnectionWrapper();
            jmx.connect();
            log.warn("Cancelling job " + job.getUuid());
            jmx.cancelJob(job.getUuid(), false);
            // log.warn("*** restarting this node ***");
            // FIXME jmx.restart();
         } catch (final Exception e) {
            throw new RuntimeException(e);
         }

      }


Is there any way that this exception could be returned to the client?

Also, if this code gets triggered,  I would have expected the task future to show cancelled=true:

   @Test
   public void testLifeCycleExceptionPropagatedToClient() throws FactoryConfigurationError, Exception {
      final JPPFExecutorService executor = new JPPFExecutorService(jppfClient);
      executor.setBatchSize(1000);
      executor.setBatchTimeout(100L);
      final JobMetadata metadata = executor.getConfiguration().getJobConfiguration().getMetadata();
      // this will cause a ClassCastException to be throw in NodeLifeCycleListener
      metadata.setParameter("initialiser", "string");

      final List<Future<?>> futures = new ArrayList<>();

      for (int j = 0; j < 100; j++) {
         for (int i = 0; i < 10; i++) {
            futures.add(executor.submit(new FailingTaskChecked()));
         }
      }

      for (int i = 0; i < futures.size(); i++) {
         final Future<?> f = futures.get(i);
         assertFalse(f.isDone());
         assertTrue(f.isCancelled()); // THIS ASSERTION FAILS
      }
   }

The only indication that the task was never run is that Future.isDone() returns false.

On a related note, would it be possible to add an API by which to track job(s) progress when using the Executor service - even a task completion listener would do. Counting back the futures isn't ideal if one task gets 'stuck'.

Thanks, Paul
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2262
    • JPPF Web site
Re: JPPFExecutorService & exceptions
« Reply #1 on: September 18, 2012, 07:24:22 AM »

Hi Paul,

Currently, there is no specific exception handling for the exceptions returned by the methods of NodeLifeCycleListenener. So, throwing a RuntimeException will cause the node send a nodeEnding() notification and to reset itself (i.e. disconnect then reconnect to the server). In particular there is no built-in mechanism to capture the exception and send it back with the job.
There are several ways you could report the exception back to the client:
- use a custom node MBean to send notification to the client (the client would have to register a notification listener)
- add initialization code in your tasks to check if an exception occurred within the NodeLifeCycleListenener, for instance using static accessors or any other way, and report it within the tasks results
- use other means of communication between node and client, such a s a distributed cache for instance
- etc...

About the isCancelled() indicator, the JPPFExecutorService does not fully implement the semantics of java.util.concurrent.ExecutorService, which was never intended for distributed systems in the first place. So Future.isCancelled() will always return false for tasks submitted via JPPFExecutorService. We are still thinking how best to implement this, so I don't think it will be any time soon. So far, I believe it will have to be encapsulated within the JPPFTask.onCancel() mechanism and in the job cancelling logic, accounting for scenarios where a job is cancelled before even going to a node.

Quote
On a related note, would it be possible to add an API by which to track job(s) progress when using the Executor service - even a task completion listener would do. Counting back the futures isn't ideal if one task gets 'stuck'.

I have added this to JPPF-53 Enhancements to JPPFExecutorService , see point 2).

I hope this helps,
-Laurent
Logged

row_perfect

  • Guest
Re: JPPFExecutorService & exceptions
« Reply #2 on: September 18, 2012, 08:34:14 AM »

Currently, there is no specific exception handling for the exceptions returned by the methods of NodeLifeCycleListenener. So, throwing a RuntimeException will cause the node send a nodeEnding() notification and to reset itself (i.e. disconnect then reconnect to the server).

My experience of this so far is that if the NodeLifeCycleListenener throws an exception then it's terminal for both node AND driver and the entire grid needs restarting. I just get class not found for SerializationHelperImpl (or something very similar) for any further jobs that the submitting client or any new client submits. It's quite possible that I've done something dumb.

Thanks for the tips on client feedback, I'll have a look.

Paul
Logged
Pages: [1]   Go Up
 
JPPF Powered by SMF 2.0 RC5 | SMF © 2006–2011, Simple Machines LLC Get JPPF at SourceForge.net. Fast, secure and Free Open Source software downloads