Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: dev/cosbench-driver/src/com/intel/cosbench/driver/operator/FileWriter.java dev/cosbench-driver/src/com/intel/cosbench/driver/util/FilePicker.java
- Loading branch information
Showing
7 changed files
with
122 additions
and
11 deletions.
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,8 @@ | |||
*.class | *.class | ||
|
|
||
# Package Files # | # Package Files # | ||
/0.3.0.10 | |||
/0.3.0.8 | |||
/0.3.0.9 | |||
/META-INF | |||
/OSGI-INF |
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
81 changes: 81 additions & 0 deletions
81
dev/cosbench-driver/src/com/intel/cosbench/driver/random/SequentialIntGenerator.java
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,81 @@ | |||
/** | |||
Copyright 2013 Intel Corporation, All Rights Reserved. | |||
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.intel.cosbench.driver.random; | |||
|
|||
import java.util.Random; | |||
import java.util.concurrent.atomic.AtomicLong; | |||
|
|||
import org.apache.commons.lang.StringUtils; | |||
|
|||
import com.intel.cosbench.config.ConfigException; | |||
|
|||
/** | |||
* This class supplies a thread-save int generator that returns ints from lower to upper, and then restarts at lower | |||
* again. | |||
* | |||
* | |||
* @author Niklas Goerke niklas974@github | |||
* | |||
*/ | |||
class SequentialIntGenerator implements IntGenerator { | |||
|
|||
private int lower; | |||
private int range; | |||
private AtomicLong cursor; | |||
|
|||
public SequentialIntGenerator(int lower, int upper) { | |||
if (lower <= 0 || upper <= 0 || lower > upper) | |||
throw new IllegalArgumentException(); | |||
this.lower = lower; | |||
this.range = upper - lower + 1; // plus one, because we want upper and lower | |||
this.cursor = new AtomicLong(); | |||
this.cursor.set(-1); | |||
} | |||
|
|||
@Override | |||
public int next(Random random) { | |||
return (int) (lower + (cursor.incrementAndGet() % range)); | |||
} | |||
|
|||
@Override | |||
public int next(Random random, int idx, int all) { | |||
return next(random); | |||
|
|||
} | |||
|
|||
public static SequentialIntGenerator parse(String pattern) { | |||
if (!StringUtils.startsWith(pattern, "s(")) { | |||
return null; | |||
} else { | |||
try { | |||
return tryParse(pattern); | |||
} catch (NullPointerException e) { | |||
String msg = "illegal iteration pattern: " + pattern; | |||
throw new ConfigException(msg); | |||
} | |||
} | |||
} | |||
|
|||
private static SequentialIntGenerator tryParse(String pattern) { | |||
pattern = StringUtils.substringBetween(pattern, "(", ")"); | |||
String[] args = StringUtils.split(pattern, ","); | |||
int lower = Integer.parseInt(args[0]); | |||
int upper = Integer.parseInt(args[1]); | |||
return new SequentialIntGenerator(lower, upper); | |||
} | |||
} |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
This is a short explanation of how the config for the filewriter works: | |||
|
|||
<work name="filewrite" workers="4" totalOps="104"> | |||
As known from other work configs. | |||
Notice: 104 ops will be done, if there are only 100 files given, 4 pretty much random files will be written twice. | |||
|
|||
|
|||
|
|||
<operation type="filewrite" config="cprefix=cont;containers=u(1,2);fileselection=s;files=/tmp/testfiles/" /> | |||
type should be filewrite, so that the filewriter is being used. | |||
|
|||
For the config= part: | |||
|
|||
cprefix= The Container Prefix, as known from other configs | |||
containers= The identifier for the container, as known from other configs | |||
fileselection= The Selector to be used to generate the ints which will then be used to distinguish between the files on the disk. Only the letter needs to be given, any range given will be ignored and replaced with the amount of files. | |||
Notice: s ist suggested, as it guarantees thread-safe reading of all the files (if totalOps >= amount of files). | |||
files= The absoulte path to the folder containing the files which should be written. | |||
Notice: If you run one or more drivers on different hosts, the files must accessible on that very machine. | |||
|
|||
|
|||
|
|||
</work> | |||
As known. |
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