-
Notifications
You must be signed in to change notification settings - Fork 33
Create a new TimedInputFormat with the time-based virtual split logic used by CreateFileMapper. This allows for future workloads to easily also have time-based mapper logic. #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xkrogen
merged 1 commit into
linkedin:master
from
xkrogen:ekrogen-generic-timedinputformat
Feb 13, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...r-workload/src/main/java/com/linkedin/dynamometer/workloadgenerator/TimedInputFormat.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * Copyright 2019 LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.dynamometer.workloadgenerator; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.LongWritable; | ||
| import org.apache.hadoop.io.NullWritable; | ||
| import org.apache.hadoop.mapreduce.InputFormat; | ||
| import org.apache.hadoop.mapreduce.InputSplit; | ||
| import org.apache.hadoop.mapreduce.JobContext; | ||
| import org.apache.hadoop.mapreduce.RecordReader; | ||
| import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
|
|
||
|
|
||
| /** | ||
| * An {@link InputFormat} which is time-based. Starts at some timestamp (specified by the | ||
| * {@value WorkloadDriver#START_TIMESTAMP_MS configuration) and runs for a time specified by the | ||
| * {@value DURATION_KEY} configuration. Spawns {@value NUM_MAPPERS_KEY} mappers. Both {@value DURATION_KEY} | ||
| * and {@value NUM_MAPPERS_KEY} are required. | ||
| * | ||
| * <p/>The values returned as the key by this InputFormat are just a sequential counter. | ||
| */ | ||
| public class TimedInputFormat extends InputFormat<LongWritable, NullWritable> { | ||
|
|
||
| public static final String DURATION_KEY = "timedinput.duration"; | ||
| public static final String NUM_MAPPERS_KEY = "timedinput.num-mappers"; | ||
|
|
||
| // Number of splits = Number of mappers. Creates fakeSplits to launch | ||
| // the required number of mappers | ||
| @Override | ||
| public List<InputSplit> getSplits(JobContext job) { | ||
| Configuration conf = job.getConfiguration(); | ||
| int numMappers = conf.getInt(NUM_MAPPERS_KEY, -1); | ||
| List<InputSplit> splits = new ArrayList<>(); | ||
| for (int i = 0; i < numMappers; i++) { | ||
| splits.add(new VirtualInputSplit()); | ||
| } | ||
| return splits; | ||
| } | ||
|
|
||
| @Override | ||
| public RecordReader<LongWritable, NullWritable> createRecordReader(InputSplit split, TaskAttemptContext context) { | ||
| return new TimedRecordReader(); | ||
| } | ||
|
|
||
| public static List<String> getConfigDescriptions() { | ||
| return Lists.newArrayList( | ||
| NUM_MAPPERS_KEY + " (required): Number of mappers to launch.", | ||
| DURATION_KEY + " (required): Number of minutes to induce workload for." | ||
| ); | ||
| } | ||
|
|
||
| public static boolean verifyConfigurations(Configuration conf) { | ||
| return conf.getInt(NUM_MAPPERS_KEY, -1) != -1 | ||
| && conf.getTimeDuration(DURATION_KEY, -1, TimeUnit.MILLISECONDS) != -1; | ||
| } | ||
|
|
||
| } |
74 changes: 74 additions & 0 deletions
74
...-workload/src/main/java/com/linkedin/dynamometer/workloadgenerator/TimedRecordReader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * Copyright 2019 LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license. | ||
| * See LICENSE in the project root for license information. | ||
| */ | ||
| package com.linkedin.dynamometer.workloadgenerator; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.io.LongWritable; | ||
| import org.apache.hadoop.io.NullWritable; | ||
| import org.apache.hadoop.mapreduce.InputSplit; | ||
| import org.apache.hadoop.mapreduce.RecordReader; | ||
| import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static com.linkedin.dynamometer.workloadgenerator.TimedInputFormat.DURATION_KEY; | ||
|
|
||
|
|
||
| /** | ||
| * A {@link RecordReader} to support {@link TimedInputFormat}. Waits to emit the first | ||
| * value until the start time has been reached, then continually emits values | ||
| * (a sequential counter) until the end of the duration has been reached. | ||
| */ | ||
| public class TimedRecordReader extends RecordReader<LongWritable, NullWritable> { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TimedRecordReader.class); | ||
|
|
||
| private LongWritable nextValue; | ||
| private long durationMs; | ||
| private long startTimestampMs; | ||
|
|
||
| @Override | ||
| public void initialize(InputSplit split, TaskAttemptContext context) { | ||
| Configuration conf = context.getConfiguration(); | ||
| durationMs = conf.getTimeDuration(DURATION_KEY, -1, TimeUnit.MILLISECONDS); | ||
| startTimestampMs = conf.getLong(WorkloadDriver.START_TIMESTAMP_MS, 0); | ||
| nextValue = new LongWritable(0); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean nextKeyValue() throws InterruptedException { | ||
| long elapsed = System.currentTimeMillis() - startTimestampMs; | ||
| LOG.info("Starting at " + startTimestampMs + " ms"); | ||
| if (elapsed < 0) { | ||
| LOG.info("Sleeping for " + (-1 * elapsed) + " ms"); | ||
| Thread.sleep(-1 * elapsed); | ||
| } else if (elapsed > durationMs) { | ||
| return false; | ||
| } | ||
| nextValue.set(nextValue.get() + 1L); | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public LongWritable getCurrentKey() { | ||
| return nextValue; | ||
| } | ||
|
|
||
| @Override | ||
| public NullWritable getCurrentValue() { | ||
| return NullWritable.get(); | ||
| } | ||
|
|
||
| @Override | ||
| public float getProgress() { | ||
| return (System.currentTimeMillis() - startTimestampMs) / ((float) durationMs); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| // do Nothing | ||
| } | ||
| } |
40 changes: 0 additions & 40 deletions
40
...workload/src/main/java/com/linkedin/dynamometer/workloadgenerator/VirtualInputFormat.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.