Esempio n. 1
0
  public static void main(String[] args) throws IOException, TException {
    OptionParser parser = new OptionParser();
    parser.accepts("c", "configuration file").withRequiredArg().ofType(String.class);
    parser.accepts("help", "print help statement");
    OptionSet options = parser.parse(args);

    if (options.has("help")) {
      parser.printHelpOn(System.out);
      System.exit(-1);
    }

    // Logger configuration: log to the console
    BasicConfigurator.configure();
    LOG.setLevel(Level.DEBUG);
    LOG.debug("debug logging on");

    Configuration conf = new PropertiesConfiguration();

    if (options.has("c")) {
      String configFile = (String) options.valueOf("c");
      try {
        conf = new PropertiesConfiguration(configFile);
      } catch (ConfigurationException e) {
      }
    }
    // Start backend server
    BackendService.Processor<BackendService.Iface> processor =
        new BackendService.Processor<BackendService.Iface>(new ProtoBackend());

    int listenPort = conf.getInt("listen_port", DEFAULT_LISTEN_PORT);
    NM_PORT = conf.getInt("node_monitor_port", NodeMonitorThrift.DEFAULT_NM_THRIFT_PORT);
    TServers.launchThreadedThriftServer(listenPort, THRIFT_WORKER_THREADS, processor);

    // Register server
    client = TClients.createBlockingNmClient(NM_HOST, NM_PORT);

    try {
      client.registerBackend(APP_ID, "localhost:" + listenPort);
      LOG.debug("Client successfullly registered");
    } catch (TTransportException e) {
      LOG.debug("Error while registering backend: " + e.getMessage());
    }
  }
Esempio n. 2
0
    @Override
    public void run() {
      if (startTime == -1) {
        startTime = System.currentTimeMillis();
      }

      long taskStart = System.currentTimeMillis();
      NodeMonitorService.Client client = null;
      try {
        client = TClients.createBlockingNmClient(NM_HOST, NM_PORT);
      } catch (IOException e) {
        LOG.fatal("Error creating NM client", e);
      }

      int tasks = numTasks.addAndGet(1);
      double taskRate = ((double) tasks) * 1000 / (System.currentTimeMillis() - startTime);
      LOG.debug("Aggregate task rate: " + taskRate);

      Random r = new Random();

      long benchmarkStart = System.currentTimeMillis();
      runBenchmark(benchmarkId, benchmarkIterations, r);
      LOG.debug("Benchmark runtime: " + (System.currentTimeMillis() - benchmarkStart));

      // Update bookkeeping for task finish
      synchronized (resourceUsage) {
        TResources.subtractFrom(resourceUsage, taskResources);
      }

      HashMap<TUserGroupInfo, TResourceVector> out = new HashMap<TUserGroupInfo, TResourceVector>();
      // Inform NM of resource usage
      out.put(user, resourceUsage);
      try {
        client.tasksFinished(Lists.newArrayList(taskId));
      } catch (TException e) {
        e.printStackTrace();
      }
      client.getInputProtocol().getTransport().close();
      client.getOutputProtocol().getTransport().close();
      LOG.debug("Task running for " + (System.currentTimeMillis() - taskStart) + " ms");
    }