Search in sources :

Example 1 with PartitionGenerator

use of org.apache.cassandra.stress.generate.PartitionGenerator in project cassandra by apache.

the class SampledOpDistributionFactory method get.

public OpDistribution get(boolean isWarmup, MeasurementSink sink) {
    PartitionGenerator generator = newGenerator();
    List<Pair<Operation, Double>> operations = new ArrayList<>();
    for (Map.Entry<T, Double> ratio : ratios.entrySet()) {
        List<? extends Operation> ops = get(new Timer(ratio.getKey().toString(), sink), generator, ratio.getKey(), isWarmup);
        for (Operation op : ops) operations.add(new Pair<>(op, ratio.getValue() / ops.size()));
    }
    return new SampledOpDistribution(new EnumeratedDistribution<>(operations), clustering.get());
}
Also used : PartitionGenerator(org.apache.cassandra.stress.generate.PartitionGenerator) ArrayList(java.util.ArrayList) Operation(org.apache.cassandra.stress.Operation) Timer(org.apache.cassandra.stress.report.Timer) Map(java.util.Map) Pair(org.apache.commons.math3.util.Pair)

Example 2 with PartitionGenerator

use of org.apache.cassandra.stress.generate.PartitionGenerator in project cassandra by apache.

the class SettingsCommandUser method getFactory.

public OpDistributionFactory getFactory(final StressSettings settings) {
    final SeedManager seeds = new SeedManager(settings);
    final Map<String, TokenRangeIterator> tokenRangeIterators = new LinkedHashMap<>();
    profiles.forEach((k, v) -> tokenRangeIterators.put(k, (v.tokenRangeQueries.isEmpty() ? null : new TokenRangeIterator(settings, v.maybeLoadTokenRanges(settings)))));
    return new SampledOpDistributionFactory<String>(ratios, clustering) {

        protected List<? extends Operation> get(Timer timer, String key, boolean isWarmup) {
            Matcher m = EXTRACT_SPEC_CMD.matcher(key);
            final String profile_name;
            final String sub_key;
            if (m.matches()) {
                profile_name = m.group(1);
                sub_key = m.group(2);
            } else {
                profile_name = default_profile_name;
                sub_key = key;
            }
            if (!profiles.containsKey(profile_name)) {
                throw new IllegalArgumentException(String.format("Op name %s contains an invalid profile specname: %s", key, profile_name));
            }
            StressProfile profile = profiles.get(profile_name);
            TokenRangeIterator tokenRangeIterator = tokenRangeIterators.get(profile_name);
            PartitionGenerator generator = profile.newGenerator(settings);
            if (sub_key.equalsIgnoreCase("insert"))
                return Collections.singletonList(profile.getInsert(timer, generator, seeds, settings));
            if (sub_key.equalsIgnoreCase("validate"))
                return profile.getValidate(timer, generator, seeds, settings);
            if (profile.tokenRangeQueries.containsKey(sub_key))
                return Collections.singletonList(profile.getBulkReadQueries(sub_key, timer, settings, tokenRangeIterator, isWarmup));
            return Collections.singletonList(profile.getQuery(sub_key, timer, generator, seeds, settings, isWarmup));
        }
    };
}
Also used : StressProfile(org.apache.cassandra.stress.StressProfile) Timer(org.apache.cassandra.stress.report.Timer) PartitionGenerator(org.apache.cassandra.stress.generate.PartitionGenerator) Matcher(java.util.regex.Matcher) TokenRangeIterator(org.apache.cassandra.stress.generate.TokenRangeIterator) SeedManager(org.apache.cassandra.stress.generate.SeedManager) SampledOpDistributionFactory(org.apache.cassandra.stress.operations.SampledOpDistributionFactory) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with PartitionGenerator

use of org.apache.cassandra.stress.generate.PartitionGenerator in project cassandra by apache.

the class SettingsCommandPreDefined method newGenerator.

PartitionGenerator newGenerator(StressSettings settings) {
    List<String> names = settings.columns.namestrs;
    List<Generator> partitionKey = Collections.<Generator>singletonList(new HexBytes("key", new GeneratorConfig("randomstrkey", null, OptionDistribution.get("fixed(" + keySize + ")"), null)));
    List<Generator> columns = new ArrayList<>();
    for (int i = 0; i < settings.columns.maxColumnsPerKey; i++) columns.add(new Bytes(names.get(i), new GeneratorConfig("randomstr" + names.get(i), null, settings.columns.sizeDistribution, null)));
    return new PartitionGenerator(partitionKey, Collections.<Generator>emptyList(), columns, PartitionGenerator.Order.ARBITRARY);
}
Also used : HexBytes(org.apache.cassandra.stress.generate.values.HexBytes) Bytes(org.apache.cassandra.stress.generate.values.Bytes) PartitionGenerator(org.apache.cassandra.stress.generate.PartitionGenerator) ArrayList(java.util.ArrayList) HexBytes(org.apache.cassandra.stress.generate.values.HexBytes) GeneratorConfig(org.apache.cassandra.stress.generate.values.GeneratorConfig) PartitionGenerator(org.apache.cassandra.stress.generate.PartitionGenerator) Generator(org.apache.cassandra.stress.generate.values.Generator)

Aggregations

PartitionGenerator (org.apache.cassandra.stress.generate.PartitionGenerator)3 ArrayList (java.util.ArrayList)2 Timer (org.apache.cassandra.stress.report.Timer)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Operation (org.apache.cassandra.stress.Operation)1 StressProfile (org.apache.cassandra.stress.StressProfile)1 SeedManager (org.apache.cassandra.stress.generate.SeedManager)1 TokenRangeIterator (org.apache.cassandra.stress.generate.TokenRangeIterator)1 Bytes (org.apache.cassandra.stress.generate.values.Bytes)1 Generator (org.apache.cassandra.stress.generate.values.Generator)1 GeneratorConfig (org.apache.cassandra.stress.generate.values.GeneratorConfig)1 HexBytes (org.apache.cassandra.stress.generate.values.HexBytes)1 SampledOpDistributionFactory (org.apache.cassandra.stress.operations.SampledOpDistributionFactory)1 Pair (org.apache.commons.math3.util.Pair)1