Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,32 @@

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mina-transport-serial</artifactId>
<artifactId>mina-http</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mina-http</artifactId>
<artifactId>mina-benchmarks</artifactId>
<version>${project.version}</version>
</dependency>

<!-- We don't include distrinution as a dependency : it's not part of the release -->
<!-- We don't include distribution as a dependency : it's not part of the release -->
</dependencies>

<profiles>
<profile>
<id>serial</id>
<activation>
<property>
<name>with-LGPL-dependencies</name>
</property>
</activation>
<modules>
<module>mina-transport-serial</module>
</modules>
</profile>
</profiles>

</project>

3 changes: 3 additions & 0 deletions distribution/src/main/assembly/bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@

<!-- Excluding transport-serial jar -->
<exclude>${project.groupId}:mina-transport-serial</exclude>

<!-- Excluding mina-benchmarks jar -->
<exclude>${project.groupId}:mina-benchmarks</exclude>
</excludes>
</dependencySet>

Expand Down
4 changes: 1 addition & 3 deletions mina-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
<parent>
<groupId>org.apache.mina</groupId>
<artifactId>mina-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
<version>2.2.11-SNAPSHOT</version>
</parent>

<artifactId>mina-benchmarks</artifactId>
<groupId>org.apache.mina</groupId>
<version>2.0.12-SNAPSHOT</version>
<name>Apache MINA Benchmarks tests</name>
<properties>
<!-- defined in order to run against a different MINA version -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,52 @@
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.apache.mina.core.BenchmarkFactory.Type;
import org.apache.mina.util.AvailablePortFinder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.assertTrue;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
@RunWith(Parameterized.class)
public abstract class BenchmarkBinaryTest {
private int numberOfMessages;

private int port;

private BenchmarkServer server;

private BenchmarkClient client;

private int messageSize;

private int timeout;

private byte[] data;

public BenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
this.numberOfMessages = numberOfMessages;
this.messageSize = messageSize;
this.timeout = timeout;
}

public abstract Type getClientType();

public abstract Type getServerType();

@Parameters
public static Collection<Object[]> getParameters() {
Object[][] parameters = new Object[][] {
{ 100000, 10, 2 * 60 },
{ 100000, 1 * 1024, 2 * 60 },
{ 100000, 10 * 1024, 2 * 60 },
{ 100, 64 * 1024 * 1024, 10 * 60 }
};
return Arrays.asList(parameters);
// TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
private static Stream<Arguments> parameters() {
return Stream.of(
Arguments.of(100000, 10, 2 * 60),
Arguments.of(100000, 1 * 1024, 2 * 60),
Arguments.of(100000, 10 * 1024, 2 * 60),
Arguments.of(100, 64 * 1024 * 1024, 10 * 60)
);
}

@Before
@BeforeEach
public void init() throws IOException {
port = AvailablePortFinder.getNextAvailable();
server = BenchmarkServerFactory.INSTANCE.get(getServerType());
server.start(port);
client = BenchmarkClientFactory.INSTANCE.get(getClientType());
data = new byte[messageSize + 4];
data[0] = (byte) (messageSize >>> 24 & 255);
data[1] = (byte) (messageSize >>> 16 & 255);
data[2] = (byte) (messageSize >>> 8 & 255);
data[3] = (byte) (messageSize & 255);

}

@After
@AfterEach
public void shutdown() throws IOException {
client.stop();
server.stop();
Expand All @@ -99,12 +79,21 @@ public void shutdown() throws IOException {
* Send "numberOfMessages" messages to a server. Currently, 1 million, with two different
* size, 10Ko and 64Ko.
*/
@Test
public void benchmark() throws IOException, InterruptedException {
@ParameterizedTest(name = "{index}: numberOfMessages={0}, messageSize={1}, timeout={2}")
@MethodSource("parameters")
@Tag("benchmark")
public void benchmark(int numberOfMessages, int messageSize, int timeout) throws IOException, InterruptedException {
CountDownLatch counter = new CountDownLatch(numberOfMessages);

byte[] data = new byte[messageSize + 4];
data[0] = (byte) (messageSize >>> 24 & 255);
data[1] = (byte) (messageSize >>> 16 & 255);
data[2] = (byte) (messageSize >>> 8 & 255);
data[3] = (byte) (messageSize & 255);

client.start(port, counter, data);

boolean result = counter.await(timeout, TimeUnit.SECONDS);
assertTrue("Still " + counter.getCount() + " messages to send on a total of " + numberOfMessages, result);
assertTrue(result, "Still " + counter.getCount() + " messages to send on a total of " + numberOfMessages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class MinaBenchmarkClient implements BenchmarkClient {
/**
* {@inheritDoc}
*/
@Override
public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
connector = new NioSocketConnector(2 * Runtime.getRuntime().availableProcessors());
((SocketConnector) connector).getSessionConfig().setSendBufferSize(64 * 1024);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private static enum State {
/**
* {@inheritDoc}
*/
@Override
public void start(int port) throws IOException {
acceptor = new NioSocketAcceptor(2 * Runtime.getRuntime().availableProcessors());
((NioSocketAcceptor) acceptor).getSessionConfig().setReadBufferSize(128 * 1024);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
*/
public class MinaClientVsMinaServerBenchmarkBinaryTest extends BenchmarkBinaryTest {

/**
* @param numberOfMessages
* @param messageSize
*/
public MinaClientVsMinaServerBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
super(numberOfMessages, messageSize, timeout);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
*/
public class MinaClientVsNettyServerBenchmarkBinaryTest extends BenchmarkBinaryTest {

/**
* @param numberOfMessages
* @param messageSize
*/
public MinaClientVsNettyServerBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
super(numberOfMessages, messageSize, timeout);
}

/**
* {@inheritDoc}
*/
Expand All @@ -49,5 +41,4 @@ public Type getClientType() {
public Type getServerType() {
return Type.Netty;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
Expand All @@ -42,16 +45,15 @@
public class NettyBenchmarkClient implements BenchmarkClient {

private ChannelFactory factory;
private Channel channel;

/**
*
*/
public NettyBenchmarkClient() {
}

/**
* {@inheritedDoc}
*/
@Override
public void start(final int port, final CountDownLatch counter, final byte[] data) throws IOException {
factory = new NioClientSocketChannelFactory();
ClientBootstrap bootstrap = new ClientBootstrap(factory);
Expand Down Expand Up @@ -90,13 +92,24 @@ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) thr
});
}
});
bootstrap.connect(new InetSocketAddress(port));

ChannelFuture connectFuture = bootstrap.connect(new InetSocketAddress(port));
boolean connected = connectFuture.awaitUninterruptibly(4L, TimeUnit.SECONDS);

if (!connected) {
throw new IllegalStateException("Failed to connect to the server");
}

channel = connectFuture.getChannel();
}

/**
* {@inheritedDoc}
*/
public void stop() throws IOException {
ChannelFuture closeFuture = channel.close();
closeFuture.awaitUninterruptibly(2L, TimeUnit.SECONDS);

factory.releaseExternalResources();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
Expand Down Expand Up @@ -60,6 +63,7 @@ private static enum State {
private static final String LENGTH_ATTRIBUTE = NettyBenchmarkServer.class.getName() + ".length";

private ChannelFactory factory;
private Channel channel;

/**
* Allocate a map as attachment for storing attributes.
Expand Down Expand Up @@ -88,6 +92,7 @@ private static Object getAttribute(ChannelHandlerContext ctx, String name) {
/**
* {@inheritDoc}
*/
@Override
public void start(int port) throws IOException {
factory = new NioServerSocketChannelFactory();
ServerBootstrap bootstrap = new ServerBootstrap(factory);
Expand Down Expand Up @@ -165,13 +170,17 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws
});
}
});
bootstrap.bind(new InetSocketAddress(port));

channel = bootstrap.bind(new InetSocketAddress(port));
}

/**
* {@inheritedDoc}
*/
public void stop() throws IOException {
ChannelFuture closeFuture = channel.close();
closeFuture.awaitUninterruptibly(2L, TimeUnit.SECONDS);

factory.releaseExternalResources();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,26 @@
import java.util.Collection;

import org.apache.mina.core.BenchmarkFactory.Type;
import org.junit.runners.Parameterized.Parameters;

/**
* @author <a href="http://mina.apache.org">Apache MINA Project</a>
*/
public class NettyClientVsMinaServerBenchmarkBinaryTest
extends BenchmarkBinaryTest {
extends BenchmarkBinaryTest {

/**
* @param numberOfMessages
* @param messageSize
*/
public NettyClientVsMinaServerBenchmarkBinaryTest( int numberOfMessages, int messageSize, int timeout ) {
super( numberOfMessages, messageSize, timeout );
}

/** {@inheritDoc}
* {@inheritDoc}
*/
@Override
public Type getClientType() {
return Type.Netty;
}

/** {@inheritDoc}
/**
* {@inheritDoc}
*/
@Override
public Type getServerType() {
return Type.Mina;
}

//TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
@Parameters
public static Collection<Object[]> getParameters() {
Object[][] parameters = new Object[][] {
{ 1000000, 10, 2 * 60 },
{ 1000000, 1 * 1024, 2 * 60 },
{ 1000000, 10 * 1024, 2 * 60 },
{ 100, 64 * 1024 * 1024, 10 * 60 }
};
return Arrays.asList(parameters);
}
}
Loading
Loading