diff --git a/distribution/pom.xml b/distribution/pom.xml index ef835c5827..50c7d20e30 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -126,18 +126,32 @@ ${project.groupId} - mina-transport-serial + mina-http ${project.version} ${project.groupId} - mina-http + mina-benchmarks ${project.version} - + + + + serial + + + with-LGPL-dependencies + + + + mina-transport-serial + + + + diff --git a/distribution/src/main/assembly/bin.xml b/distribution/src/main/assembly/bin.xml index 16325893a0..8e431db819 100644 --- a/distribution/src/main/assembly/bin.xml +++ b/distribution/src/main/assembly/bin.xml @@ -75,6 +75,9 @@ ${project.groupId}:mina-transport-serial + + + ${project.groupId}:mina-benchmarks diff --git a/mina-benchmarks/pom.xml b/mina-benchmarks/pom.xml index c202d79da0..5b507a90fd 100755 --- a/mina-benchmarks/pom.xml +++ b/mina-benchmarks/pom.xml @@ -24,12 +24,10 @@ org.apache.mina mina-parent - 2.0.8-SNAPSHOT + 2.2.11-SNAPSHOT mina-benchmarks - org.apache.mina - 2.0.12-SNAPSHOT Apache MINA Benchmarks tests diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java b/mina-benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java index 2d28ad7a69..406647c056 100755 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java @@ -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 Apache MINA Project */ -@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 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 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(); @@ -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); } } diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkClient.java b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkClient.java index 4f5a54e4bb..118e9f9b18 100755 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkClient.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkClient.java @@ -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); diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkServer.java b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkServer.java index f71a90f4ec..d919d48e46 100755 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkServer.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaBenchmarkServer.java @@ -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); diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsMinaServerBenchmarkBinaryTest.java b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsMinaServerBenchmarkBinaryTest.java index 78cdbdb460..0d47393680 100755 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsMinaServerBenchmarkBinaryTest.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsMinaServerBenchmarkBinaryTest.java @@ -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} */ diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsNettyServerBenchmarkBinaryTest.java b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsNettyServerBenchmarkBinaryTest.java index aaa2a16a3e..c39f9c70b8 100644 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsNettyServerBenchmarkBinaryTest.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/MinaClientVsNettyServerBenchmarkBinaryTest.java @@ -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} */ @@ -49,5 +41,4 @@ public Type getClientType() { public Type getServerType() { return Type.Netty; } - } diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkClient.java b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkClient.java index 71145dc753..4fe608de38 100644 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkClient.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkClient.java @@ -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; @@ -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); @@ -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(); } } diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkServer.java b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkServer.java index 35fb94d2a6..3fea35a65e 100644 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkServer.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyBenchmarkServer.java @@ -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; @@ -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. @@ -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); @@ -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(); } } diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsMinaServerBenchmarkBinaryTest.java b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsMinaServerBenchmarkBinaryTest.java index d6645fd4f6..4a90c431e8 100644 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsMinaServerBenchmarkBinaryTest.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsMinaServerBenchmarkBinaryTest.java @@ -23,45 +23,26 @@ import java.util.Collection; import org.apache.mina.core.BenchmarkFactory.Type; -import org.junit.runners.Parameterized.Parameters; /** * @author Apache MINA Project */ 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 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); - } } diff --git a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsNettyServerBenchmarkBinaryTest.java b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsNettyServerBenchmarkBinaryTest.java index 1921ca4baf..1a2b5f65de 100644 --- a/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsNettyServerBenchmarkBinaryTest.java +++ b/mina-benchmarks/src/test/java/org/apache/mina/core/NettyClientVsNettyServerBenchmarkBinaryTest.java @@ -23,45 +23,26 @@ import java.util.Collection; import org.apache.mina.core.BenchmarkFactory.Type; -import org.junit.runners.Parameterized.Parameters; /** * @author Apache MINA Project */ public class NettyClientVsNettyServerBenchmarkBinaryTest - extends BenchmarkBinaryTest { + extends BenchmarkBinaryTest { /** - * @param numberOfMessages - * @param messageSize - */ - public NettyClientVsNettyServerBenchmarkBinaryTest( 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.Netty; } - - //TODO: analyze with Netty is so slow on large message: last test lower to 100 messages - @Parameters - public static Collection 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); - } } diff --git a/pom.xml b/pom.xml index 2dcb0811dd..4999cf1c05 100644 --- a/pom.xml +++ b/pom.xml @@ -181,7 +181,7 @@ mina-example mina-http mina-legal - + mina-benchmarks @@ -663,6 +663,7 @@ ${version.surefire.plugin} -Xmx1024m + benchmark