Skip to content

Commit

Permalink
[core] Use longs instead of ints to support larger key spaces.
Browse files Browse the repository at this point in the history
Changed int to long in Measurements code to support large scale workloads.
(manolama - fixed checkstyle errors)

Signed-off-by: Chris Larsen <clarsen@yahoo-inc.com>
  • Loading branch information
Mairbek Khadikov authored and manolama committed Aug 5, 2017
1 parent 2c66bc6 commit 59bc986
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class AcknowledgedCounterGenerator extends CounterGenerator {

private final ReentrantLock lock;
private final boolean[] window;
private volatile int limit;
private volatile long limit;

/**
* Create a counter that starts at countstart.
*/
public AcknowledgedCounterGenerator(int countstart) {
public AcknowledgedCounterGenerator(long countstart) {
super(countstart);
lock = new ReentrantLock();
window = new boolean[WINDOW_SIZE];
Expand All @@ -48,15 +48,15 @@ public AcknowledgedCounterGenerator(int countstart) {
* (as opposed to the highest generated counter value).
*/
@Override
public Integer lastValue() {
public Long lastValue() {
return limit;
}

/**
* Make a generated counter value available via lastInt().
*/
public void acknowledge(int value) {
final int currentSlot = (value & WINDOW_MASK);
public void acknowledge(long value) {
final int currentSlot = (int)(value & WINDOW_MASK);
if (window[currentSlot]) {
throw new RuntimeException("Too many unacknowledged insertion keys.");
}
Expand All @@ -68,10 +68,10 @@ public void acknowledge(int value) {
// over to the "limit" variable
try {
// Only loop through the entire window at most once.
int beforeFirstSlot = (limit & WINDOW_MASK);
int index;
long beforeFirstSlot = (limit & WINDOW_MASK);
long index;
for (index = limit + 1; index != beforeFirstSlot; ++index) {
int slot = (index & WINDOW_MASK);
int slot = (int)(index & WINDOW_MASK);
if (!window[slot]) {
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2016 Yahoo! Inc., 2017 YCSB contributors. All rights reserved.
* Copyright (c) 2010 Yahoo! Inc., Copyright (c) 2017 YCSB contributors. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
Expand All @@ -17,29 +17,29 @@

package com.yahoo.ycsb.generator;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
* Generates a sequence of integers.
* (0, 1, ...)
*/
public class CounterGenerator extends NumberGenerator {
private final AtomicInteger counter;
private final AtomicLong counter;

/**
* Create a counter that starts at countstart.
*/
public CounterGenerator(int countstart) {
counter = new AtomicInteger(countstart);
public CounterGenerator(long countstart) {
counter=new AtomicLong(countstart);
}

@Override
public Integer nextValue() {
public Long nextValue() {
return counter.getAndIncrement();
}

@Override
public Integer lastValue() {
public Long lastValue() {
return counter.get() - 1;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2016 Yahoo! Inc., 2017 YCSB contributors. All rights reserved.
* Copyright (c) 2010 Yahoo! Inc. Copyright (c) 2017 YCSB contributors. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
Expand Down Expand Up @@ -31,10 +31,10 @@
*/
public class HotspotIntegerGenerator extends NumberGenerator {

private final int lowerBound;
private final int upperBound;
private final int hotInterval;
private final int coldInterval;
private final long lowerBound;
private final long upperBound;
private final long hotInterval;
private final long coldInterval;
private final double hotsetFraction;
private final double hotOpnFraction;

Expand All @@ -46,7 +46,7 @@ public class HotspotIntegerGenerator extends NumberGenerator {
* @param hotsetFraction percentage of data item
* @param hotOpnFraction percentage of operations accessing the hot set.
*/
public HotspotIntegerGenerator(int lowerBound, int upperBound,
public HotspotIntegerGenerator(long lowerBound, long upperBound,
double hotsetFraction, double hotOpnFraction) {
if (hotsetFraction < 0.0 || hotsetFraction > 1.0) {
System.err.println("Hotset fraction out of range. Setting to 0.0");
Expand All @@ -59,29 +59,29 @@ public HotspotIntegerGenerator(int lowerBound, int upperBound,
if (lowerBound > upperBound) {
System.err.println("Upper bound of Hotspot generator smaller than the lower bound. " +
"Swapping the values.");
int temp = lowerBound;
long temp = lowerBound;
lowerBound = upperBound;
upperBound = temp;
}
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.hotsetFraction = hotsetFraction;
int interval = upperBound - lowerBound + 1;
long interval = upperBound - lowerBound + 1;
this.hotInterval = (int) (interval * hotsetFraction);
this.coldInterval = interval - hotInterval;
this.hotOpnFraction = hotOpnFraction;
}

@Override
public Integer nextValue() {
int value = 0;
public Long nextValue() {
long value = 0;
Random random = Utils.random();
if (random.nextDouble() < hotOpnFraction) {
// Choose a value from the hot set.
value = lowerBound + random.nextInt(hotInterval);
value = lowerBound + Math.abs(Utils.random().nextLong()) % hotInterval;
} else {
// Choose a value from the cold set.
value = lowerBound + hotInterval + random.nextInt(coldInterval);
value = lowerBound + hotInterval + Math.abs(Utils.random().nextLong()) % coldInterval;
}
setLastValue(value);
return value;
Expand All @@ -90,14 +90,14 @@ public Integer nextValue() {
/**
* @return the lowerBound
*/
public int getLowerBound() {
public long getLowerBound() {
return lowerBound;
}

/**
* @return the upperBound
*/
public int getUpperBound() {
public long getUpperBound() {
return upperBound;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,39 @@

package com.yahoo.ycsb.generator;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
* Generates a sequence of integers 0, 1, ...
*/
public class SequentialGenerator extends NumberGenerator {
protected final AtomicInteger counter;
protected int interval, countstart;
private final AtomicLong counter;
private long interval;
private long countstart;

/**
* Create a counter that starts at countstart.
*/
public SequentialGenerator(int countstart, int countend) {
counter = new AtomicInteger();
public SequentialGenerator(long countstart, long countend) {
counter = new AtomicLong();
setLastValue(counter.get());
this.countstart = countstart;
interval = countend - countstart + 1;
}

/**
* If the generator returns numeric (integer) values, return the next value as an int.
* If the generator returns numeric (long) values, return the next value as an long.
* Default is to return -1, which is appropriate for generators that do not return numeric values.
*/
public int nextInt() {
int ret = countstart + counter.getAndIncrement() % interval;
public long nextLong() {
long ret = countstart + counter.getAndIncrement() % interval;
setLastValue(ret);
return ret;
}

@Override
public Number nextValue() {
int ret = countstart + counter.getAndIncrement() % interval;
long ret = countstart + counter.getAndIncrement() % interval;
setLastValue(ret);
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2016 Yahoo! Inc., 2017 YCSB contributors. All rights reserved.
* Copyright (c) 2010 Yahoo! Inc. Copyright (c) 2017 YCSB contributors. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
Expand Down Expand Up @@ -27,23 +27,23 @@
public class UniformGenerator extends Generator<String> {
private final List<String> values;
private String laststring;
private final UniformIntegerGenerator gen;
private final UniformLongGenerator gen;

/**
* Creates a generator that will return strings from the specified set uniformly randomly.
*/
public UniformGenerator(Collection<String> values) {
this.values = new ArrayList<>(values);
laststring = null;
gen = new UniformIntegerGenerator(0, values.size() - 1);
gen = new UniformLongGenerator(0, values.size() - 1);
}

/**
* Generate the next string in the distribution.
*/
@Override
public String nextValue() {
laststring = values.get(gen.nextValue());
laststring = values.get(gen.nextValue().intValue());
return laststring;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2010-2016 Yahoo! Inc., 2017 YCSB contributors. All rights reserved.
* Copyright (c) 2010 Yahoo! Inc. Copyright (c) 2017 YCSB contributors. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
Expand All @@ -20,27 +20,28 @@
import com.yahoo.ycsb.Utils;

/**
* Generates integers randomly uniform from an interval.
* Generates longs randomly uniform from an interval.
*/
public class UniformIntegerGenerator extends NumberGenerator {
private final int lb, ub, interval;
public class UniformLongGenerator extends NumberGenerator {
private final long lb, ub, interval;

/**
* Creates a generator that will return integers uniformly randomly from the interval [lb,ub] inclusive.
* Creates a generator that will return longs uniformly randomly from the
* interval [lb,ub] inclusive (that is, lb and ub are possible values)
* (lb and ub are possible values).
*
* @param lb the lower bound (inclusive) of generated values
* @param ub the upper bound (inclusive) of generated values
*/
public UniformIntegerGenerator(int lb, int ub) {
public UniformLongGenerator(long lb, long ub) {
this.lb = lb;
this.ub = ub;
interval = this.ub - this.lb + 1;
}

@Override
public Integer nextValue() {
int ret = Utils.random().nextInt(interval) + lb;
public Long nextValue() {
long ret = Math.abs(Utils.random().nextLong()) % interval + lb;
setLastValue(ret);

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public class OneMeasurementHistogram extends OneMeasurement {
/**
* Groups operations in discrete blocks of 1ms width.
*/
private final int[] histogram;
private long[] histogram;

/**
* Counts all operations outside the histogram's range.
*/
private int histogramoverflow;
private long histogramoverflow;

/**
* The total number of reported operations.
*/
private int operations;
private long operations;

/**
* The sum of each latency measurement over all operations.
Expand All @@ -65,7 +65,7 @@ public class OneMeasurementHistogram extends OneMeasurement {
private double totalsquaredlatency;

//keep a windowed version of these stats for printing status
private int windowoperations;
private long windowoperations;
private long windowtotallatency;

private int min;
Expand All @@ -74,7 +74,7 @@ public class OneMeasurementHistogram extends OneMeasurement {
public OneMeasurementHistogram(String name, Properties props) {
super(name);
buckets = Integer.parseInt(props.getProperty(BUCKETS, BUCKETS_DEFAULT));
histogram = new int[buckets];
histogram = new long[buckets];
histogramoverflow = 0;
operations = 0;
totallatency = 0;
Expand Down Expand Up @@ -120,7 +120,7 @@ public void exportMeasurements(MeasurementsExporter exporter) throws IOException
exporter.write(getName(), "MinLatency(us)", min);
exporter.write(getName(), "MaxLatency(us)", max);

int opcounter = 0;
long opcounter=0;
boolean done95th = false;
for (int i = 0; i < buckets; i++) {
opcounter += histogram[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class OneMeasurementTimeSeries extends OneMeasurement {

private long start = -1;
private long currentunit = -1;
private int count = 0;
private int sum = 0;
private int operations = 0;
private long count = 0;
private long sum = 0;
private long operations = 0;
private long totallatency = 0;

//keep a windowed version of these stats for printing status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public void write(String metric, String measurement, int i) throws IOException {
g.writeEndObject();
}

public void write(String metric, String measurement, long i) throws IOException {
g.writeStartObject();
g.writeStringField("metric", metric);
g.writeStringField("measurement", measurement);
g.writeNumberField("value", i);
g.writeEndObject();
}

public void write(String metric, String measurement, double d) throws IOException {
g.writeStartObject();
g.writeStringField("metric", metric);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public void write(String metric, String measurement, int i) throws IOException {
g.writeEndObject();
}

public void write(String metric, String measurement, long i) throws IOException {
g.writeStartObject();
g.writeStringField("metric", metric);
g.writeStringField("measurement", measurement);
g.writeNumberField("value", i);
g.writeEndObject();
}

public void write(String metric, String measurement, double d) throws IOException {
g.writeStartObject();
g.writeStringField("metric", metric);
Expand Down
Loading

0 comments on commit 59bc986

Please sign in to comment.