Skip to content
Permalink
Browse files
Add *LongBenchmark (#110)
Add prefill and benchmarks using Longs
  • Loading branch information
kamilla1201 authored and nonbinaryprogrammer committed Sep 12, 2019
1 parent 873ee68 commit bffbb225038e838413b4a7218668d249f0404c55
Showing 14 changed files with 866 additions and 0 deletions.
@@ -0,0 +1,114 @@
/*
* 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.tasks;

import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.LOCATOR;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.perftest.Task;
import org.apache.geode.perftest.TestContext;


public class PrePopulateRegionLong implements Task {
private static final Logger logger = LoggerFactory.getLogger(PrePopulateRegionLong.class);

private LongRange keyRangeToPrepopulate = new LongRange(0, 10000);
private int batchSize = 1000;

public PrePopulateRegionLong() {}

public PrePopulateRegionLong(LongRange keyRangeToPrepopulate) {
this.keyRangeToPrepopulate = keyRangeToPrepopulate;
}

/**
* This method prepopulates the region before the actual benchmark starts.
*/
@Override
public void run(TestContext context) throws InterruptedException {
final ClientCache cache = ClientCacheFactory.getAnyInstance();
final Region<Long, Long> region = cache.getRegion("region");
final int numLocators = context.getHostsIDsForRole(LOCATOR).size();
final int numServers = context.getHostsIDsForRole(SERVER).size();
final int numClient = context.getHostsIDsForRole(CLIENT).size();
final int jvmID = context.getJvmID();
final int clientIndex = jvmID - numLocators - numServers;

run(region, keyRangeToPrepopulate.sliceFor(numClient, clientIndex));
}

void run(final Map<Long, Long> region, final LongRange range) throws InterruptedException {
logger.info("*******************************************");
logger.info(" Prepopulating the region ");
logger.info("*******************************************");
final Instant start = Instant.now();

final int numThreads = Runtime.getRuntime().availableProcessors();
final ExecutorService threadPool = Executors.newFixedThreadPool(numThreads);
final List<CompletableFuture<Void>> futures = new ArrayList<>();

for (final LongRange slice : range.slice(numThreads)) {
futures.add(CompletableFuture.runAsync(() -> doPuts(region, slice), threadPool));
}

futures.forEach(CompletableFuture::join);

final Instant finish = Instant.now();
logger.info("*******************************************");
logger.info(" Prepopulating the region completed");
logger.info(" Duration = " + Duration.between(start, finish).toMillis() + "ms.");
logger.info("*******************************************");

threadPool.shutdownNow();
threadPool.awaitTermination(5, TimeUnit.MINUTES);
}

private void doPuts(final Map<Long, Long> region, final LongRange range) {
for (final LongRange slice : range.slicesOfSize(batchSize)) {
final Map<Long, Long> valueMap = new HashMap<>();
slice.forEach(i -> valueMap.put(i, i));
region.putAll(valueMap);
}
}

public int getBatchSize() {
return batchSize;
}

public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
}
}
@@ -0,0 +1,65 @@
/*
* 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.tests;


import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreatePartitionedRegion;
import org.apache.geode.benchmark.tasks.GetTask;
import org.apache.geode.benchmark.tasks.PrePopulateRegionLong;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

/**
* Benchmark of gets on a partitioned region.
*/
public class PartitionedGetLongBenchmark implements PerformanceTest {

private LongRange keyRange = new LongRange(0, 1000000);

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

public PartitionedGetLongBenchmark() {}

public void setKeyRange(final LongRange keyRange) {
this.keyRange = keyRange;
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
ClientServerTopology.configure(config);
config.before(new CreatePartitionedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegionLong(keyRange), CLIENT);
config.workload(new GetTask(keyRange), CLIENT);
return config;

}
}
@@ -0,0 +1,66 @@
/*
* 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.tests;

import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreatePartitionedRegion;
import org.apache.geode.benchmark.tasks.PrePopulateRegionLong;
import org.apache.geode.benchmark.tasks.PutAllTask;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

/**
* Benchmark of putAlls on a partitioned region.
*/
public class PartitionedPutAllLongBenchmark implements PerformanceTest {

private LongRange keyRange = new LongRange(0, 1000000);

private int batchSize = 1000;

public PartitionedPutAllLongBenchmark() {}

public void setKeyRange(final LongRange keyRange) {
this.keyRange = keyRange;
}

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
config.threads(Runtime.getRuntime().availableProcessors() * 2);
ClientServerTopology.configure(config);
config.before(new CreatePartitionedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegionLong(keyRange), CLIENT);
config.workload(new PutAllTask(keyRange, batchSize), CLIENT);
return config;
}
}
@@ -0,0 +1,64 @@
/*
* 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.tests;

import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreatePartitionedRegion;
import org.apache.geode.benchmark.tasks.PrePopulateRegionLong;
import org.apache.geode.benchmark.tasks.PutTask;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

/**
* Benchmark of puts on a partitioned region.
*/
public class PartitionedPutLongBenchmark implements PerformanceTest {

private LongRange keyRange = new LongRange(0, 1000000);

public PartitionedPutLongBenchmark() {}

public void setKeyRange(final LongRange keyRange) {
this.keyRange = keyRange;
}

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
ClientServerTopology.configure(config);
config.before(new CreatePartitionedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegionLong(keyRange), CLIENT);
config.workload(new PutTask(keyRange), CLIENT);
return config;

}
}
@@ -0,0 +1,65 @@
/*
* 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.tests;


import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.CLIENT;
import static org.apache.geode.benchmark.topology.ClientServerTopology.Roles.SERVER;

import org.junit.jupiter.api.Test;

import org.apache.geode.benchmark.LongRange;
import org.apache.geode.benchmark.tasks.CreateClientProxyRegion;
import org.apache.geode.benchmark.tasks.CreateReplicatedRegion;
import org.apache.geode.benchmark.tasks.GetTask;
import org.apache.geode.benchmark.tasks.PrePopulateRegionLong;
import org.apache.geode.benchmark.topology.ClientServerTopology;
import org.apache.geode.perftest.PerformanceTest;
import org.apache.geode.perftest.TestConfig;
import org.apache.geode.perftest.TestRunners;

/**
* Benchmark of gets on a replicated region.
*/
public class ReplicatedGetLongBenchmark implements PerformanceTest {

private LongRange keyRange = new LongRange(0, 1000000);

@Test
public void run() throws Exception {
TestRunners.defaultRunner().runTest(this);
}

public ReplicatedGetLongBenchmark() {}

public void setKeyRange(final LongRange keyRange) {
this.keyRange = keyRange;
}

@Override
public TestConfig configure() {
TestConfig config = GeodeBenchmark.createConfig();
ClientServerTopology.configure(config);
config.before(new CreateReplicatedRegion(), SERVER);
config.before(new CreateClientProxyRegion(), CLIENT);
config.before(new PrePopulateRegionLong(keyRange), CLIENT);
config.workload(new GetTask(keyRange), CLIENT);
return config;

}
}

0 comments on commit bffbb22

Please sign in to comment.