Permalink
Browse files

Merge branch 'filewriter'

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...
2 parents fac4f92 + 8556d42 commit 7bccbc62b833830f8b3ec5148a03dffc9bb3419b @Niklas974 Niklas974 committed Jun 17, 2013
View
5 .gitignore
@@ -1,3 +1,8 @@
*.class
# Package Files #
+/0.3.0.10
+/0.3.0.8
+/0.3.0.9
+/META-INF
+/OSGI-INF
View
14 dev/cosbench-driver/src/com/intel/cosbench/driver/operator/FileWriter.java
@@ -60,10 +60,11 @@ protected void init(String division, Config config) {
contPicker.init(division, config);
String filepath = config.get("files");
folder = new File(filepath);
+ if (!folder.exists()) {
+ throw new RuntimeException("Folder " + filepath + " does not exist.");
+ }
listOfFiles = folder.listFiles();
- System.out.println("listOfFiles.length: " + listOfFiles.length);
String range = "(1," + listOfFiles.length + ")";
- System.out.println("initialising filePicker, range: " + range);
filePicker.init(range, config);
}
@@ -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());
sample = new Sample(new Date(), OP_TYPE, false);
}
-
- // looks kinda ugly, but does make sense…
-
Random random = session.getRandom();
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);
String filename = null;
try {
@@ -103,10 +101,8 @@ protected void operate(int idx, int all, Session session) {
try {
FileInputStream fis = new FileInputStream(listOfFiles[rand]);
sample = doWrite(fis, listOfFiles[rand].length(), containerName, filename, config, session);
- System.out.println("rand: " + rand + " filename: " + filename + " container " + containerName);
} catch (FileNotFoundException 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);
}
session.getListener().onSampleCreated(sample);
View
2 dev/cosbench-driver/src/com/intel/cosbench/driver/random/Generators.java
@@ -45,6 +45,8 @@ private static IntGenerator getIntGenerator(String pattern) {
return generator;
if ((generator = RangeIntGenerator.parse(pattern)) != null)
return generator;
+ if ((generator = SequentialIntGenerator.parse(pattern)) != null)
+ return generator;
String msg = "unrecognized distribution: " + pattern;
throw new ConfigException(msg);
}
View
81 dev/cosbench-driver/src/com/intel/cosbench/driver/random/SequentialIntGenerator.java
@@ -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);
+ }
+}
View
2 dev/cosbench-driver/src/com/intel/cosbench/driver/util/FilePicker.java
@@ -39,7 +39,7 @@ public FilePicker() {
public void init(String range, Config config) {
String selector = config.get("fileselection").substring(0, 1);
- objNmGen = Generators.getNameGenerator(selector + range, "", "");
+ this.objNmGen = Generators.getNameGenerator(selector + range, "", "");
}
public int pickObjKey(Random random) {
View
24 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.
View
5 release/conf/workload-config.xml
@@ -32,7 +32,10 @@
<work name="main" workers="8" runtime="300">
<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" />
- </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>
<!-- Clean Up Stage -->

0 comments on commit 7bccbc6

Please sign in to comment.