Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

better usage threads

  • Loading branch information...
commit 114a217b418cc694f18bca7f3288f9eb061c3fab 1 parent 5a5d351
zznate authored
63 src/main/java/com/riptano/cassandra/stress/BucketingCounterSpreadCommand.java
@@ -8,7 +8,10 @@
8 8 import me.prettyprint.hector.api.beans.HCounterColumn;
9 9 import me.prettyprint.hector.api.factory.HFactory;
10 10 import me.prettyprint.hector.api.mutation.Mutator;
  11 +import org.apache.commons.lang.StringUtils;
11 12 import org.apache.commons.lang.time.FastDateFormat;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
12 15
13 16 /**
14 17 * Testing a scenario where HH *might* cause counter replication to loop
@@ -18,6 +21,8 @@
18 21 */
19 22 public class BucketingCounterSpreadCommand extends StressCommand {
20 23
  24 + private static Logger log = LoggerFactory.getLogger(BucketingCounterSpreadCommand.class);
  25 +
21 26 private static final long MINS_IN_YEAR = 525600L;
22 27 private static final long MINS_IN_MONTH = 43800L;
23 28 // more rounded version from 60 mins/hour * 7 days *
@@ -31,66 +36,70 @@ public BucketingCounterSpreadCommand(int startKey, CommandArgs commandArgs, Comm
31 36
32 37 @Override
33 38 public Void call() throws Exception {
34   -
  39 + log.info("In call on counter insert");
35 40 Mutator<String> counterMutator =
36 41 HFactory.createMutator(commandArgs.keyspace, StringSerializer.get(), new BatchSizeHint(500,2));
37   - int x=0;
38   - for(; x < MINS_IN_YEAR; x++) {
  42 + int rows = 0;
  43 + for (;rows < commandArgs.getKeysPerThread(); rows++) {
  44 +
  45 + log.info("current count {}", rows);
39 46 // build all bucket - 1 row
40   - new CounterColumnBuilder(BucketType.ALL,x)
  47 + new CounterColumnBuilder(BucketType.ALL,rows)
41 48 .applyClicks(1)
42 49 .applyView(1)
43 50 .addToMutation(counterMutator);
44 51
45 52 // 12 rows
46   - new CounterColumnBuilder(BucketType.MONTH,x)
  53 + new CounterColumnBuilder(BucketType.MONTH,rows)
47 54 .applyClicks(1)
48 55 .applyView(1)
49 56 .addToMutation(counterMutator);
50 57
51 58 // 52 rows
52   - new CounterColumnBuilder(BucketType.WEEK,x)
  59 + new CounterColumnBuilder(BucketType.WEEK,rows)
53 60 .applyClicks(1)
54 61 .applyView(1)
55 62 .addToMutation(counterMutator);
56 63
57 64 // 365 rows
58   - new CounterColumnBuilder(BucketType.DAY,x)
  65 + new CounterColumnBuilder(BucketType.DAY,rows)
59 66 .applyClicks(1)
60 67 .applyView(1)
61 68 .addToMutation(counterMutator);
62 69
63 70 // 8760 rows
64   - new CounterColumnBuilder(BucketType.HOUR,x)
  71 + new CounterColumnBuilder(BucketType.HOUR,rows)
65 72 .applyClicks(1)
66 73 .applyView(1)
67 74 .addToMutation(counterMutator);
68 75
69 76 // 525600 rows
70   - new CounterColumnBuilder(BucketType.MINUTE,x)
  77 + new CounterColumnBuilder(BucketType.MINUTE,rows)
71 78 .applyClicks(1)
72 79 .applyView(1)
73 80 .addToMutation(counterMutator);
74 81
75 82 // TODO test≈ auto-batching here
76   - if ( x % 500 == 0) {
77   - executeMutator(counterMutator, x);
  83 + if ( rows % 500 == 0) {
  84 + log.info("mutator fired on 500");
  85 + executeMutator(counterMutator, rows);
78 86 }
79 87 }
80   - executeMutator(counterMutator,x);
81   -
  88 + executeMutator(counterMutator,0);
  89 + commandRunner.doneSignal.countDown();
82 90
83 91 return null;
84 92 }
85 93
86 94
87   - static class CounterColumnBuilder {
  95 + class CounterColumnBuilder {
88 96 private HCounterColumn<String> clicksCounter;
89 97 private HCounterColumn<String> viewsCounter;
90 98 private final String keyString;
91 99
92   - CounterColumnBuilder(BucketType bucketType, long minInYear) {
93   - this.keyString = bucketType.formatDate(minInYear * 60 * 1000);
  100 + CounterColumnBuilder(BucketType bucketType, long rowNumber) {
  101 + this.keyString = bucketType.formatDate(System.currentTimeMillis() + (rowNumber * 60 * 1000));
  102 + log.info("using keyString {}",keyString);
94 103 }
95 104
96 105 CounterColumnBuilder applyClicks(long clicks) {
@@ -104,8 +113,8 @@ CounterColumnBuilder applyView(long views) {
104 113 }
105 114
106 115 void addToMutation(Mutator<String> mutator) {
107   - mutator.addCounter(keyString,"CounterCf",clicksCounter);
108 116 mutator.addCounter(keyString,"CounterCf",viewsCounter);
  117 + mutator.addCounter(keyString,"CounterCf",clicksCounter);
109 118 }
110 119 }
111 120
@@ -115,16 +124,19 @@ void addToMutation(Mutator<String> mutator) {
115 124 */
116 125 enum BucketType {
117 126 ALL("__ALL__"),
118   - MONTH("YYYY_MM"),
119   - WEEK("YYYY_MM_w"),
120   - DAY("YYYY_MM_dd"),
121   - HOUR("YYYY_MM_dd_hh"),
122   - MINUTE("YYYY_MM_dd_hh_mm");
  127 + MONTH("yyyy_MM"),
  128 + WEEK("yyyy_MM_w"),
  129 + DAY("yyyy_MM_dd"),
  130 + HOUR("yyyy_MM_dd_hh"),
  131 + MINUTE("yyyy_MM_dd_hh_mm");
123 132
124   - final FastDateFormat formatter;
  133 + FastDateFormat formatter;
125 134
126 135 BucketType(String format) {
127   - this.formatter = FastDateFormat.getInstance(format, TimeZone.getTimeZone("GMT"));
  136 + if ( !StringUtils.equals(format,"__ALL__")) {
  137 + this.formatter = FastDateFormat.getInstance(format, TimeZone.getTimeZone("GMT"));
  138 + }
  139 +
128 140 }
129 141
130 142 /**
@@ -142,6 +154,9 @@ public String formatDate(long date) {
142 154
143 155 @Override
144 156 public String toString() {
  157 + if ( formatter == null ) {
  158 + return "__ALL__";
  159 + }
145 160 return formatter.getPattern();
146 161 }
147 162 }
2  src/main/java/com/riptano/cassandra/stress/CommandRunner.java
@@ -89,7 +89,7 @@ private StressCommand getCommandInstance(int startKeyArg, CommandArgs commandArg
89 89 return new MultigetSliceCommand(startKey, commandArgs, commandRunner);
90 90 case VERIFY_LAST_INSERT:
91 91 return new VerifyLastInsertCommand(startKey, commandArgs, commandRunner);
92   - case COUNTER_SPREAD:
  92 + case COUNTERSPREAD:
93 93 return new BucketingCounterSpreadCommand(startKey, commandArgs, commandRunner);
94 94 };
95 95 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.