All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jppf.load.balancer.impl.NodeSimulator Maven / Gradle / Ivy

There is a newer version: 6.3-alpha
Show newest version
/*
 * JPPF.
 * Copyright (C) 2005-2015 JPPF Team.
 * http://www.jppf.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jppf.load.balancer.impl;

import java.util.*;
import java.util.concurrent.*;

import org.jppf.load.balancer.*;
import org.jppf.utils.LoggingUtils;
import org.slf4j.*;

/**
 * Simulation of a node to test a bundler.
 * @author Laurent Cohen
 * @exclude
 */
public class NodeSimulator
{
  /**
   * Logger for this class.
   */
  private static Logger log = LoggerFactory.getLogger(NodeSimulator.class);
  /**
   * Determines whether debugging level is set for logging.
   */
  private static boolean debugEnabled = LoggingUtils.isDebugEnabled(log);
  /**
   * 
   */
  private static int nbNodes = 1;
  /**
   * 
   */
  private static ExecutorService threadPool = null;
  /**
   * Static simulated latency.
   */
  private double latency = 0L;
  /**
   * Dynamic overhead expressed as milliseconds per megabyte of data transferred.
   */
  private double dynamicOverhead = 0.0d;
  /**
   * Relative speed of the node.
   */
  private double speed = 0.0d;

  /**
   * Initialize this simulator with the specified parameters.
   * @param latency static simulated latency.
   * @param dynamicOverhead dynamic overhead expressed as milliseconds per megabyte of data transferred.
   * @param speed relative speed of the node.
   */
  public NodeSimulator(final double latency, final double dynamicOverhead, final double speed)
  {
    this.latency = latency;
    this.dynamicOverhead = dynamicOverhead;
    this.speed = speed;
    log.info("initializing with "+latency+", "+dynamicOverhead+", "+speed);
  }

  /**
   * Simulate the execution of a set of tasks.
   * @param bundler the bundler to send the resulting statistics to.
   * @param sizeMB the size in megabytes of the data that is transferred.
   * @param nbTasks the number of simulated tasks.
   * @param timePerTask the simulated execution time for each task.
   */
  public void run(final Bundler bundler, final double sizeMB, final int nbTasks, final long timePerTask)
  {
    try
    {
      long start = System.nanoTime();
      long a = (long) latency;
      int b = (int) ((latency - a) * 1.0e6);
      Thread.sleep(a, b);
      Thread.sleep((long) (sizeMB * dynamicOverhead));
      for (int i=0; iBundler instance.
     * @see org.jppf.load.balancer.Bundler#copy()
     */
    @Override
    public Bundler copy()
    {
      return new SimulatedProportionalBundler(profile, maximumSize);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy