This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
forked from brianfrankcooper/YCSB
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to specify field length distributions
- Loading branch information
Russell Sears
committed
Nov 12, 2011
1 parent
e204c05
commit 2c5daad
Showing
9 changed files
with
253 additions
and
13 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/com/yahoo/ycsb/generator/ConstantIntegerGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* 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 com.yahoo.ycsb.generator; | ||
|
||
/** | ||
* A trivial integer generator that always returns the same value. | ||
* | ||
* @author sears | ||
* | ||
*/ | ||
public class ConstantIntegerGenerator extends IntegerGenerator { | ||
private final int i; | ||
/** | ||
* @param i The integer that this generator will always return. | ||
*/ | ||
public ConstantIntegerGenerator(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Override | ||
public int nextInt() { | ||
return i; | ||
} | ||
|
||
@Override | ||
public double mean() { | ||
return i; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* 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 com.yahoo.ycsb.generator; | ||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Random; | ||
import com.yahoo.ycsb.generator.IntegerGenerator; | ||
|
||
/** | ||
* Generate integers according to a histogram distribution. The histogram | ||
* buckets are of width one, but the values are multiplied by a block size. | ||
* Therefore, instead of drawing sizes uniformly at random within each | ||
* bucket, we always draw the largest value in the current bucket, so the value | ||
* drawn is always a multiple of block_size. | ||
* | ||
* The minimum value this distribution returns is block_size (not zero). | ||
* | ||
* Modified Nov 19 2010 by sears | ||
* | ||
* @author snjones | ||
* | ||
*/ | ||
public class HistogramGenerator extends IntegerGenerator { | ||
|
||
long block_size; | ||
long[] buckets; | ||
long area; | ||
Random rand = new Random(); | ||
long weighted_area = 0; | ||
double mean_size = 0; | ||
|
||
public HistogramGenerator(String histogramfile) throws IOException { | ||
BufferedReader in = new BufferedReader(new FileReader(histogramfile)); | ||
String str; | ||
String[] line; | ||
|
||
ArrayList<Integer> a = new ArrayList<Integer>(); | ||
|
||
str = in.readLine(); | ||
if(str == null) { | ||
throw new IOException("Empty input file!\n"); | ||
} | ||
line = str.split("\t"); | ||
if(line[0].compareTo("BlockSize") != 0) { | ||
throw new IOException("First line of histogram is not the BlockSize!\n"); | ||
} | ||
block_size = Integer.parseInt(line[1]); | ||
|
||
while((str = in.readLine()) != null){ | ||
// [0] is the bucket, [1] is the value | ||
line = str.split("\t"); | ||
|
||
a.add(Integer.parseInt(line[0]), Integer.parseInt(line[1])); | ||
} | ||
buckets = new long[a.size()]; | ||
for(int i = 0; i < a.size(); i++) { | ||
buckets[i] = a.get(i); | ||
} | ||
|
||
in.close(); | ||
init(); | ||
} | ||
|
||
public HistogramGenerator(long[] buckets, int block_size) { | ||
this.block_size = block_size; | ||
this.buckets = buckets; | ||
init(); | ||
} | ||
private void init() { | ||
for(int i = 0; i < buckets.length; i++) { | ||
area += buckets[i]; | ||
weighted_area = i * buckets[i]; | ||
} | ||
// calculate average file size | ||
mean_size = ((double)block_size) * ((double)weighted_area) / (double)(area); | ||
} | ||
|
||
@Override | ||
public int nextInt() { | ||
int number = rand.nextInt((int)area); | ||
int i; | ||
|
||
for(i = 0; i < (buckets.length - 1); i++){ | ||
number -= buckets[i]; | ||
if(number <= 0){ | ||
return (int)((i+1)*block_size); | ||
} | ||
} | ||
|
||
return (int)(i * block_size); | ||
} | ||
|
||
@Override | ||
public double mean() { | ||
return mean_size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters