Skip to content
Browse files

better usage threads

  • Loading branch information...
1 parent 5a5d351 commit 114a217b418cc694f18bca7f3288f9eb061c3fab zznate committed Jan 23, 2012
View
63 src/main/java/com/riptano/cassandra/stress/BucketingCounterSpreadCommand.java
@@ -8,7 +8,10 @@
import me.prettyprint.hector.api.beans.HCounterColumn;
import me.prettyprint.hector.api.factory.HFactory;
import me.prettyprint.hector.api.mutation.Mutator;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Testing a scenario where HH *might* cause counter replication to loop
@@ -18,6 +21,8 @@
*/
public class BucketingCounterSpreadCommand extends StressCommand {
+ private static Logger log = LoggerFactory.getLogger(BucketingCounterSpreadCommand.class);
+
private static final long MINS_IN_YEAR = 525600L;
private static final long MINS_IN_MONTH = 43800L;
// more rounded version from 60 mins/hour * 7 days *
@@ -31,66 +36,70 @@ public BucketingCounterSpreadCommand(int startKey, CommandArgs commandArgs, Comm
@Override
public Void call() throws Exception {
-
+ log.info("In call on counter insert");
Mutator<String> counterMutator =
HFactory.createMutator(commandArgs.keyspace, StringSerializer.get(), new BatchSizeHint(500,2));
- int x=0;
- for(; x < MINS_IN_YEAR; x++) {
+ int rows = 0;
+ for (;rows < commandArgs.getKeysPerThread(); rows++) {
+
+ log.info("current count {}", rows);
// build all bucket - 1 row
- new CounterColumnBuilder(BucketType.ALL,x)
+ new CounterColumnBuilder(BucketType.ALL,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// 12 rows
- new CounterColumnBuilder(BucketType.MONTH,x)
+ new CounterColumnBuilder(BucketType.MONTH,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// 52 rows
- new CounterColumnBuilder(BucketType.WEEK,x)
+ new CounterColumnBuilder(BucketType.WEEK,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// 365 rows
- new CounterColumnBuilder(BucketType.DAY,x)
+ new CounterColumnBuilder(BucketType.DAY,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// 8760 rows
- new CounterColumnBuilder(BucketType.HOUR,x)
+ new CounterColumnBuilder(BucketType.HOUR,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// 525600 rows
- new CounterColumnBuilder(BucketType.MINUTE,x)
+ new CounterColumnBuilder(BucketType.MINUTE,rows)
.applyClicks(1)
.applyView(1)
.addToMutation(counterMutator);
// TODO test≈ auto-batching here
- if ( x % 500 == 0) {
- executeMutator(counterMutator, x);
+ if ( rows % 500 == 0) {
+ log.info("mutator fired on 500");
+ executeMutator(counterMutator, rows);
}
}
- executeMutator(counterMutator,x);
-
+ executeMutator(counterMutator,0);
+ commandRunner.doneSignal.countDown();
return null;
}
- static class CounterColumnBuilder {
+ class CounterColumnBuilder {
private HCounterColumn<String> clicksCounter;
private HCounterColumn<String> viewsCounter;
private final String keyString;
- CounterColumnBuilder(BucketType bucketType, long minInYear) {
- this.keyString = bucketType.formatDate(minInYear * 60 * 1000);
+ CounterColumnBuilder(BucketType bucketType, long rowNumber) {
+ this.keyString = bucketType.formatDate(System.currentTimeMillis() + (rowNumber * 60 * 1000));
+ log.info("using keyString {}",keyString);
}
CounterColumnBuilder applyClicks(long clicks) {
@@ -104,8 +113,8 @@ CounterColumnBuilder applyView(long views) {
}
void addToMutation(Mutator<String> mutator) {
- mutator.addCounter(keyString,"CounterCf",clicksCounter);
mutator.addCounter(keyString,"CounterCf",viewsCounter);
+ mutator.addCounter(keyString,"CounterCf",clicksCounter);
}
}
@@ -115,16 +124,19 @@ void addToMutation(Mutator<String> mutator) {
*/
enum BucketType {
ALL("__ALL__"),
- MONTH("YYYY_MM"),
- WEEK("YYYY_MM_w"),
- DAY("YYYY_MM_dd"),
- HOUR("YYYY_MM_dd_hh"),
- MINUTE("YYYY_MM_dd_hh_mm");
+ MONTH("yyyy_MM"),
+ WEEK("yyyy_MM_w"),
+ DAY("yyyy_MM_dd"),
+ HOUR("yyyy_MM_dd_hh"),
+ MINUTE("yyyy_MM_dd_hh_mm");
- final FastDateFormat formatter;
+ FastDateFormat formatter;
BucketType(String format) {
- this.formatter = FastDateFormat.getInstance(format, TimeZone.getTimeZone("GMT"));
+ if ( !StringUtils.equals(format,"__ALL__")) {
+ this.formatter = FastDateFormat.getInstance(format, TimeZone.getTimeZone("GMT"));
+ }
+
}
/**
@@ -142,6 +154,9 @@ public String formatDate(long date) {
@Override
public String toString() {
+ if ( formatter == null ) {
+ return "__ALL__";
+ }
return formatter.getPattern();
}
}
View
2 src/main/java/com/riptano/cassandra/stress/CommandRunner.java
@@ -89,7 +89,7 @@ private StressCommand getCommandInstance(int startKeyArg, CommandArgs commandArg
return new MultigetSliceCommand(startKey, commandArgs, commandRunner);
case VERIFY_LAST_INSERT:
return new VerifyLastInsertCommand(startKey, commandArgs, commandRunner);
- case COUNTER_SPREAD:
+ case COUNTERSPREAD:
return new BucketingCounterSpreadCommand(startKey, commandArgs, commandRunner);
};
return new InsertCommand(startKey, commandArgs, commandRunner);

0 comments on commit 114a217

Please sign in to comment.
Something went wrong with that request. Please try again.