-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Improve the random read behavior in StressWorkerBench #18000
Merged
alluxio-bot
merged 23 commits into
Alluxio:main
from
voddle:StressWorkerBench-random-read
Sep 22, 2023
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2629fbe
new random read
voddle 1a22001
rand
voddle 560132a
check style
voddle e2de17e
add random sequence length to params
voddle c620551
new random
voddle 28234e5
runClass to exec class
voddle 66b8efd
StressBenchDefinition to exec class now
voddle f6876b2
StressBench Definition array list initialCapacity to 4
voddle c18e52a
split exec and class
voddle 932b52b
remove sequence
voddle 70ffb64
remove sequence
voddle 3a09004
reset env.go
voddle 56e6f61
format
voddle 4cb7ac9
move exec class change to another pr
voddle 63ebb45
remove mRandomIndex
voddle a13b83a
read min length
voddle efa774a
int to long
voddle 5835da7
check 2.1G now
voddle d894259
Update dora/stress/shell/src/main/java/alluxio/stress/cli/worker/Stre…
voddle 87c855f
Update dora/stress/shell/src/main/java/alluxio/stress/cli/worker/Stre…
voddle 24e5409
clean code
voddle d7c81f9
add description for random in length
voddle 36c8938
another nextLong
voddle 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 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
This file contains 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 |
---|---|---|
|
@@ -46,9 +46,9 @@ | |
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
|
@@ -67,13 +67,17 @@ public class StressWorkerBench extends AbstractStressBench<WorkerBenchTaskResult | |
|
||
private FileSystem[] mCachedFs; | ||
private Path[] mFilePaths; | ||
private Integer[] mOffsets; | ||
private Integer[] mLengths; | ||
private FileSystemContext mFsContext; | ||
|
||
/** generate random number in range [min, max] (include both min and max).*/ | ||
private Integer randomNumInRange(Random rand, int min, int max) { | ||
return rand.nextInt(max - min + 1) + min; | ||
/** | ||
* generate random number in range [min, max] (include both min and max). | ||
*/ | ||
private long randomNumInRange(long min, long max) { | ||
return ThreadLocalRandom.current().nextLong(min, max + 1) + min; | ||
} | ||
|
||
private long minLong(long a, long b) { | ||
return a > b ? a : b; | ||
} | ||
|
||
/** | ||
|
@@ -153,8 +157,6 @@ public void prepare() throws Exception { | |
// and offsets | ||
mFilePaths = new Path[numFiles]; | ||
// set random offsets and lengths if enabled | ||
mLengths = new Integer[numFiles]; | ||
mOffsets = new Integer[numFiles]; | ||
|
||
generateTestFilePaths(basePath); | ||
|
||
|
@@ -204,16 +206,10 @@ public void prepare() throws Exception { | |
* @param basePath base dir where the files should be prepared | ||
*/ | ||
public void generateTestFilePaths(Path basePath) throws IOException { | ||
int fileSize = (int) FormatUtils.parseSpaceSize(mParameters.mFileSize); | ||
int clusterSize = mBaseParameters.mClusterLimit; | ||
int threads = mParameters.mThreads; | ||
List<BlockWorkerInfo> workers = mFsContext.getCachedWorkers(); | ||
|
||
Random rand = new Random(); | ||
if (mParameters.mIsRandom) { | ||
rand = new Random(mParameters.mRandomSeed); | ||
} | ||
|
||
for (int i = 0; i < clusterSize; i++) { | ||
BlockWorkerInfo localWorker = workers.get(i); | ||
LOG.info("Building file paths for worker {}", localWorker); | ||
|
@@ -222,19 +218,6 @@ public void generateTestFilePaths(Path basePath) throws IOException { | |
|
||
int index = i * threads + j; | ||
mFilePaths[index] = filePath; | ||
|
||
// Continue init other aspects of the file read operation | ||
// TODO(jiacheng): do we want a new randomness for every read? | ||
if (mParameters.mIsRandom) { | ||
int randomMin = (int) FormatUtils.parseSpaceSize(mParameters.mRandomMinReadLength); | ||
int randomMax = (int) FormatUtils.parseSpaceSize(mParameters.mRandomMaxReadLength); | ||
mOffsets[index] = randomNumInRange(rand, 0, fileSize - 1 - randomMin); | ||
mLengths[index] = randomNumInRange(rand, randomMin, | ||
voddle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Integer.min(fileSize - mOffsets[i], randomMax)); | ||
} else { | ||
mOffsets[index] = 0; | ||
mLengths[index] = fileSize; | ||
} | ||
} | ||
} | ||
LOG.info("{} file paths generated", mFilePaths.length); | ||
|
@@ -356,6 +339,16 @@ public void validateParams() throws Exception { | |
throw new IllegalStateException(String.format("%s cannot be %s when %s option provided", | ||
FileSystemParameters.WRITE_TYPE_OPTION_NAME, WritePType.MUST_CACHE, "--free")); | ||
} | ||
|
||
if (FormatUtils.parseSpaceSize(mParameters.mRandomMaxReadLength) > Integer.MAX_VALUE) { | ||
throw new IllegalArgumentException("mRandomReadMaxLength cannot be larger than 2.1G"); | ||
} | ||
|
||
if (FormatUtils.parseSpaceSize(mParameters.mRandomMaxReadLength) | ||
< FormatUtils.parseSpaceSize(mParameters.mRandomMinReadLength)) { | ||
throw new IllegalArgumentException("mRandomReadMinLength must not larger" | ||
+ " than mRandomReadMaxLength"); | ||
} | ||
} | ||
|
||
private static final class BenchContext { | ||
|
@@ -402,6 +395,9 @@ private final class BenchThread implements Callable<Void> { | |
private final byte[] mBuffer; | ||
private final WorkerBenchTaskResult mResult; | ||
private final boolean mIsRandomRead; | ||
private final long mRandomMax; | ||
private final long mRandomMin; | ||
Comment on lines
+398
to
+399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. length should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since these two value will evaluated with long type |
||
private final long mFileSize; | ||
|
||
private FSDataInputStream mInStream; | ||
|
||
|
@@ -415,6 +411,9 @@ private BenchThread(BenchContext context, int targetFileIndex, FileSystem fs) { | |
mResult.setParameters(mParameters); | ||
mResult.setBaseParameters(mBaseParameters); | ||
mIsRandomRead = mParameters.mIsRandom; | ||
mRandomMin = FormatUtils.parseSpaceSize(mParameters.mRandomMinReadLength); | ||
mRandomMax = FormatUtils.parseSpaceSize(mParameters.mRandomMaxReadLength); | ||
mFileSize = FormatUtils.parseSpaceSize(mParameters.mFileSize); | ||
} | ||
|
||
@Override | ||
|
@@ -480,8 +479,6 @@ private void runInternal() throws Exception { | |
*/ | ||
private WorkerBenchDataPoint applyOperation() throws IOException { | ||
Path filePath = mFilePaths[mTargetFileIndex]; | ||
int offset = mOffsets[mTargetFileIndex]; | ||
int length = mLengths[mTargetFileIndex]; | ||
|
||
long startOperation = CommonUtils.getCurrentMs(); | ||
if (mInStream == null) { | ||
|
@@ -490,9 +487,12 @@ private WorkerBenchDataPoint applyOperation() throws IOException { | |
|
||
int bytesRead = 0; | ||
if (mIsRandomRead) { | ||
long offset = randomNumInRange(0, mFileSize - 1 - mRandomMin); | ||
long lengthMax = Math.min(mFileSize - offset, mRandomMax); | ||
long length = randomNumInRange(mRandomMin, lengthMax); | ||
while (length > 0) { | ||
int actualReadLength = mInStream | ||
.read(offset, mBuffer, 0, mBuffer.length); | ||
.read(offset, mBuffer, 0, (int) minLong(mBuffer.length, length)); | ||
if (actualReadLength < 0) { | ||
closeInStream(); | ||
break; | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note we are using thread local random here, so does the
--seed
parameter still take effect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we no longer need this param