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 
June 03, 2023, 04:13:55 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: Limit max. used Threads on a Node by JobSLA  (Read 1800 times)

neep

  • JPPF Padawan
  • *
  • Posts: 6
Limit max. used Threads on a Node by JobSLA
« on: July 22, 2014, 04:30:34 PM »

Hello everyone,

i'm very new to JPPF and i've got the following question:

Is it possible to limit the number of used threads on a specific node via an execution policy or a similar job SLA?
I know thats its possible to limit the execution of tasks within a job to specific nodes with the use of execution policies.

Here the example:
I have a bunch of Desktop-PCs in a business environment, mostly used for office stuff. We want to do some computations on them, without using alle cores of each machine, so that working on it stays fluid. But in the night, we want to use all cores. So i dont want to set the thread pool size per node configuration.

So is there a way to set it for each job?

Greetz,
Oliver
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: Limit max. used Threads on a Node by JobSLA
« Reply #1 on: July 22, 2014, 09:05:29 PM »

Hello Oliver,

The SLA of a job, including the execution policy, is only evaluated on the server side and does not provide the ability to modify the chosen node's number of threads. The execution policy only serves to filter the nodes for which a job is eligible.

Thus, you need another way to implement your requirements. A good solution would be to use a node life cycle listener whose jobStarting() notification method would enforce the desired number of threads via the node management APIs, using a local connection to the node JMX server.

As an example, here is a very simple implementation:

Code: [Select]
public class TimeSensitiveNodeListener extends NodeLifeCycleListenerAdapter {
  @Override
  public void jobStarting(NodeLifeCycleEvent event) {
    Calendar now = new GregorianCalendar();
    now.setTime(new Date());
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int nbCores = Runtime.getRuntime().availableProcessors();
    try (JMXNodeConnectionWrapper jmx = getJmxConnection()) {
      // during business hours, use only one core
      if ((hour < 9) || (hour > 18)) jmx.updateThreadPoolSize(1);
      // during off hours, use all available cores
      else jmx.updateThreadPoolSize(nbCores);
    } catch(Exception e) {
      e.printStackTrace();
    }
  }

  // get a connection to the node's MBean server
  private JMXNodeConnectionWrapper getJmxConnection() {
    // local connection: no network involved, it's much faster
    JMXNodeConnectionWrapper jmx = new JMXNodeConnectionWrapper();
    jmx.connect();
    return jmx;
  }
}

You could eventually make this more sophisticated by having the actual schedule for business hours set as job metadata, or any means you see fit ... the possibilities are without limit.

I hope this helps.

Sincerely,
-Laurent
Logged

neep

  • JPPF Padawan
  • *
  • Posts: 6
Re: Limit max. used Threads on a Node by JobSLA
« Reply #2 on: July 23, 2014, 03:56:31 PM »

Thanks Laurent, this gave me a great hint.
But i have a problem, might be a little one, but i dont know solving it. When i'm trying to compile your code, the compiler tells me this error:

setzeThreads2.java:13: error: try-with-resources not applicable to variable type
    [javac]     try (JMXNodeConnectionWrapper jmx = getJmxConnection()) {
    [javac]                                   ^
    [javac]   required: AutoCloseable
    [javac]   found:    JMXNodeConnectionWrapper
    [javac] 1 error

The JPPF API Documentation tells me AutoCloseable seems to be implemented in JMXNodeConnectionWrapper, so i dont understand getting the error message.

Any hint solving this?
« Last Edit: July 23, 2014, 03:59:45 PM by neep »
Logged

lolo

  • Administrator
  • JPPF Council Member
  • *****
  • Posts: 2272
    • JPPF Web site
Re: Limit max. used Threads on a Node by JobSLA
« Reply #3 on: July 23, 2014, 07:15:21 PM »

Hi Oliver,

There are two possibilities:
- since the JPPF API you're using is before 4.2 (JMXNodeConnectionWrapper did not implement closeable before this version), you can upgrade your JPPF jar files to v4.2
- or you can use the "old" try {} finally {} syntax:
Code: [Select]
JMXNodeConnectionWrapper jmx = null;
try {
  jmx = getJmxConnection();
  ...
} finally {
  jmx.close();
}

Sincerely,
-Laurent
Logged

neep

  • JPPF Padawan
  • *
  • Posts: 6
Re: Limit max. used Threads on a Node by JobSLA
« Reply #4 on: July 24, 2014, 12:16:19 PM »

Thanks Laurent!
I did not know that closeable wasnt implemented in the JMXNodeConnectionWrapper before 4.2. It works now.
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