Skip to content

Commit

Permalink
Merge branch 'filewriter'
Browse files Browse the repository at this point in the history
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
Niklas974 committed Jun 17, 2013
2 parents fac4f92 + 8556d42 commit 7bccbc6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -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
Expand Up @@ -60,10 +60,11 @@ protected void init(String division, Config config) {
contPicker.init(division, config); contPicker.init(division, config);
String filepath = config.get("files"); String filepath = config.get("files");
folder = new File(filepath); folder = new File(filepath);
if (!folder.exists()) {
throw new RuntimeException("Folder " + filepath + " does not exist.");
}
listOfFiles = folder.listFiles(); listOfFiles = folder.listFiles();
System.out.println("listOfFiles.length: " + listOfFiles.length);
String range = "(1," + listOfFiles.length + ")"; String range = "(1," + listOfFiles.length + ")";
System.out.println("initialising filePicker, range: " + range);
filePicker.init(range, config); filePicker.init(range, config);
} }


Expand All @@ -79,13 +80,10 @@ protected void operate(int idx, int all, Session session) {
doLogErr(session.getLogger(), "fail to perform file filewrite operation, can not read " + folder.getAbsolutePath()); doLogErr(session.getLogger(), "fail to perform file filewrite operation, can not read " + folder.getAbsolutePath());
sample = new Sample(new Date(), OP_TYPE, false); sample = new Sample(new Date(), OP_TYPE, false);
} }

// looks kinda ugly, but does make sense…

Random random = session.getRandom(); Random random = session.getRandom();
String containerName = contPicker.pickContName(random, idx, all); String containerName = contPicker.pickContName(random, idx, all);

// as I said, the 1 from init() is being removed here // as we index arrays starting from 0, we need to remove 1 here
Integer rand = (filePicker.pickObjKey(random) - 1); Integer rand = (filePicker.pickObjKey(random) - 1);
String filename = null; String filename = null;
try { try {
Expand All @@ -103,10 +101,8 @@ protected void operate(int idx, int all, Session session) {
try { try {
FileInputStream fis = new FileInputStream(listOfFiles[rand]); FileInputStream fis = new FileInputStream(listOfFiles[rand]);
sample = doWrite(fis, listOfFiles[rand].length(), containerName, filename, config, session); sample = doWrite(fis, listOfFiles[rand].length(), containerName, filename, config, session);
System.out.println("rand: " + rand + " filename: " + filename + " container " + containerName);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
doLogErr(session.getLogger(), "fail to perform file Write operation", e); doLogErr(session.getLogger(), "fail to perform file Write operation", e);
System.out.println("fail to perform file Write operation " + e.getMessage());
sample = new Sample(new Date(), OP_TYPE, false); sample = new Sample(new Date(), OP_TYPE, false);
} }
session.getListener().onSampleCreated(sample); session.getListener().onSampleCreated(sample);
Expand Down
Expand Up @@ -45,6 +45,8 @@ private static IntGenerator getIntGenerator(String pattern) {
return generator; return generator;
if ((generator = RangeIntGenerator.parse(pattern)) != null) if ((generator = RangeIntGenerator.parse(pattern)) != null)
return generator; return generator;
if ((generator = SequentialIntGenerator.parse(pattern)) != null)
return generator;
String msg = "unrecognized distribution: " + pattern; String msg = "unrecognized distribution: " + pattern;
throw new ConfigException(msg); throw new ConfigException(msg);
} }
Expand Down
@@ -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);
}
}
Expand Up @@ -39,7 +39,7 @@ public FilePicker() {


public void init(String range, Config config) { public void init(String range, Config config) {
String selector = config.get("fileselection").substring(0, 1); String selector = config.get("fileselection").substring(0, 1);
objNmGen = Generators.getNameGenerator(selector + range, "", ""); this.objNmGen = Generators.getNameGenerator(selector + range, "", "");
} }


public int pickObjKey(Random random) { public int pickObjKey(Random random) {
Expand Down
24 changes: 24 additions & 0 deletions release/conf/filewriter-config-explanation.txt
@@ -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.
5 changes: 4 additions & 1 deletion release/conf/workload-config.xml
Expand Up @@ -32,7 +32,10 @@
<work name="main" workers="8" runtime="300"> <work name="main" workers="8" runtime="300">
<operation type="read" ratio="80" config="containers=u(1,32);objects=u(1,50)" /> <operation type="read" ratio="80" config="containers=u(1,32);objects=u(1,50)" />
<operation type="write" ratio="20" config="containers=u(1,32);objects=u(51,100);sizes=c(64)KB" /> <operation type="write" ratio="20" config="containers=u(1,32);objects=u(51,100);sizes=c(64)KB" />
</work> </work>
<work name="filewrite" workers="8" totalOps="80">
<operation type="filewrite" config="cprefix=radtest;containers=u(1,2);fileselection=s;files=/tmp/testfiles/" />
</work>
</workstage> </workstage>


<!-- Clean Up Stage --> <!-- Clean Up Stage -->
Expand Down

0 comments on commit 7bccbc6

Please sign in to comment.