Skip to content

Commit

Permalink
Merge pull request brianfrankcooper#7 from achille/master
Browse files Browse the repository at this point in the history
Allow for generation of compressible data of varying compressibility
  • Loading branch information
asya999 committed Nov 12, 2015
2 parents dc28f89 + 4b68eeb commit 8bbcb5c
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public class MongoDbClient extends DB {

private static InsertOptions io = new InsertOptions().continueOnError(true);

/** Measure of how compressible the data is, compressibility=10 means the data can compress tenfold.
* The default is 1, which is uncompressible */
private static float compressibility = (float) 1.0;

/**
* Initialize any state for this DB.
* Called once per DB instance; there is one DB instance per client thread.
Expand All @@ -107,6 +111,9 @@ public void init() throws DBException {
final String batchSizeString = props.getProperty("batchsize", "1");
BATCHSIZE = Integer.parseInt(batchSizeString);

final String compressibilityString = props.getProperty("compressibility", "1");
this.compressibility = Float.parseFloat(compressibilityString);

// Set connectionpool to size of ycsb thread pool
final String maxConnections = props.getProperty("threadcount", "100");

Expand Down Expand Up @@ -210,6 +217,16 @@ public void cleanup() throws DBException {
}
}

private byte[] applyCompressibility(byte[] data){
long string_length = data.length;

long random_string_length = (int) Math.round(string_length /compressibility);
long compressible_len = string_length - random_string_length;
for(int i=0;i<compressible_len;i++)
data[i] = 0;
return data;
}

/**
* Delete a record from the database.
*
Expand Down Expand Up @@ -247,7 +264,8 @@ public int insert(String table, String key,
DBCollection collection = db[serverCounter++%db.length].getCollection(table);
DBObject r = new BasicDBObject().append("_id", key);
for (String k : values.keySet()) {
r.put(k, values.get(k).toArray());
byte[] data = values.get(k).toArray();
r.put(k,applyCompressibility(data));
}
if (BATCHSIZE == 1 ) {
try {
Expand Down Expand Up @@ -349,8 +367,8 @@ public int update(String table, String key,
Iterator<String> keys = values.keySet().iterator();
while (keys.hasNext()) {
String tmpKey = keys.next();
fieldsToSet.put(tmpKey, values.get(tmpKey).toArray());

byte[] data = values.get(tmpKey).toArray();
fieldsToSet.put(tmpKey, applyCompressibility(data));
}
u.put("$set", fieldsToSet);
WriteResult res = collection.update(q, u);
Expand Down

0 comments on commit 8bbcb5c

Please sign in to comment.