Skip to content

Commit 7bccbc6

Browse files
committed
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
2 parents fac4f92 + 8556d42 commit 7bccbc6

File tree

7 files changed

+122
-11
lines changed

7 files changed

+122
-11
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*.class
22

33
# Package Files #
4+
/0.3.0.10
5+
/0.3.0.8
6+
/0.3.0.9
7+
/META-INF
8+
/OSGI-INF

dev/cosbench-driver/src/com/intel/cosbench/driver/operator/FileWriter.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ protected void init(String division, Config config) {
6060
contPicker.init(division, config);
6161
String filepath = config.get("files");
6262
folder = new File(filepath);
63+
if (!folder.exists()) {
64+
throw new RuntimeException("Folder " + filepath + " does not exist.");
65+
}
6366
listOfFiles = folder.listFiles();
64-
System.out.println("listOfFiles.length: " + listOfFiles.length);
6567
String range = "(1," + listOfFiles.length + ")";
66-
System.out.println("initialising filePicker, range: " + range);
6768
filePicker.init(range, config);
6869
}
6970

@@ -79,13 +80,10 @@ protected void operate(int idx, int all, Session session) {
7980
doLogErr(session.getLogger(), "fail to perform file filewrite operation, can not read " + folder.getAbsolutePath());
8081
sample = new Sample(new Date(), OP_TYPE, false);
8182
}
82-
83-
// looks kinda ugly, but does make sense…
84-
8583
Random random = session.getRandom();
8684
String containerName = contPicker.pickContName(random, idx, all);
87-
88-
// as I said, the 1 from init() is being removed here
85+
86+
// as we index arrays starting from 0, we need to remove 1 here
8987
Integer rand = (filePicker.pickObjKey(random) - 1);
9088
String filename = null;
9189
try {
@@ -103,10 +101,8 @@ protected void operate(int idx, int all, Session session) {
103101
try {
104102
FileInputStream fis = new FileInputStream(listOfFiles[rand]);
105103
sample = doWrite(fis, listOfFiles[rand].length(), containerName, filename, config, session);
106-
System.out.println("rand: " + rand + " filename: " + filename + " container " + containerName);
107104
} catch (FileNotFoundException e) {
108105
doLogErr(session.getLogger(), "fail to perform file Write operation", e);
109-
System.out.println("fail to perform file Write operation " + e.getMessage());
110106
sample = new Sample(new Date(), OP_TYPE, false);
111107
}
112108
session.getListener().onSampleCreated(sample);

dev/cosbench-driver/src/com/intel/cosbench/driver/random/Generators.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ private static IntGenerator getIntGenerator(String pattern) {
4545
return generator;
4646
if ((generator = RangeIntGenerator.parse(pattern)) != null)
4747
return generator;
48+
if ((generator = SequentialIntGenerator.parse(pattern)) != null)
49+
return generator;
4850
String msg = "unrecognized distribution: " + pattern;
4951
throw new ConfigException(msg);
5052
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
3+
Copyright 2013 Intel Corporation, All Rights Reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package com.intel.cosbench.driver.random;
19+
20+
import java.util.Random;
21+
import java.util.concurrent.atomic.AtomicLong;
22+
23+
import org.apache.commons.lang.StringUtils;
24+
25+
import com.intel.cosbench.config.ConfigException;
26+
27+
/**
28+
* This class supplies a thread-save int generator that returns ints from lower to upper, and then restarts at lower
29+
* again.
30+
*
31+
*
32+
* @author Niklas Goerke niklas974@github
33+
*
34+
*/
35+
class SequentialIntGenerator implements IntGenerator {
36+
37+
private int lower;
38+
private int range;
39+
private AtomicLong cursor;
40+
41+
public SequentialIntGenerator(int lower, int upper) {
42+
if (lower <= 0 || upper <= 0 || lower > upper)
43+
throw new IllegalArgumentException();
44+
this.lower = lower;
45+
this.range = upper - lower + 1; // plus one, because we want upper and lower
46+
this.cursor = new AtomicLong();
47+
this.cursor.set(-1);
48+
}
49+
50+
@Override
51+
public int next(Random random) {
52+
return (int) (lower + (cursor.incrementAndGet() % range));
53+
}
54+
55+
@Override
56+
public int next(Random random, int idx, int all) {
57+
return next(random);
58+
59+
}
60+
61+
public static SequentialIntGenerator parse(String pattern) {
62+
if (!StringUtils.startsWith(pattern, "s(")) {
63+
return null;
64+
} else {
65+
try {
66+
return tryParse(pattern);
67+
} catch (NullPointerException e) {
68+
String msg = "illegal iteration pattern: " + pattern;
69+
throw new ConfigException(msg);
70+
}
71+
}
72+
}
73+
74+
private static SequentialIntGenerator tryParse(String pattern) {
75+
pattern = StringUtils.substringBetween(pattern, "(", ")");
76+
String[] args = StringUtils.split(pattern, ",");
77+
int lower = Integer.parseInt(args[0]);
78+
int upper = Integer.parseInt(args[1]);
79+
return new SequentialIntGenerator(lower, upper);
80+
}
81+
}

dev/cosbench-driver/src/com/intel/cosbench/driver/util/FilePicker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public FilePicker() {
3939

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

4545
public int pickObjKey(Random random) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is a short explanation of how the config for the filewriter works:
2+
3+
<work name="filewrite" workers="4" totalOps="104">
4+
As known from other work configs.
5+
Notice: 104 ops will be done, if there are only 100 files given, 4 pretty much random files will be written twice.
6+
7+
8+
9+
<operation type="filewrite" config="cprefix=cont;containers=u(1,2);fileselection=s;files=/tmp/testfiles/" />
10+
type should be filewrite, so that the filewriter is being used.
11+
12+
For the config= part:
13+
14+
cprefix= The Container Prefix, as known from other configs
15+
containers= The identifier for the container, as known from other configs
16+
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.
17+
Notice: s ist suggested, as it guarantees thread-safe reading of all the files (if totalOps >= amount of files).
18+
files= The absoulte path to the folder containing the files which should be written.
19+
Notice: If you run one or more drivers on different hosts, the files must accessible on that very machine.
20+
21+
22+
23+
</work>
24+
As known.

release/conf/workload-config.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
<work name="main" workers="8" runtime="300">
3333
<operation type="read" ratio="80" config="containers=u(1,32);objects=u(1,50)" />
3434
<operation type="write" ratio="20" config="containers=u(1,32);objects=u(51,100);sizes=c(64)KB" />
35-
</work>
35+
</work>
36+
<work name="filewrite" workers="8" totalOps="80">
37+
<operation type="filewrite" config="cprefix=radtest;containers=u(1,2);fileselection=s;files=/tmp/testfiles/" />
38+
</work>
3639
</workstage>
3740

3841
<!-- Clean Up Stage -->

0 commit comments

Comments
 (0)