Skip to content

Commit

Permalink
Add Client based perf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wburns committed Jun 28, 2023
1 parent 11d07de commit 933a246
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 32 deletions.
2 changes: 0 additions & 2 deletions getputremovetest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
<version>7.7.0</version>
</dependency>

<!--
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-hotrod</artifactId>
Expand All @@ -91,7 +90,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
<artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
</dependency>
-->
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.infinispan;

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.impl.ConfigurationProperties;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.server.hotrod.HotRodServer;
import org.infinispan.server.hotrod.configuration.HotRodServerConfiguration;
import org.infinispan.server.hotrod.configuration.HotRodServerConfigurationBuilder;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;

@State(Scope.Benchmark)
public class InfinispanRemoteHolder {

private static final AtomicInteger hotRodPort = new AtomicInteger(ConfigurationProperties.DEFAULT_HOTROD_PORT);

static final String cfg = System.getProperty( "infinispan.cfg", "dist-sync.xml" );

private final LongAdder gets = new LongAdder();
private final LongAdder puts = new LongAdder();
private final LongAdder removes = new LongAdder();

private final AtomicInteger cacheRequestCount = new AtomicInteger();

private DefaultCacheManager[] mgrs;
private RemoteCacheManager[] remotes;
private RemoteCache<?, ?>[] caches;

private HotRodServer[] servers;

@Param("3")
private int nodes;

@Param({"1", "3"})
private int remoteClients;

@Param({"-1"})
int maxPoolSize = -1;

@Setup
public void initializeState() throws IOException {
mgrs = new DefaultCacheManager[nodes];
servers = new HotRodServer[nodes];
remotes = new RemoteCacheManager[remoteClients];
caches = new RemoteCache[remoteClients];
HotRodServerConfiguration firstConfig = null;

for (int i = 0; i < nodes; ++i) {
mgrs[i] = new DefaultCacheManager(cfg);
HotRodServerConfigurationBuilder configurationBuilder = new HotRodServerConfigurationBuilder();
configurationBuilder.port(hotRodPort.getAndIncrement());
HotRodServerConfiguration hotRodServerConfiguration = configurationBuilder.build();
if (firstConfig == null) {
firstConfig = hotRodServerConfiguration;
}
servers[i] = new HotRodServer();
servers[i].start(hotRodServerConfiguration, mgrs[i]);
System.out.printf("Started server %d\n", hotRodServerConfiguration.port());
}

ConfigurationBuilder remoteCacheConfigurationBuilder = new ConfigurationBuilder();
remoteCacheConfigurationBuilder.connectionPool().maxActive(maxPoolSize);
remoteCacheConfigurationBuilder.addServer().host(firstConfig.host()).port(firstConfig.port());
for (int i = 0; i < remoteClients; ++i) {
remotes[i] = new RemoteCacheManager(remoteCacheConfigurationBuilder.build());
caches[i] = remotes[i].getCache();
}
}

@TearDown
public void shutdownState() {
Arrays.stream(servers).forEach(HotRodServer::stop);
Arrays.stream(mgrs).forEach(DefaultCacheManager::stop);
System.out.println( "Gets performed: " + gets.longValue() );
System.out.println( "Puts performed: " + puts.longValue() );
System.out.println( "Removes performed: " + removes.longValue() );
}

public RemoteCache getCache() {
int offset = cacheRequestCount.getAndIncrement();
return caches[offset % caches.length];
}

public void cacheGetDone() {
gets.increment();
}

public void cachePutDone() {
puts.increment();
}

public void cacheRemoveDone() {
removes.increment();
}
}

61 changes: 31 additions & 30 deletions getputremovetest/src/main/java/org/infinispan/JMHBenchmarks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.infinispan;

import org.infinispan.client.hotrod.RemoteCache;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -23,36 +24,36 @@
@BenchmarkMode(Mode.Throughput)
public class JMHBenchmarks {

// @Benchmark
// @GroupThreads(2)
// @Group("getPutHotRod")
// public void infinispanRemoteRemove(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
// Object key = kg.getNextKey();
// RemoteCache cache = ih.getCache();
// bh.consume( cache.remove( key) );
// ih.cacheRemoveDone();
// }
//
// @Benchmark
// @GroupThreads(4)
// @Group("getPutHotRod")
// public void infinispanRemotePut(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
// Object key = kg.getNextKey();
// Object value = kg.getNextValue();
// RemoteCache cache = ih.getCache();
// bh.consume( cache.put( key, value ) );
// ih.cachePutDone();
// }
//
// @Benchmark
// @GroupThreads(16)
// @Group("getPutHotRod")
// public void infinispanRemoteGet(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
// Object key = kg.getNextKey();
// RemoteCache cache = ih.getCache();
// bh.consume( cache.get( key ) );
// ih.cacheGetDone();
// }
@Benchmark
@GroupThreads(2)
@Group("getPutHotRod")
public void infinispanRemoteRemove(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
Object key = kg.getNextKey();
RemoteCache cache = ih.getCache();
bh.consume( cache.remove( key) );
ih.cacheRemoveDone();
}

@Benchmark
@GroupThreads(4)
@Group("getPutHotRod")
public void infinispanRemotePut(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
Object key = kg.getNextKey();
Object value = kg.getNextValue();
RemoteCache cache = ih.getCache();
bh.consume( cache.put( key, value ) );
ih.cachePutDone();
}

@Benchmark
@GroupThreads(16)
@Group("getPutHotRod")
public void infinispanRemoteGet(InfinispanRemoteHolder ih, Blackhole bh, KeySequenceGenerator kg) {
Object key = kg.getNextKey();
RemoteCache cache = ih.getCache();
bh.consume( cache.get( key ) );
ih.cacheGetDone();
}

@Benchmark
@Threads(16)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.infinispan;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Set;

import org.apache.commons.math3.random.JDKRandomGenerator;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.infinispan.commons.io.UnsignedNumeric;
import org.infinispan.commons.marshall.AdvancedExternalizer;
import org.infinispan.commons.util.Util;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
Expand Down Expand Up @@ -109,6 +116,32 @@ else if (obj instanceof ValueWrapper)
else
return false;
}
}

public static class ValueWrapperSerializer implements AdvancedExternalizer<ValueWrapper> {

@Override
public Set<Class<? extends ValueWrapper>> getTypeClasses() {
return Util.asSet(ValueWrapper.class);
}

@Override
public Integer getId() {
return 205;
}

@Override
public void writeObject(ObjectOutput objectOutput, ValueWrapper valueWrapper) throws IOException {
UnsignedNumeric.writeUnsignedInt(objectOutput, valueWrapper.bytes.length);
objectOutput.write(valueWrapper.bytes);
}

@Override
public ValueWrapper readObject(ObjectInput objectInput) throws IOException, ClassNotFoundException {
int size = UnsignedNumeric.readUnsignedInt(objectInput);
byte[] bytes = new byte[size];
objectInput.read(bytes);
return new ValueWrapper(bytes);
}
}
}
18 changes: 18 additions & 0 deletions getputremovetest/src/main/resources/dist-sync.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<infinispan
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:infinispan:config:15.0">

<cache-container name="default" default-cache="testCache">
<transport stack="tcp" lock-timeout="600000" cluster="default" />
<serialization>
<advanced-externalizer class="org.infinispan.KeySequenceGenerator$ValueWrapperSerializer"/>
</serialization>

<distributed-cache name="testCache" mode="SYNC" >
<state-transfer enabled="false" />
</distributed-cache>
</cache-container>

</infinispan>

0 comments on commit 933a246

Please sign in to comment.