Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merged conflicted sources

  • Loading branch information...
commit afa05996bff8027bf7ee51e91ca05ce723e6d0fc 2 parents ed6ddd3 + 63615ea
@baepiff authored
View
6 src/java/voldemort/store/mysql/MysqlStorageConfiguration.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008-2009 LinkedIn, Inc
- *
+ *
* 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
View
332 test/integration/voldemort/performance/benchmark/Measurement.java
@@ -1,166 +1,166 @@
-/*
- * Copyright 2010 LinkedIn, Inc
- *
- * 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 voldemort.performance.benchmark;
-
-import java.io.PrintStream;
-import java.text.NumberFormat;
-import java.util.HashMap;
-
-class Results {
-
- public int operations;
- public long totalLatency, minLatency, maxLatency, q99Latency, q95Latency, medianLatency;
-
- public Results(int ops, long minL, long maxL, long totalLat, long medL, long q95, long q99) {
- this.operations = ops;
- this.minLatency = minL;
- this.maxLatency = maxL;
- this.totalLatency = totalLat;
- this.medianLatency = medL;
- this.q99Latency = q99;
- this.q95Latency = q95;
- }
-
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Operations = " + operations + "\n");
- buffer.append("Min Latency = " + minLatency + "\n");
- buffer.append("Max latency = " + maxLatency + "\n");
- buffer.append("Median Latency = " + medianLatency + "\n");
- buffer.append("95th percentile Latency = " + q95Latency + "\n");
- buffer.append("99th percentile Latency = " + q99Latency + "\n");
- return buffer.toString();
- }
-}
-
-public class Measurement {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- private int buckets;
- private int[] histogram;
- private int histogramOverflow;
- private int windowOperations;
- private long windowTotalLatency;
- private int operations = 0;
- private int minLatency = -1;
- private int maxLatency = -1;
- private long totalLatency = 0;
- private HashMap<Integer, int[]> returnCodes;
- private boolean summaryOnly = false;
-
- public Measurement(String name, boolean summaryOnly) {
- this.name = name;
- this.buckets = 3000; // Default bucket size of 3000 milliseconds
- this.histogram = new int[buckets];
- this.histogramOverflow = 0;
- this.operations = 0;
- this.totalLatency = 0;
- this.windowOperations = 0;
- this.windowTotalLatency = 0;
- this.minLatency = -1;
- this.maxLatency = -1;
- this.returnCodes = new HashMap<Integer, int[]>();
- this.summaryOnly = summaryOnly;
- }
-
- public synchronized void recordReturnCode(int code) {
- Integer Icode = code;
- if(!returnCodes.containsKey(Icode)) {
- int[] val = new int[1];
- val[0] = 0;
- returnCodes.put(Icode, val);
- }
- returnCodes.get(Icode)[0]++;
- }
-
- public synchronized void recordLatency(int latency) {
- if(latency >= buckets) {
- histogramOverflow++;
- } else {
- histogram[latency]++;
- }
- operations++;
- totalLatency += latency;
- windowOperations++;
- windowTotalLatency += latency;
-
- if((minLatency < 0) || (latency < minLatency)) {
- minLatency = latency;
- }
-
- if((maxLatency < 0) || (latency > maxLatency)) {
- maxLatency = latency;
- }
- }
-
- public Results generateResults() {
- int median = 0, q95 = 0, q99 = 0;
- int opcounter = 0;
- boolean done95th = false, done50th = false;
- for(int i = 0; i < buckets; i++) {
- opcounter += histogram[i];
- double currentQuartile = ((double) opcounter) / ((double) operations);
- if(!done50th && currentQuartile >= 0.50) {
- median = i;
- done50th = true;
- }
- if(!done95th && currentQuartile >= 0.95) {
- q95 = i;
- done95th = true;
- }
- if(currentQuartile >= 0.99) {
- q99 = i;
- break;
- }
- }
- return new Results(operations, minLatency, maxLatency, totalLatency, median, q95, q99);
- }
-
- public void printReport(PrintStream out) {
-
- Results result = generateResults();
- NumberFormat nf = NumberFormat.getInstance();
- nf.setMaximumFractionDigits(4);
- nf.setGroupingUsed(false);
-
- out.println("[" + getName() + "]\tOperations: " + operations);
- out.println("[" + getName() + "]\tAverage(ms): "
- + nf.format((((double) totalLatency) / ((double) operations))));
- out.println("[" + getName() + "]\tMin(ms): " + nf.format(minLatency));
- out.println("[" + getName() + "]\tMax(ms): " + nf.format(maxLatency));
- out.println("[" + getName() + "]\tMedian(ms): " + nf.format(result.medianLatency));
- out.println("[" + getName() + "]\t95th(ms): " + nf.format(result.q95Latency));
- out.println("[" + getName() + "]\t99th(ms): " + nf.format(result.q99Latency));
-
- if(!this.summaryOnly) {
- for(Integer I: returnCodes.keySet()) {
- int[] val = returnCodes.get(I);
- out.println("[" + getName() + "]\tReturn: " + I + "\t" + val[0]);
- }
-
- for(int i = 0; i < buckets; i++) {
- out.println("[" + getName() + "]: " + i + "\t" + histogram[i]);
- }
- out.println("[" + getName() + "]: >" + buckets + "\t" + histogramOverflow);
- }
- }
-}
+/*
+ * Copyright 2010 LinkedIn, Inc
+ *
+ * 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 voldemort.performance.benchmark;
+
+import java.io.PrintStream;
+import java.text.NumberFormat;
+import java.util.HashMap;
+
+class Results {
+
+ public int operations;
+ public long totalLatency, minLatency, maxLatency, q99Latency, q95Latency, medianLatency;
+
+ public Results(int ops, long minL, long maxL, long totalLat, long medL, long q95, long q99) {
+ this.operations = ops;
+ this.minLatency = minL;
+ this.maxLatency = maxL;
+ this.totalLatency = totalLat;
+ this.medianLatency = medL;
+ this.q99Latency = q99;
+ this.q95Latency = q95;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Operations = " + operations + "\n");
+ buffer.append("Min Latency = " + minLatency + "\n");
+ buffer.append("Max latency = " + maxLatency + "\n");
+ buffer.append("Median Latency = " + medianLatency + "\n");
+ buffer.append("95th percentile Latency = " + q95Latency + "\n");
+ buffer.append("99th percentile Latency = " + q99Latency + "\n");
+ return buffer.toString();
+ }
+}
+
+public class Measurement {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ private int buckets;
+ private int[] histogram;
+ private int histogramOverflow;
+ private int windowOperations;
+ private long windowTotalLatency;
+ private int operations = 0;
+ private int minLatency = -1;
+ private int maxLatency = -1;
+ private long totalLatency = 0;
+ private HashMap<Integer, int[]> returnCodes;
+ private boolean summaryOnly = false;
+
+ public Measurement(String name, boolean summaryOnly) {
+ this.name = name;
+ this.buckets = 3000; // Default bucket size of 3000 milliseconds
+ this.histogram = new int[buckets];
+ this.histogramOverflow = 0;
+ this.operations = 0;
+ this.totalLatency = 0;
+ this.windowOperations = 0;
+ this.windowTotalLatency = 0;
+ this.minLatency = -1;
+ this.maxLatency = -1;
+ this.returnCodes = new HashMap<Integer, int[]>();
+ this.summaryOnly = summaryOnly;
+ }
+
+ public synchronized void recordReturnCode(int code) {
+ Integer Icode = code;
+ if(!returnCodes.containsKey(Icode)) {
+ int[] val = new int[1];
+ val[0] = 0;
+ returnCodes.put(Icode, val);
+ }
+ returnCodes.get(Icode)[0]++;
+ }
+
+ public synchronized void recordLatency(int latency) {
+ if(latency >= buckets) {
+ histogramOverflow++;
+ } else {
+ histogram[latency]++;
+ }
+ operations++;
+ totalLatency += latency;
+ windowOperations++;
+ windowTotalLatency += latency;
+
+ if((minLatency < 0) || (latency < minLatency)) {
+ minLatency = latency;
+ }
+
+ if((maxLatency < 0) || (latency > maxLatency)) {
+ maxLatency = latency;
+ }
+ }
+
+ public Results generateResults() {
+ int median = 0, q95 = 0, q99 = 0;
+ int opcounter = 0;
+ boolean done95th = false, done50th = false;
+ for(int i = 0; i < buckets; i++) {
+ opcounter += histogram[i];
+ double currentQuartile = ((double) opcounter) / ((double) operations);
+ if(!done50th && currentQuartile >= 0.50) {
+ median = i;
+ done50th = true;
+ }
+ if(!done95th && currentQuartile >= 0.95) {
+ q95 = i;
+ done95th = true;
+ }
+ if(currentQuartile >= 0.99) {
+ q99 = i;
+ break;
+ }
+ }
+ return new Results(operations, minLatency, maxLatency, totalLatency, median, q95, q99);
+ }
+
+ public void printReport(PrintStream out) {
+
+ Results result = generateResults();
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setMaximumFractionDigits(4);
+ nf.setGroupingUsed(false);
+
+ out.println("[" + getName() + "]\tOperations: " + operations);
+ out.println("[" + getName() + "]\tAverage(ms): "
+ + nf.format((((double) totalLatency) / ((double) operations))));
+ out.println("[" + getName() + "]\tMin(ms): " + nf.format(minLatency));
+ out.println("[" + getName() + "]\tMax(ms): " + nf.format(maxLatency));
+ out.println("[" + getName() + "]\tMedian(ms): " + nf.format(result.medianLatency));
+ out.println("[" + getName() + "]\t95th(ms): " + nf.format(result.q95Latency));
+ out.println("[" + getName() + "]\t99th(ms): " + nf.format(result.q99Latency));
+
+ if(!this.summaryOnly) {
+ for(Integer I: returnCodes.keySet()) {
+ int[] val = returnCodes.get(I);
+ out.println("[" + getName() + "]\tReturn: " + I + "\t" + val[0]);
+ }
+
+ for(int i = 0; i < buckets; i++) {
+ out.println("[" + getName() + "]: " + i + "\t" + histogram[i]);
+ }
+ out.println("[" + getName() + "]: >" + buckets + "\t" + histogramOverflow);
+ }
+ }
+}
View
92 test/integration/voldemort/performance/benchmark/generator/IntegerGenerator.java
@@ -1,46 +1,46 @@
-/*
- * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
- */
-
-package voldemort.performance.benchmark.generator;
-
-/**
- * A generator that is capable of generating Ints, Strings and Bytes
- */
-public abstract class IntegerGenerator extends Generator {
-
- private int lastInt;
-
- public abstract int nextInt();
-
- public void setLastInt(int last) {
- lastInt = last;
- }
-
- @Override
- public String nextString() {
- return Integer.toString(nextInt());
- }
-
- @Override
- public String lastString() {
- return Integer.toString(lastInt);
- }
-
- public int lastInt() {
- return lastInt;
- }
-
-}
+/*
+ * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
+ */
+
+package voldemort.performance.benchmark.generator;
+
+/**
+ * A generator that is capable of generating Ints, Strings and Bytes
+ */
+public abstract class IntegerGenerator extends Generator {
+
+ private int lastInt;
+
+ public abstract int nextInt();
+
+ public void setLastInt(int last) {
+ lastInt = last;
+ }
+
+ @Override
+ public String nextString() {
+ return Integer.toString(nextInt());
+ }
+
+ @Override
+ public String lastString() {
+ return Integer.toString(lastInt);
+ }
+
+ public int lastInt() {
+ return lastInt;
+ }
+
+}
View
134 test/integration/voldemort/performance/benchmark/generator/ScrambledZipfianGenerator.java
@@ -1,67 +1,67 @@
-/*
- * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
- */
-
-package voldemort.performance.benchmark.generator;
-
-import voldemort.utils.FnvHashFunction;
-
-/**
- * A generator of a Zipfian distribution. It produces a sequence of items, such
- * that some items are more popular than others, according to a Zipfian
- * distribution.
- *
- * Unlike @ZipfianGenerator, this class scatters the "popular" items across the
- * item space. Use this, instead of @ZipfianGenerator, if you don't want the
- * head of the distribution (the popular items) clustered together.
- */
-public class ScrambledZipfianGenerator extends IntegerGenerator {
-
- public static final double ZETAN = 52.93805640344461;
- public static final long ITEM_COUNT = 10000000000L;
-
- private ZipfianGenerator generator;
- private long min, max, itemCount;
- private FnvHashFunction hash;
-
- public ScrambledZipfianGenerator(long items) {
- this(0, items - 1);
- }
-
- public ScrambledZipfianGenerator(long min, long max) {
- this(min, max, ZipfianGenerator.ZIPFIAN_CONSTANT);
- }
-
- public ScrambledZipfianGenerator(long min, long max, double zipfianConstant) {
- this.min = min;
- this.max = max;
- this.itemCount = this.max - this.min + 1;
- generator = new ZipfianGenerator(0, ITEM_COUNT, zipfianConstant, ZETAN);
- hash = new FnvHashFunction();
- }
-
- @Override
- public int nextInt() {
- return (int) nextLong();
- }
-
- public long nextLong() {
- long ret = generator.nextLong();
- ret = min + hash.hash64(ret) % itemCount;
- setLastInt((int) ret);
- return ret;
- }
-
-}
+/*
+ * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
+ */
+
+package voldemort.performance.benchmark.generator;
+
+import voldemort.utils.FnvHashFunction;
+
+/**
+ * A generator of a Zipfian distribution. It produces a sequence of items, such
+ * that some items are more popular than others, according to a Zipfian
+ * distribution.
+ *
+ * Unlike @ZipfianGenerator, this class scatters the "popular" items across the
+ * item space. Use this, instead of @ZipfianGenerator, if you don't want the
+ * head of the distribution (the popular items) clustered together.
+ */
+public class ScrambledZipfianGenerator extends IntegerGenerator {
+
+ public static final double ZETAN = 52.93805640344461;
+ public static final long ITEM_COUNT = 10000000000L;
+
+ private ZipfianGenerator generator;
+ private long min, max, itemCount;
+ private FnvHashFunction hash;
+
+ public ScrambledZipfianGenerator(long items) {
+ this(0, items - 1);
+ }
+
+ public ScrambledZipfianGenerator(long min, long max) {
+ this(min, max, ZipfianGenerator.ZIPFIAN_CONSTANT);
+ }
+
+ public ScrambledZipfianGenerator(long min, long max, double zipfianConstant) {
+ this.min = min;
+ this.max = max;
+ this.itemCount = this.max - this.min + 1;
+ generator = new ZipfianGenerator(0, ITEM_COUNT, zipfianConstant, ZETAN);
+ hash = new FnvHashFunction();
+ }
+
+ @Override
+ public int nextInt() {
+ return (int) nextLong();
+ }
+
+ public long nextLong() {
+ long ret = generator.nextLong();
+ ret = min + hash.hash64(ret) % itemCount;
+ setLastInt((int) ret);
+ return ret;
+ }
+
+}
View
80 test/integration/voldemort/performance/benchmark/generator/UniformIntegerGenerator.java
@@ -1,40 +1,40 @@
-/*
- * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
- */
-
-package voldemort.performance.benchmark.generator;
-
-import java.util.Random;
-
-public class UniformIntegerGenerator extends IntegerGenerator {
-
- private Random random;
- private int lowerBound, upperBound, interval;
-
- public UniformIntegerGenerator(int lb, int ub) {
- this.random = new Random();
- this.lowerBound = lb;
- this.upperBound = ub;
- this.interval = upperBound - lowerBound + 1;
- }
-
- @Override
- public int nextInt() {
- int ret = random.nextInt(interval) + lowerBound;
- setLastInt(ret);
- return ret;
- }
-
-}
+/*
+ * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
+ */
+
+package voldemort.performance.benchmark.generator;
+
+import java.util.Random;
+
+public class UniformIntegerGenerator extends IntegerGenerator {
+
+ private Random random;
+ private int lowerBound, upperBound, interval;
+
+ public UniformIntegerGenerator(int lb, int ub) {
+ this.random = new Random();
+ this.lowerBound = lb;
+ this.upperBound = ub;
+ this.interval = upperBound - lowerBound + 1;
+ }
+
+ @Override
+ public int nextInt() {
+ int ret = random.nextInt(interval) + lowerBound;
+ setLastInt(ret);
+ return ret;
+ }
+
+}
View
266 test/integration/voldemort/performance/benchmark/generator/ZipfianGenerator.java
@@ -1,133 +1,133 @@
-/*
- * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
- */
-
-package voldemort.performance.benchmark.generator;
-
-import java.util.Random;
-
-/**
- * A generator of a Zipfian distribution. It produces a sequence of items, such
- * that some items are more popular than others, according to a zipfian
- * distribution.
- *
- * Note that the popular items will be clustered together, e.g. item 0 is the
- * most popular, item 1 the second most popular, and so on (or min is the most
- * popular, min+1 the next most popular, etc.)
- *
- */
-public class ZipfianGenerator extends IntegerGenerator {
-
- public static final double ZIPFIAN_CONSTANT = 0.99;
-
- private long items, base, countZeta;
- private double zipfianConstant, alpha, zetan, eta, theta, zeta2theta;
- private Random random;
- boolean allowItemCountDecrease = false;
-
- public ZipfianGenerator(long items) {
- this(0, items - 1);
- }
-
- public ZipfianGenerator(long min, long max) {
- this(min, max, ZIPFIAN_CONSTANT);
- }
-
- public ZipfianGenerator(long items, double zipfianConstant) {
- this(0, items - 1, zipfianConstant);
- }
-
- public ZipfianGenerator(long min, long max, double zipfianConstant) {
- this(min, max, zipfianConstant, zetaStatic(max - min + 1, zipfianConstant));
- }
-
- public ZipfianGenerator(long min, long max, double zipfianConstant, double zetan) {
- this.items = max - min + 1;
- this.base = min;
- this.zipfianConstant = zipfianConstant;
- this.random = new Random();
- this.theta = this.zipfianConstant;
- this.zeta2theta = zeta(2, theta);
- this.alpha = 1.0 / (1.0 - theta);
- this.zetan = zetan;
- this.countZeta = items;
- this.eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
- nextInt();
- }
-
- double zeta(long n, double theta) {
- countZeta = n;
- return zetaStatic(n, theta);
- }
-
- static double zetaStatic(long n, double theta) {
- return zetaStatic(0, n, theta, 0);
- }
-
- double zeta(long st, long n, double theta, double initialSum) {
- countZeta = n;
- return zetaStatic(st, n, theta, initialSum);
- }
-
- static double zetaStatic(long st, long n, double theta, double initialSum) {
- double sum = initialSum;
- for(long i = st; i < n; i++) {
- sum += 1 / (Math.pow(i + 1, theta));
- }
- return sum;
- }
-
- public int nextInt(int itemcount) {
- return (int) nextLong(itemcount);
- }
-
- public long nextLong(long itemCount) {
- // from "Quickly Generating Billion-Record Synthetic Databases"
- if(itemCount != countZeta) {
-
- synchronized(this) {
- if(itemCount > countZeta) {
- zetan = zeta(countZeta, itemCount, theta, zetan);
- eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
- } else if((itemCount < countZeta) && (allowItemCountDecrease)) {
- zetan = zeta(itemCount, theta);
- eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
- }
- }
- }
- double u = random.nextDouble();
- double uz = u * zetan;
- if(uz < 1.0) {
- return 0;
- }
-
- if(uz < 1.0 + Math.pow(0.5, theta)) {
- return 1;
- }
-
- long ret = base + (long) ((itemCount) * Math.pow(eta * u - eta + 1, alpha));
- setLastInt((int) ret);
- return ret;
- }
-
- @Override
- public int nextInt() {
- return (int) nextLong(items);
- }
-
- public long nextLong() {
- return nextLong(items);
- }
-}
+/*
+ * Copyright (c) 2010 Yahoo! Inc. 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. See accompanying LICENSE file.
+ */
+
+package voldemort.performance.benchmark.generator;
+
+import java.util.Random;
+
+/**
+ * A generator of a Zipfian distribution. It produces a sequence of items, such
+ * that some items are more popular than others, according to a zipfian
+ * distribution.
+ *
+ * Note that the popular items will be clustered together, e.g. item 0 is the
+ * most popular, item 1 the second most popular, and so on (or min is the most
+ * popular, min+1 the next most popular, etc.)
+ *
+ */
+public class ZipfianGenerator extends IntegerGenerator {
+
+ public static final double ZIPFIAN_CONSTANT = 0.99;
+
+ private long items, base, countZeta;
+ private double zipfianConstant, alpha, zetan, eta, theta, zeta2theta;
+ private Random random;
+ boolean allowItemCountDecrease = false;
+
+ public ZipfianGenerator(long items) {
+ this(0, items - 1);
+ }
+
+ public ZipfianGenerator(long min, long max) {
+ this(min, max, ZIPFIAN_CONSTANT);
+ }
+
+ public ZipfianGenerator(long items, double zipfianConstant) {
+ this(0, items - 1, zipfianConstant);
+ }
+
+ public ZipfianGenerator(long min, long max, double zipfianConstant) {
+ this(min, max, zipfianConstant, zetaStatic(max - min + 1, zipfianConstant));
+ }
+
+ public ZipfianGenerator(long min, long max, double zipfianConstant, double zetan) {
+ this.items = max - min + 1;
+ this.base = min;
+ this.zipfianConstant = zipfianConstant;
+ this.random = new Random();
+ this.theta = this.zipfianConstant;
+ this.zeta2theta = zeta(2, theta);
+ this.alpha = 1.0 / (1.0 - theta);
+ this.zetan = zetan;
+ this.countZeta = items;
+ this.eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
+ nextInt();
+ }
+
+ double zeta(long n, double theta) {
+ countZeta = n;
+ return zetaStatic(n, theta);
+ }
+
+ static double zetaStatic(long n, double theta) {
+ return zetaStatic(0, n, theta, 0);
+ }
+
+ double zeta(long st, long n, double theta, double initialSum) {
+ countZeta = n;
+ return zetaStatic(st, n, theta, initialSum);
+ }
+
+ static double zetaStatic(long st, long n, double theta, double initialSum) {
+ double sum = initialSum;
+ for(long i = st; i < n; i++) {
+ sum += 1 / (Math.pow(i + 1, theta));
+ }
+ return sum;
+ }
+
+ public int nextInt(int itemcount) {
+ return (int) nextLong(itemcount);
+ }
+
+ public long nextLong(long itemCount) {
+ // from "Quickly Generating Billion-Record Synthetic Databases"
+ if(itemCount != countZeta) {
+
+ synchronized(this) {
+ if(itemCount > countZeta) {
+ zetan = zeta(countZeta, itemCount, theta, zetan);
+ eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
+ } else if((itemCount < countZeta) && (allowItemCountDecrease)) {
+ zetan = zeta(itemCount, theta);
+ eta = (1 - Math.pow(2.0 / items, 1 - theta)) / (1 - zeta2theta / zetan);
+ }
+ }
+ }
+ double u = random.nextDouble();
+ double uz = u * zetan;
+ if(uz < 1.0) {
+ return 0;
+ }
+
+ if(uz < 1.0 + Math.pow(0.5, theta)) {
+ return 1;
+ }
+
+ long ret = base + (long) ((itemCount) * Math.pow(eta * u - eta + 1, alpha));
+ setLastInt((int) ret);
+ return ret;
+ }
+
+ @Override
+ public int nextInt() {
+ return (int) nextLong(items);
+ }
+
+ public long nextLong() {
+ return nextLong(items);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.