<commit_before>/*
 * Copyright 2016 LinkedIn Corp.
 *
 * 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 com.linkedin.drelephant.mapreduce;

import com.linkedin.drelephant.analysis.HadoopApplicationData;
import com.linkedin.drelephant.analysis.HadoopMetricsAggregator;
import com.linkedin.drelephant.analysis.HadoopAggregatedData;
import com.linkedin.drelephant.configurations.aggregator.AggregatorConfigurationData;
import com.linkedin.drelephant.mapreduce.data.MapReduceApplicationData;
import org.apache.log4j.Logger;


public class MapReduceMetricsAggregator implements HadoopMetricsAggregator {

  private static final Logger logger = Logger.getLogger(MapReduceMetricsAggregator.class);
  private static final String MAP_CONTAINER_CONFIG = "mapreduce.map.memory.mb";
  private static final String REDUCER_CONTAINER_CONFIG = "mapreduce.reduce.memory.mb";
  private static final String REDUCER_SLOW_START_CONFIG = "mapreduce.job.reduce.slowstart.completedmaps";

  private HadoopAggregatedData _hadoopAggregatedData = null;
  private TaskLevelAggregatedMetrics mapTasks;
  private TaskLevelAggregatedMetrics reduceTasks;

  private AggregatorConfigurationData _aggregatorConfigurationData;

  public MapReduceMetricsAggregator(AggregatorConfigurationData _aggregatorConfigurationData) {
    this._aggregatorConfigurationData = _aggregatorConfigurationData;
    _hadoopAggregatedData = new HadoopAggregatedData();
  }

  @Override
  public void aggregate(HadoopApplicationData hadoopData) {

    MapReduceApplicationData data = (MapReduceApplicationData) hadoopData;

    long mapTaskContainerSize = getMapContainerSize(data);
    long reduceTaskContainerSize = getReducerContainerSize(data);

    int reduceTaskSlowStartPercentage =
        (int) (Double.parseDouble(data.getConf().getProperty(REDUCER_SLOW_START_CONFIG)) * 100);

    mapTasks = new TaskLevelAggregatedMetrics(data.getMapperData(), mapTaskContainerSize, data.getSubmitTime());

    long reduceIdealStartTime = mapTasks.getNthPercentileFinishTime(reduceTaskSlowStartPercentage);

    // Mappers list is empty
    if(reduceIdealStartTime == -1) {
      // ideal start time for reducer is infinite since it cannot start
      reduceIdealStartTime = Long.MAX_VALUE;
    }

    reduceTasks = new TaskLevelAggregatedMetrics(data.getReducerData(), reduceTaskContainerSize, reduceIdealStartTime);
<commit_msg>LIHADOOP-20626 Ignore slow start for considering reducer delay<commit_after>/*
 * Copyright 2016 LinkedIn Corp.
 *
 * 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 com.linkedin.drelephant.mapreduce;

import com.linkedin.drelephant.analysis.HadoopApplicationData;
import com.linkedin.drelephant.analysis.HadoopMetricsAggregator;
import com.linkedin.drelephant.analysis.HadoopAggregatedData;
import com.linkedin.drelephant.configurations.aggregator.AggregatorConfigurationData;
import com.linkedin.drelephant.mapreduce.data.MapReduceApplicationData;
import org.apache.log4j.Logger;


public class MapReduceMetricsAggregator implements HadoopMetricsAggregator {

  private static final Logger logger = Logger.getLogger(MapReduceMetricsAggregator.class);
  private static final String MAP_CONTAINER_CONFIG = "mapreduce.map.memory.mb";
  private static final String REDUCER_CONTAINER_CONFIG = "mapreduce.reduce.memory.mb";
  private static final String REDUCER_SLOW_START_CONFIG = "mapreduce.job.reduce.slowstart.completedmaps";

  private HadoopAggregatedData _hadoopAggregatedData = null;
  private TaskLevelAggregatedMetrics mapTasks;
  private TaskLevelAggregatedMetrics reduceTasks;

  private AggregatorConfigurationData _aggregatorConfigurationData;

  public MapReduceMetricsAggregator(AggregatorConfigurationData _aggregatorConfigurationData) {
    this._aggregatorConfigurationData = _aggregatorConfigurationData;
    _hadoopAggregatedData = new HadoopAggregatedData();
  }

  @Override
  public void aggregate(HadoopApplicationData hadoopData) {

    MapReduceApplicationData data = (MapReduceApplicationData) hadoopData;

    long mapTaskContainerSize = getMapContainerSize(data);
    long reduceTaskContainerSize = getReducerContainerSize(data);

    int reduceTaskSlowStartPercentage =
        (int) (Double.parseDouble(data.getConf().getProperty(REDUCER_SLOW_START_CONFIG)) * 100);


    //overwrite reduceTaskSlowStartPercentage to 100%. TODO: make use of the slow start percent
    reduceTaskSlowStartPercentage = 100;

    mapTasks = new TaskLevelAggregatedMetrics(data.getMapperData(), mapTaskContainerSize, data.getSubmitTime());

    long reduceIdealStartTime = mapTasks.getNthPercentileFinishTime(reduceTaskSlowStartPercentage);

    // Mappers list is empty
    if(reduceIdealStartTime == -1) {
      // ideal start time for reducer is infinite since it cannot start
      reduceIdealStartTime = Long.MAX_VALUE;
    }

    reduceTasks = new TaskLevelAggregatedMetrics(data.getReducerData(), reduceTaskContainerSize, reduceIdealStartTime);

{'fraction_non_alphanumeric': 0.06749496306245803, 'fraction_numerical': 0.006212222968435191, 'mean_word_length': 5.65586592178771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5396876', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1596, 'n_words': 421}