Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-9291 sorted set benchmarks - more benchmarks (#159)
- Added benchmarks for ZRangeByScore and mixed ZAdd and ZRange operations
- Loading branch information
Showing
13 changed files
with
199 additions
and
9 deletions.
There are no files selected for viewing
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
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
92 changes: 92 additions & 0 deletions
92
...nchmarks/src/main/java/org/apache/geode/benchmark/redis/tasks/ZrangeByScoreRedisTask.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,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; | ||
} | ||
|
||
} |
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
46 changes: 46 additions & 0 deletions
46
...main/java/org/apache/geode/benchmark/redis/tests/RedisWeightedZaddAndZrangeBenchmark.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,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; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
...rks/src/main/java/org/apache/geode/benchmark/redis/tests/RedisZrangeByScoreBenchmark.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,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; | ||
} | ||
} |