-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-9291 Benchmarks for sorted sets (#158)
Basic ZADD and ZRANGE benchmarks for redis sorted sets.
- Loading branch information
Showing
12 changed files
with
323 additions
and
14 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
40 changes: 40 additions & 0 deletions
40
...marks/src/main/java/org/apache/geode/benchmark/redis/tasks/PrePopulateRedisSortedSet.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.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 org.apache.geode.benchmark.LongRange; | ||
|
||
public class PrePopulateRedisSortedSet extends AbstractPrePopulate { | ||
|
||
public PrePopulateRedisSortedSet( | ||
final RedisClientManager redisClientManager, | ||
final LongRange keyRangeToPrepopulate) { | ||
super(redisClientManager, keyRangeToPrepopulate); | ||
} | ||
|
||
@Override | ||
protected void prepopulate(final RedisClient redisClient, final long key) { | ||
final long score = toPart(key); | ||
final String value = valueOf(score); | ||
redisClient.zadd(valueOf(toKey(key)), score, value); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
geode-benchmarks/src/main/java/org/apache/geode/benchmark/redis/tasks/ZaddRedisTask.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,68 @@ | ||
/* | ||
* 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.toPart; | ||
import static org.apache.geode.benchmark.redis.tasks.RedisSplitKey.toKey; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yardstickframework.BenchmarkConfiguration; | ||
import org.yardstickframework.BenchmarkDriverAdapter; | ||
|
||
import org.apache.geode.benchmark.LongRange; | ||
|
||
public class ZaddRedisTask extends BenchmarkDriverAdapter implements Serializable { | ||
private static final Logger logger = LoggerFactory.getLogger(ZaddRedisTask.class); | ||
|
||
private final RedisClientManager redisClientManager; | ||
private final LongRange keyRange; | ||
|
||
private transient LongStringCache keyCache; | ||
private transient RedisClient redisClient; | ||
|
||
public ZaddRedisTask(final RedisClientManager redisClientManager, final LongRange keyRange) { | ||
logger.info("Initialized: keyRange={}", keyRange); | ||
this.redisClientManager = redisClientManager; | ||
this.keyRange = keyRange; | ||
} | ||
|
||
@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 score = toPart(k); | ||
final String value = keyCache.valueOf(score); | ||
redisClient.zadd(key, score, value); | ||
return true; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
geode-benchmarks/src/main/java/org/apache/geode/benchmark/redis/tasks/ZrangeRedisTask.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,91 @@ | ||
/* | ||
* 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 ZrangeRedisTask extends BenchmarkDriverAdapter implements Serializable { | ||
private static final Logger logger = LoggerFactory.getLogger(ZrangeRedisTask.class); | ||
|
||
private final RedisClientManager redisClientManager; | ||
private final LongRange keyRange; | ||
private final boolean validate; | ||
|
||
private transient LongStringCache keyCache; | ||
private transient RedisClient redisClient; | ||
|
||
public ZrangeRedisTask(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.zrange(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; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...e-benchmarks/src/main/java/org/apache/geode/benchmark/redis/tests/RedisZaddBenchmark.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,41 @@ | ||
/* | ||
* 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.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; | ||
|
||
public class RedisZaddBenchmark extends RedisBenchmark { | ||
|
||
@Override | ||
public TestConfig configure() { | ||
final TestConfig config = super.configure(); | ||
|
||
before(config, new PrePopulateRedisSortedSet(redisClientManager, keyRange), CLIENT); | ||
workload(config, new ZaddRedisTask(redisClientManager, keyRange), | ||
CLIENT); | ||
return config; | ||
} | ||
} |
Oops, something went wrong.