Skip to content

Commit

Permalink
GEODE-9291 sorted set benchmarks - more benchmarks (#159)
Browse files Browse the repository at this point in the history
 - Added benchmarks for ZRangeByScore and mixed ZAdd and ZRange operations
  • Loading branch information
ezoerner committed Oct 29, 2021
1 parent 6f9b9c8 commit 4e6fa33
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 9 deletions.
Expand Up @@ -17,8 +17,8 @@

package org.apache.geode.benchmark.redis.tasks;

import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
Expand Down
Expand Up @@ -18,8 +18,8 @@
package org.apache.geode.benchmark.redis.tasks;


import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;

import java.io.Serializable;
import java.util.Map;
Expand Down
Expand Up @@ -58,7 +58,7 @@ public boolean hset(final String key, final String field, final String value) {
}

@Override
public long zadd(String key, double score, String value) {
public long zadd(String key, double score, String value) {
return jedisCluster.zadd(key, score, value);
}

Expand All @@ -67,6 +67,11 @@ public Set<String> zrange(String key, long start, long stop) {
return jedisCluster.zrange(key, start, stop);
}

@Override
public Set<String> zrangeByScore(String key, long start, long stop) {
return jedisCluster.zrangeByScore(key, start, stop);
}

@Override
public void flushdb() {
Set<String> seen = new HashSet<>();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.Set;
import java.util.stream.Collectors;

import io.lettuce.core.Range;
import io.lettuce.core.ReadFrom;
import io.lettuce.core.RedisURI;
import io.lettuce.core.cluster.RedisClusterClient;
Expand Down Expand Up @@ -79,6 +80,12 @@ public Set<String> zrange(String key, long start, long stop) {
return new HashSet<>(redisAdvancedClusterCommands.get().zrange(key, start, stop));
}

@Override
public Set<String> zrangeByScore(String key, long start, long stop) {
return new HashSet<>(
redisAdvancedClusterCommands.get().zrangebyscore(key, Range.create(start, stop)));
}

@Override
public void flushdb() {
redisAdvancedClusterCommands.get().flushdb();
Expand Down
Expand Up @@ -18,8 +18,8 @@
package org.apache.geode.benchmark.redis.tasks;

import static java.lang.String.valueOf;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;

import org.apache.geode.benchmark.LongRange;

Expand Down
Expand Up @@ -18,8 +18,8 @@
package org.apache.geode.benchmark.redis.tasks;

import static java.lang.String.valueOf;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;

import org.apache.geode.benchmark.LongRange;

Expand Down
Expand Up @@ -31,4 +31,6 @@ public interface RedisClient {
long zadd(String key, double score, String value);

Set<String> zrange(String key, long start, long stop);

Set<String> zrangeByScore(String key, long start, long stop);
}
Expand Up @@ -18,8 +18,8 @@
package org.apache.geode.benchmark.redis.tasks;


import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toPart;

import java.io.Serializable;
import java.util.Map;
Expand Down
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.geode.benchmark.redis.tasks;

import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yardstickframework.BenchmarkConfiguration;
import org.yardstickframework.BenchmarkDriverAdapter;

import org.apache.geode.benchmark.LongRange;

public class ZrangeByScoreRedisTask extends BenchmarkDriverAdapter implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(ZrangeByScoreRedisTask.class);

private final RedisClientManager redisClientManager;
private final LongRange keyRange;
private final boolean validate;

private transient LongStringCache keyCache;
private transient RedisClient redisClient;

public ZrangeByScoreRedisTask(final RedisClientManager redisClientManager,
final LongRange keyRange,
final boolean validate) {
logger.info("Initialized: keyRange={}, validate={}", keyRange, validate);
this.redisClientManager = redisClientManager;
this.keyRange = keyRange;
this.validate = validate;
}

@Override
public void setUp(final BenchmarkConfiguration cfg) throws Exception {
super.setUp(cfg);

keyCache = new LongStringCache(keyRange);
redisClient = redisClientManager.get();
}

@Override
public boolean test(final Map<Object, Object> ctx) throws Exception {
final long k = keyRange.random();

final String key = keyCache.valueOf(toKey(k));

final long start = ThreadLocalRandom.current()
.nextLong(0, RedisSplitKey.NUM_PARTS_PER_KEY);
final long len = ThreadLocalRandom.current()
.nextLong(0, RedisSplitKey.NUM_PARTS_PER_KEY - start);
final long stop = start + len;

final Set<String> values = redisClient.zrangeByScore(key, start, stop);
if (validate) {
final LongRange range =
new LongRange(start, stop);

final Set<String> expectedValues =
LongStream.range(range.getMin(), range.getMax())
.boxed()
.map(keyCache::valueOf)
.collect(Collectors.toSet());

assertThat(values).isEqualTo(expectedValues);
}
return true;
}

}
Expand Up @@ -45,7 +45,7 @@ public class ZrangeRedisTask extends BenchmarkDriverAdapter implements Serializa
private transient RedisClient redisClient;

public ZrangeRedisTask(final RedisClientManager redisClientManager, final LongRange keyRange,
final boolean validate) {
final boolean validate) {
logger.info("Initialized: keyRange={}, validate={}", keyRange, validate);
this.redisClientManager = redisClientManager;
this.keyRange = keyRange;
Expand Down
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.geode.benchmark.redis.tests;

import static org.apache.geode.benchmark.Config.before;
import static org.apache.geode.benchmark.Config.workload;
import static org.apache.geode.benchmark.topology.Roles.CLIENT;

import org.apache.geode.benchmark.redis.tasks.PrePopulateRedisHash;
import org.apache.geode.benchmark.redis.tasks.PrePopulateRedisSortedSet;
import org.apache.geode.benchmark.redis.tasks.ZaddRedisTask;
import org.apache.geode.benchmark.redis.tasks.ZrangeRedisTask;
import org.apache.geode.benchmark.tasks.WeightedTasks;
import org.apache.geode.benchmark.tasks.WeightedTasks.WeightedTask;
import org.apache.geode.perftest.TestConfig;

public class RedisWeightedZaddAndZrangeBenchmark extends RedisBenchmark {

@Override
public TestConfig configure() {
final TestConfig config = super.configure();

before(config, new PrePopulateRedisSortedSet(redisClientManager, keyRange), CLIENT);

workload(config, new WeightedTasks(
new WeightedTask(20, new ZaddRedisTask(redisClientManager, keyRange)),
new WeightedTask(80, new ZrangeRedisTask(redisClientManager, keyRange, false))), CLIENT);

return config;
}
}
Expand Up @@ -21,8 +21,6 @@
import static org.apache.geode.benchmark.Config.workload;
import static org.apache.geode.benchmark.topology.Roles.CLIENT;

import org.apache.geode.benchmark.redis.tasks.HsetRedisTask;
import org.apache.geode.benchmark.redis.tasks.PrePopulateRedisHash;
import org.apache.geode.benchmark.redis.tasks.PrePopulateRedisSortedSet;
import org.apache.geode.benchmark.redis.tasks.ZaddRedisTask;
import org.apache.geode.perftest.TestConfig;
Expand Down
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.geode.benchmark.redis.tests;

import static org.apache.geode.benchmark.Config.before;
import static org.apache.geode.benchmark.Config.workload;
import static org.apache.geode.benchmark.topology.Roles.CLIENT;

import org.apache.geode.benchmark.redis.tasks.PrePopulateRedisSortedSet;
import org.apache.geode.benchmark.redis.tasks.ZrangeByScoreRedisTask;
import org.apache.geode.perftest.TestConfig;

public class RedisZrangeByScoreBenchmark extends RedisBenchmark {

@Override
public TestConfig configure() {
final TestConfig config = super.configure();

before(config, new PrePopulateRedisSortedSet(redisClientManager, keyRange), CLIENT);
workload(config,
new ZrangeByScoreRedisTask(redisClientManager, keyRange, isValidationEnabled()),
CLIENT);
return config;
}
}

0 comments on commit 4e6fa33

Please sign in to comment.