Search in sources :

Example 1 with UniformLongGenerator

use of site.ycsb.generator.UniformLongGenerator in project YCSB by brianfrankcooper.

the class CoreWorkload method init.

/**
 * Initialize the scenario.
 * Called once, in the main client thread, before any operations are started.
 */
@Override
public void init(Properties p) throws WorkloadException {
    table = p.getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT);
    fieldcount = Long.parseLong(p.getProperty(FIELD_COUNT_PROPERTY, FIELD_COUNT_PROPERTY_DEFAULT));
    final String fieldnameprefix = p.getProperty(FIELD_NAME_PREFIX, FIELD_NAME_PREFIX_DEFAULT);
    fieldnames = new ArrayList<>();
    for (int i = 0; i < fieldcount; i++) {
        fieldnames.add(fieldnameprefix + i);
    }
    fieldlengthgenerator = CoreWorkload.getFieldLengthGenerator(p);
    recordcount = Long.parseLong(p.getProperty(Client.RECORD_COUNT_PROPERTY, Client.DEFAULT_RECORD_COUNT));
    if (recordcount == 0) {
        recordcount = Integer.MAX_VALUE;
    }
    String requestdistrib = p.getProperty(REQUEST_DISTRIBUTION_PROPERTY, REQUEST_DISTRIBUTION_PROPERTY_DEFAULT);
    int minscanlength = Integer.parseInt(p.getProperty(MIN_SCAN_LENGTH_PROPERTY, MIN_SCAN_LENGTH_PROPERTY_DEFAULT));
    int maxscanlength = Integer.parseInt(p.getProperty(MAX_SCAN_LENGTH_PROPERTY, MAX_SCAN_LENGTH_PROPERTY_DEFAULT));
    String scanlengthdistrib = p.getProperty(SCAN_LENGTH_DISTRIBUTION_PROPERTY, SCAN_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT);
    long insertstart = Long.parseLong(p.getProperty(INSERT_START_PROPERTY, INSERT_START_PROPERTY_DEFAULT));
    long insertcount = Integer.parseInt(p.getProperty(INSERT_COUNT_PROPERTY, String.valueOf(recordcount - insertstart)));
    // Confirm valid values for insertstart and insertcount in relation to recordcount
    if (recordcount < (insertstart + insertcount)) {
        System.err.println("Invalid combination of insertstart, insertcount and recordcount.");
        System.err.println("recordcount must be bigger than insertstart + insertcount.");
        System.exit(-1);
    }
    zeropadding = Integer.parseInt(p.getProperty(ZERO_PADDING_PROPERTY, ZERO_PADDING_PROPERTY_DEFAULT));
    readallfields = Boolean.parseBoolean(p.getProperty(READ_ALL_FIELDS_PROPERTY, READ_ALL_FIELDS_PROPERTY_DEFAULT));
    readallfieldsbyname = Boolean.parseBoolean(p.getProperty(READ_ALL_FIELDS_BY_NAME_PROPERTY, READ_ALL_FIELDS_BY_NAME_PROPERTY_DEFAULT));
    writeallfields = Boolean.parseBoolean(p.getProperty(WRITE_ALL_FIELDS_PROPERTY, WRITE_ALL_FIELDS_PROPERTY_DEFAULT));
    dataintegrity = Boolean.parseBoolean(p.getProperty(DATA_INTEGRITY_PROPERTY, DATA_INTEGRITY_PROPERTY_DEFAULT));
    // integrity check requested.
    if (dataintegrity && !(p.getProperty(FIELD_LENGTH_DISTRIBUTION_PROPERTY, FIELD_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT)).equals("constant")) {
        System.err.println("Must have constant field size to check data integrity.");
        System.exit(-1);
    }
    if (dataintegrity) {
        System.out.println("Data integrity is enabled.");
    }
    if (p.getProperty(INSERT_ORDER_PROPERTY, INSERT_ORDER_PROPERTY_DEFAULT).compareTo("hashed") == 0) {
        orderedinserts = false;
    } else {
        orderedinserts = true;
    }
    keysequence = new CounterGenerator(insertstart);
    operationchooser = createOperationGenerator(p);
    transactioninsertkeysequence = new AcknowledgedCounterGenerator(recordcount);
    if (requestdistrib.compareTo("uniform") == 0) {
        keychooser = new UniformLongGenerator(insertstart, insertstart + insertcount - 1);
    } else if (requestdistrib.compareTo("exponential") == 0) {
        double percentile = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_PERCENTILE_PROPERTY, ExponentialGenerator.EXPONENTIAL_PERCENTILE_DEFAULT));
        double frac = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_FRAC_PROPERTY, ExponentialGenerator.EXPONENTIAL_FRAC_DEFAULT));
        keychooser = new ExponentialGenerator(percentile, recordcount * frac);
    } else if (requestdistrib.compareTo("sequential") == 0) {
        keychooser = new SequentialGenerator(insertstart, insertstart + insertcount - 1);
    } else if (requestdistrib.compareTo("zipfian") == 0) {
        // it does this by generating a random "next key" in part by taking the modulus over the
        // number of keys.
        // If the number of keys changes, this would shift the modulus, and we don't want that to
        // change which keys are popular so we'll actually construct the scrambled zipfian generator
        // with a keyspace that is larger than exists at the beginning of the test. that is, we'll predict
        // the number of inserts, and tell the scrambled zipfian generator the number of existing keys
        // plus the number of predicted keys as the total keyspace. then, if the generator picks a key
        // that hasn't been inserted yet, will just ignore it and pick another key. this way, the size of
        // the keyspace doesn't change from the perspective of the scrambled zipfian generator
        final double insertproportion = Double.parseDouble(p.getProperty(INSERT_PROPORTION_PROPERTY, INSERT_PROPORTION_PROPERTY_DEFAULT));
        int opcount = Integer.parseInt(p.getProperty(Client.OPERATION_COUNT_PROPERTY));
        // 2 is fudge factor
        int expectednewkeys = (int) ((opcount) * insertproportion * 2.0);
        keychooser = new ScrambledZipfianGenerator(insertstart, insertstart + insertcount + expectednewkeys);
    } else if (requestdistrib.compareTo("latest") == 0) {
        keychooser = new SkewedLatestGenerator(transactioninsertkeysequence);
    } else if (requestdistrib.equals("hotspot")) {
        double hotsetfraction = Double.parseDouble(p.getProperty(HOTSPOT_DATA_FRACTION, HOTSPOT_DATA_FRACTION_DEFAULT));
        double hotopnfraction = Double.parseDouble(p.getProperty(HOTSPOT_OPN_FRACTION, HOTSPOT_OPN_FRACTION_DEFAULT));
        keychooser = new HotspotIntegerGenerator(insertstart, insertstart + insertcount - 1, hotsetfraction, hotopnfraction);
    } else {
        throw new WorkloadException("Unknown request distribution \"" + requestdistrib + "\"");
    }
    fieldchooser = new UniformLongGenerator(0, fieldcount - 1);
    if (scanlengthdistrib.compareTo("uniform") == 0) {
        scanlength = new UniformLongGenerator(minscanlength, maxscanlength);
    } else if (scanlengthdistrib.compareTo("zipfian") == 0) {
        scanlength = new ZipfianGenerator(minscanlength, maxscanlength);
    } else {
        throw new WorkloadException("Distribution \"" + scanlengthdistrib + "\" not allowed for scan length");
    }
    insertionRetryLimit = Integer.parseInt(p.getProperty(INSERTION_RETRY_LIMIT, INSERTION_RETRY_LIMIT_DEFAULT));
    insertionRetryInterval = Integer.parseInt(p.getProperty(INSERTION_RETRY_INTERVAL, INSERTION_RETRY_INTERVAL_DEFAULT));
}
Also used : UniformLongGenerator(site.ycsb.generator.UniformLongGenerator)

Example 2 with UniformLongGenerator

use of site.ycsb.generator.UniformLongGenerator in project YCSB by brianfrankcooper.

the class TimeSeriesWorkload method init.

@Override
public void init(final Properties p) throws WorkloadException {
    properties = p;
    recordcount = Integer.parseInt(p.getProperty(Client.RECORD_COUNT_PROPERTY, Client.DEFAULT_RECORD_COUNT));
    if (recordcount == 0) {
        recordcount = Integer.MAX_VALUE;
    }
    timestampKey = p.getProperty(TIMESTAMP_KEY_PROPERTY, TIMESTAMP_KEY_PROPERTY_DEFAULT);
    valueKey = p.getProperty(VALUE_KEY_PROPERTY, VALUE_KEY_PROPERTY_DEFAULT);
    operationchooser = CoreWorkload.createOperationGenerator(properties);
    final int maxscanlength = Integer.parseInt(p.getProperty(CoreWorkload.MAX_SCAN_LENGTH_PROPERTY, CoreWorkload.MAX_SCAN_LENGTH_PROPERTY_DEFAULT));
    String scanlengthdistrib = p.getProperty(CoreWorkload.SCAN_LENGTH_DISTRIBUTION_PROPERTY, CoreWorkload.SCAN_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT);
    if (scanlengthdistrib.compareTo("uniform") == 0) {
        scanlength = new UniformLongGenerator(1, maxscanlength);
    } else if (scanlengthdistrib.compareTo("zipfian") == 0) {
        scanlength = new ZipfianGenerator(1, maxscanlength);
    } else {
        throw new WorkloadException("Distribution \"" + scanlengthdistrib + "\" not allowed for scan length");
    }
    randomizeTimestampOrder = Boolean.parseBoolean(p.getProperty(RANDOMIZE_TIMESTAMP_ORDER_PROPERTY, RANDOMIZE_TIMESTAMP_ORDER_PROPERTY_DEFAULT));
    randomizeTimeseriesOrder = Boolean.parseBoolean(p.getProperty(RANDOMIZE_TIMESERIES_ORDER_PROPERTY, RANDOMIZE_TIMESERIES_ORDER_PROPERTY_DEFAULT));
    // setup the cardinality
    numKeys = Integer.parseInt(p.getProperty(CoreWorkload.FIELD_COUNT_PROPERTY, CoreWorkload.FIELD_COUNT_PROPERTY_DEFAULT));
    tagPairs = Integer.parseInt(p.getProperty(TAG_COUNT_PROPERTY, TAG_COUNT_PROPERTY_DEFAULT));
    sparsity = Double.parseDouble(p.getProperty(SPARSITY_PROPERTY, SPARSITY_PROPERTY_DEFAULT));
    tagCardinality = new int[tagPairs];
    final String requestdistrib = p.getProperty(CoreWorkload.REQUEST_DISTRIBUTION_PROPERTY, CoreWorkload.REQUEST_DISTRIBUTION_PROPERTY_DEFAULT);
    if (requestdistrib.compareTo("uniform") == 0) {
        keychooser = new UniformLongGenerator(0, numKeys - 1);
    } else if (requestdistrib.compareTo("sequential") == 0) {
        keychooser = new SequentialGenerator(0, numKeys - 1);
    } else if (requestdistrib.compareTo("zipfian") == 0) {
        keychooser = new ScrambledZipfianGenerator(0, numKeys - 1);
    // } else if (requestdistrib.compareTo("latest") == 0) {
    // keychooser = new SkewedLatestGenerator(transactioninsertkeysequence);
    } else if (requestdistrib.equals("hotspot")) {
        double hotsetfraction = Double.parseDouble(p.getProperty(CoreWorkload.HOTSPOT_DATA_FRACTION, CoreWorkload.HOTSPOT_DATA_FRACTION_DEFAULT));
        double hotopnfraction = Double.parseDouble(p.getProperty(CoreWorkload.HOTSPOT_OPN_FRACTION, CoreWorkload.HOTSPOT_OPN_FRACTION_DEFAULT));
        keychooser = new HotspotIntegerGenerator(0, numKeys - 1, hotsetfraction, hotopnfraction);
    } else {
        throw new WorkloadException("Unknown request distribution \"" + requestdistrib + "\"");
    }
    // figure out the start timestamp based on the units, cardinality and interval
    try {
        timestampInterval = Integer.parseInt(p.getProperty(TIMESTAMP_INTERVAL_PROPERTY, TIMESTAMP_INTERVAL_PROPERTY_DEFAULT));
    } catch (NumberFormatException nfe) {
        throw new WorkloadException("Unable to parse the " + TIMESTAMP_INTERVAL_PROPERTY, nfe);
    }
    try {
        timeUnits = TimeUnit.valueOf(p.getProperty(TIMESTAMP_UNITS_PROPERTY, TIMESTAMP_UNITS_PROPERTY_DEFAULT).toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new WorkloadException("Unknown time unit type", e);
    }
    if (timeUnits == TimeUnit.NANOSECONDS || timeUnits == TimeUnit.MICROSECONDS) {
        throw new WorkloadException("YCSB doesn't support " + timeUnits + " at this time.");
    }
    tagPairDelimiter = p.getProperty(PAIR_DELIMITER_PROPERTY, PAIR_DELIMITER_PROPERTY_DEFAULT);
    deleteDelimiter = p.getProperty(DELETE_DELIMITER_PROPERTY, DELETE_DELIMITER_PROPERTY_DEFAULT);
    dataintegrity = Boolean.parseBoolean(p.getProperty(CoreWorkload.DATA_INTEGRITY_PROPERTY, CoreWorkload.DATA_INTEGRITY_PROPERTY_DEFAULT));
    if (dataintegrity) {
        System.out.println("Data integrity is enabled.");
    }
    queryTimeSpan = Integer.parseInt(p.getProperty(QUERY_TIMESPAN_PROPERTY, QUERY_TIMESPAN_PROPERTY_DEFAULT));
    queryRandomTimeSpan = Boolean.parseBoolean(p.getProperty(QUERY_RANDOM_TIMESPAN_PROPERTY, QUERY_RANDOM_TIMESPAN_PROPERTY_DEFAULT));
    queryTimeSpanDelimiter = p.getProperty(QUERY_TIMESPAN_DELIMITER_PROPERTY, QUERY_TIMESPAN_DELIMITER_PROPERTY_DEFAULT);
    groupByKey = p.getProperty(GROUPBY_KEY_PROPERTY, GROUPBY_KEY_PROPERTY_DEFAULT);
    groupByFunction = p.getProperty(GROUPBY_PROPERTY);
    if (groupByFunction != null && !groupByFunction.isEmpty()) {
        final String groupByKeys = p.getProperty(GROUPBY_KEYS_PROPERTY);
        if (groupByKeys == null || groupByKeys.isEmpty()) {
            throw new WorkloadException("Group by was enabled but no keys were specified.");
        }
        final String[] gbKeys = groupByKeys.split(",");
        if (gbKeys.length != tagKeys.length) {
            throw new WorkloadException("Only " + gbKeys.length + " group by keys " + "were specified but there were " + tagKeys.length + " tag keys given.");
        }
        groupBys = new boolean[gbKeys.length];
        for (int i = 0; i < gbKeys.length; i++) {
            groupBys[i] = Integer.parseInt(gbKeys[i].trim()) == 0 ? false : true;
        }
        groupBy = true;
    }
    downsampleKey = p.getProperty(DOWNSAMPLING_KEY_PROPERTY, DOWNSAMPLING_KEY_PROPERTY_DEFAULT);
    downsampleFunction = p.getProperty(DOWNSAMPLING_FUNCTION_PROPERTY);
    if (downsampleFunction != null && !downsampleFunction.isEmpty()) {
        final String interval = p.getProperty(DOWNSAMPLING_INTERVAL_PROPERTY);
        if (interval == null || interval.isEmpty()) {
            throw new WorkloadException("'" + DOWNSAMPLING_INTERVAL_PROPERTY + "' was missing despite '" + DOWNSAMPLING_FUNCTION_PROPERTY + "' being set.");
        }
        downsampleInterval = Integer.parseInt(interval);
        downsample = true;
    }
    delayedSeries = Double.parseDouble(p.getProperty(DELAYED_SERIES_PROPERTY, DELAYED_SERIES_PROPERTY_DEFAULT));
    delayedIntervals = Integer.parseInt(p.getProperty(DELAYED_INTERVALS_PROPERTY, DELAYED_INTERVALS_PROPERTY_DEFAULT));
    valueType = ValueType.fromString(p.getProperty(VALUE_TYPE_PROPERTY, VALUE_TYPE_PROPERTY_DEFAULT));
    table = p.getProperty(CoreWorkload.TABLENAME_PROPERTY, CoreWorkload.TABLENAME_PROPERTY_DEFAULT);
    initKeysAndTags();
    validateSettings();
}
Also used : ScrambledZipfianGenerator(site.ycsb.generator.ScrambledZipfianGenerator) ZipfianGenerator(site.ycsb.generator.ZipfianGenerator) WorkloadException(site.ycsb.WorkloadException) UniformLongGenerator(site.ycsb.generator.UniformLongGenerator) SequentialGenerator(site.ycsb.generator.SequentialGenerator) ScrambledZipfianGenerator(site.ycsb.generator.ScrambledZipfianGenerator) HotspotIntegerGenerator(site.ycsb.generator.HotspotIntegerGenerator)

Example 3 with UniformLongGenerator

use of site.ycsb.generator.UniformLongGenerator in project YCSB by brianfrankcooper.

the class RestWorkload method getKeyChooser.

private static NumberGenerator getKeyChooser(String requestDistrib, int recordCount, double zipfContant, Properties p) throws WorkloadException {
    NumberGenerator keychooser;
    switch(requestDistrib) {
        case "exponential":
            double percentile = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_PERCENTILE_PROPERTY, ExponentialGenerator.EXPONENTIAL_PERCENTILE_DEFAULT));
            double frac = Double.parseDouble(p.getProperty(ExponentialGenerator.EXPONENTIAL_FRAC_PROPERTY, ExponentialGenerator.EXPONENTIAL_FRAC_DEFAULT));
            keychooser = new ExponentialGenerator(percentile, recordCount * frac);
            break;
        case "uniform":
            keychooser = new UniformLongGenerator(0, recordCount - 1);
            break;
        case "zipfian":
            keychooser = new ZipfianGenerator(recordCount, zipfContant);
            break;
        case "latest":
            throw new WorkloadException("Latest request distribution is not supported for RestWorkload.");
        case "hotspot":
            double hotsetfraction = Double.parseDouble(p.getProperty(HOTSPOT_DATA_FRACTION, HOTSPOT_DATA_FRACTION_DEFAULT));
            double hotopnfraction = Double.parseDouble(p.getProperty(HOTSPOT_OPN_FRACTION, HOTSPOT_OPN_FRACTION_DEFAULT));
            keychooser = new HotspotIntegerGenerator(0, recordCount - 1, hotsetfraction, hotopnfraction);
            break;
        default:
            throw new WorkloadException("Unknown request distribution \"" + requestDistrib + "\"");
    }
    return keychooser;
}
Also used : WorkloadException(site.ycsb.WorkloadException) UniformLongGenerator(site.ycsb.generator.UniformLongGenerator)

Aggregations

UniformLongGenerator (site.ycsb.generator.UniformLongGenerator)3 WorkloadException (site.ycsb.WorkloadException)2 HotspotIntegerGenerator (site.ycsb.generator.HotspotIntegerGenerator)1 ScrambledZipfianGenerator (site.ycsb.generator.ScrambledZipfianGenerator)1 SequentialGenerator (site.ycsb.generator.SequentialGenerator)1 ZipfianGenerator (site.ycsb.generator.ZipfianGenerator)1