You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by je...@apache.org on 2014/05/16 11:09:28 UTC
[4/4] git commit: Refactor benchmark tests in single multi module to
be more DRY oriented
Refactor benchmark tests in single multi module to be more DRY oriented
Project: http://git-wip-us.apache.org/repos/asf/mina/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/a79cb81b
Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/a79cb81b
Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/a79cb81b
Branch: refs/heads/trunk
Commit: a79cb81bbc7fee4c1724a5a1a0d3ba338853cf6f
Parents: fc584a7
Author: Jeff MAURY <je...@apache.org>
Authored: Fri May 16 11:08:28 2014 +0200
Committer: Jeff MAURY <je...@apache.org>
Committed: Fri May 16 11:08:28 2014 +0200
----------------------------------------------------------------------
benchmarks/common/pom.xml | 33 ++++
.../apache/mina/core/BenchmarkBinaryTest.java | 154 +++++++++++++++
.../org/apache/mina/core/BenchmarkClient.java | 36 ++++
.../org/apache/mina/core/BenchmarkServer.java | 35 ++++
...ClientVsBioServerUdpBenchmarkBinaryTest.java | 69 +++++++
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 +++++++
.../org/apache/mina/core/CounterFilter.java | 31 +++
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 74 +++++++
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 +++++++
.../core/bio/udp/BioUdpBenchmarkClient.java | 80 ++++++++
.../core/bio/udp/BioUdpBenchmarkServer.java | 167 ++++++++++++++++
.../core/nio/tcp/Mina3TcpBenchmarkClient.java | 107 ++++++++++
.../core/nio/tcp/Mina3TcpBenchmarkServer.java | 159 +++++++++++++++
.../core/nio/udp/Mina3UdpBenchmarkClient.java | 116 +++++++++++
.../core/nio/udp/Mina3UdpBenchmarkServer.java | 167 ++++++++++++++++
.../common/src/test/resources/log4j.properties | 23 +++
benchmarks/netty3/pom.xml | 49 +++++
...entVsNetty3ServerTcpBenchmarkBinaryTest.java | 66 +++++++
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 65 ++++++
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 67 +++++++
...entVsNetty3ServerTcpBenchmarkBinaryTest.java | 65 ++++++
...entVsNetty3ServerUdpBenchmarkBinaryTest.java | 67 +++++++
.../core/nio/tcp/Netty3TcpBenchmarkClient.java | 104 ++++++++++
.../core/nio/tcp/Netty3TcpBenchmarkServer.java | 194 ++++++++++++++++++
.../core/nio/udp/Netty3UdpBenchmarkClient.java | 106 ++++++++++
.../core/nio/udp/Netty3UdpBenchmarkServer.java | 197 +++++++++++++++++++
benchmarks/netty4/pom.xml | 49 +++++
.../apache/mina/core/Netty4BenchmarkServer.java | 46 +++++
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 75 +++++++
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 +++++++
...entVsNetty4ServerTcpBenchmarkBinaryTest.java | 75 +++++++
...entVsNetty4ServerUdpBenchmarkBinaryTest.java | 69 +++++++
.../core/nio/tcp/Netty4TcpBenchmarkClient.java | 109 ++++++++++
.../core/nio/tcp/Netty4TcpBenchmarkServer.java | 155 +++++++++++++++
.../core/nio/udp/Netty4UdpBenchmarkClient.java | 100 ++++++++++
.../core/nio/udp/Netty4UdpBenchmarkServer.java | 133 +++++++++++++
benchmarks/pom.xml | 16 +-
.../apache/mina/core/BenchmarkBinaryTest.java | 154 ---------------
.../org/apache/mina/core/BenchmarkClient.java | 36 ----
.../org/apache/mina/core/BenchmarkServer.java | 35 ----
...ClientVsBioServerUdpBenchmarkBinaryTest.java | 69 -------
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 -------
.../org/apache/mina/core/CounterFilter.java | 31 ---
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 74 -------
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 -------
...entVsNetty3ServerTcpBenchmarkBinaryTest.java | 66 -------
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 65 ------
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 67 -------
...entVsNetty3ServerTcpBenchmarkBinaryTest.java | 65 ------
...entVsNetty3ServerUdpBenchmarkBinaryTest.java | 67 -------
.../core/bio/udp/BioUdpBenchmarkClient.java | 80 --------
.../core/bio/udp/BioUdpBenchmarkServer.java | 167 ----------------
.../core/nio/tcp/Mina3TcpBenchmarkClient.java | 107 ----------
.../core/nio/tcp/Mina3TcpBenchmarkServer.java | 159 ---------------
.../core/nio/tcp/Netty3TcpBenchmarkClient.java | 104 ----------
.../core/nio/tcp/Netty3TcpBenchmarkServer.java | 194 ------------------
.../core/nio/udp/Mina3UdpBenchmarkClient.java | 116 -----------
.../core/nio/udp/Mina3UdpBenchmarkServer.java | 167 ----------------
.../core/nio/udp/Netty3UdpBenchmarkClient.java | 106 ----------
.../core/nio/udp/Netty3UdpBenchmarkServer.java | 197 -------------------
benchmarks/src/test/resources/log4j.properties | 23 ---
benchmarks2/pom.xml | 71 -------
.../apache/mina/core/BenchmarkBinaryTest.java | 123 ------------
.../org/apache/mina/core/BenchmarkClient.java | 36 ----
.../org/apache/mina/core/BenchmarkServer.java | 35 ----
.../apache/mina/core/Netty4BenchmarkServer.java | 46 -----
...ientVsMina3ServerTcpBenchmarkBinaryTest.java | 75 -------
...ientVsMina3ServerUdpBenchmarkBinaryTest.java | 69 -------
...entVsNetty4ServerTcpBenchmarkBinaryTest.java | 75 -------
...entVsNetty4ServerUdpBenchmarkBinaryTest.java | 69 -------
.../core/nio/tcp/Mina3TcpBenchmarkServer.java | 156 ---------------
.../core/nio/tcp/Netty4TcpBenchmarkClient.java | 109 ----------
.../core/nio/tcp/Netty4TcpBenchmarkServer.java | 155 ---------------
.../core/nio/udp/Mina3UdpBenchmarkServer.java | 166 ----------------
.../core/nio/udp/Netty4UdpBenchmarkClient.java | 100 ----------
.../core/nio/udp/Netty4UdpBenchmarkServer.java | 133 -------------
benchmarks2/src/test/resources/log4j.properties | 23 ---
pom.xml | 11 +-
78 files changed, 3266 insertions(+), 3738 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/pom.xml
----------------------------------------------------------------------
diff --git a/benchmarks/common/pom.xml b/benchmarks/common/pom.xml
new file mode 100644
index 0000000..4807b1a
--- /dev/null
+++ b/benchmarks/common/pom.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-benchmarks</artifactId>
+ <version>3.0.0-M3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mina-benchmarks-common</artifactId>
+ <name>Apache MINA Benchmarks against JDK and MINA tests</name>
+
+</project>
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
new file mode 100644
index 0000000..5c2e85e
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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.mina.core;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+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;
+
+/**
+ * Binary benchmark
+ * @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 BenchmarkClient getClient();
+
+ public abstract BenchmarkServer getServer();
+
+ @Parameters(name = "{0} messages of size {1}")
+ 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);
+ }
+
+ public static int getNextAvailable() {
+ ServerSocket serverSocket = null;
+
+ try {
+ // Here, we simply return an available port found by the system
+ serverSocket = new ServerSocket(0);
+ int port = serverSocket.getLocalPort();
+
+ // Don't forget to close the socket...
+ serverSocket.close();
+
+ return port;
+ } catch (IOException ioe) {
+ throw new NoSuchElementException(ioe.getMessage());
+ }
+ }
+
+ @Before
+ public void init() throws IOException {
+ port = getNextAvailable();
+ server = getServer();
+ server.start(port);
+ client = getClient();
+ 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
+ public void shutdown() throws IOException {
+ client.stop();
+ server.stop();
+ }
+
+ /**
+ * Send "numberOfMessages" messages to a server. Currently, 1 million, with two different
+ * size, 10Ko and 64Ko.
+ */
+ @Test
+ public void benchmark() throws IOException, InterruptedException {
+ CountDownLatch counter = new CountDownLatch(numberOfMessages);
+ CounterFilter.messageSent.set(0);
+
+ boolean result = true;
+
+ System.out.println("-------------- Sending " + data.length + " bytes");
+ client.start(port, counter, data);
+ long globalSent = 0;
+ long warmedUpSent = 0;
+ int nbSeconds = 0;
+
+ while ((counter.getCount() > 0) && (nbSeconds < 120)) {
+ result = counter.await(1, TimeUnit.SECONDS);
+
+ long nbSent = CounterFilter.messageSent.getAndSet(0);
+ nbSeconds++;
+
+ globalSent += nbSent;
+
+ if (nbSeconds > 5) {
+ warmedUpSent += nbSent;
+ }
+
+ System.out.print("Nb messages sent per second : " + nbSent + "\r");
+ }
+
+ System.out.println();
+ if (nbSeconds < 120) {
+ System.out.println("Average : " + (warmedUpSent / (nbSeconds - 5)) + ", for " + globalSent
+ + " messages sent in " + nbSeconds + "s");
+ } else {
+ System.out.println("Wasn't able to send all the messages : sent " + globalSent);
+ }
+
+ assertTrue("Still " + counter.getCount() + " messages to send of a total of " + numberOfMessages, result);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkClient.java b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkClient.java
new file mode 100644
index 0000000..393eea6
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkClient.java
@@ -0,0 +1,36 @@
+/*
+ * 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.mina.core;
+
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * An interface for a server
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public interface BenchmarkClient {
+ /** Starts the client */
+ public void start(int port, CountDownLatch counter, byte[] data) throws IOException;
+
+ /** Stops the client */
+ public void stop() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkServer.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkServer.java b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkServer.java
new file mode 100644
index 0000000..d4652e3
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/BenchmarkServer.java
@@ -0,0 +1,35 @@
+/*
+ * 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.mina.core;
+
+import java.io.IOException;
+
+/**
+ * An interface for a server
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public interface BenchmarkServer {
+ /** Starts the server */
+ public void start(int port) throws IOException;
+
+ /** Stops the server */
+ public void stop() throws IOException;
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..815983d
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsBioServerUdpBenchmarkBinaryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkClient;
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BioClientVsBioServerUdpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public BioClientVsBioServerUdpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new BioUdpBenchmarkClient();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new BioUdpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ // Note : depending on your OS, the maximum PDU you can send can vary. See sysctl net.inet.udp.maxdgram
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 },
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 2 * 1024, 2 * 60 },
+ { 1000000, 4 * 1024, 2 * 60 },
+ { 500000, 8 * 1024, 2 * 60 } }; // No need to test any further, the maximum size for an UDP message is 64Kb
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..f2f292b
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/BioClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.bio.udp.BioUdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BioClientVsMina3ServerUdpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public BioClientVsMina3ServerUdpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new BioUdpBenchmarkClient();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ // Note : depending on your OS, the maximum PDU you can send can vary. See sysctl net.inet.udp.maxdgram
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 },
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 2 * 1024, 2 * 60 },
+ { 1000000, 4 * 1024, 2 * 60 },
+ { 500000, 8 * 1024, 2 * 60 } }; // No need to test any further, the maximum size for an UDP message is 64Kb
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/CounterFilter.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/CounterFilter.java b/benchmarks/common/src/test/java/org/apache/mina/core/CounterFilter.java
new file mode 100644
index 0000000..f501141
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/CounterFilter.java
@@ -0,0 +1,31 @@
+/*
+ * 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.mina.core;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * A counter used for the benchmarks
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class CounterFilter {
+ public static AtomicLong messageSent = new AtomicLong(0);
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..600b5ae
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Mina3ClientVsMina3ServerTcpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Mina3TcpBenchmarkClient();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Mina3TcpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 },
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 10 * 1024, 2 * 60 },
+ { 1000000, 20 * 1024, 2 * 60 },
+ { 500000, 50 * 1024, 2 * 60 },
+ { 200000, 100 * 1024, 2 * 60 },
+ { 100000, 200 * 1024, 2 * 60 },
+ { 50000, 500 * 1024, 2 * 60 },
+ { 20000, 1024 * 1024, 2 * 60 },
+ { 2000, 10 * 1024 * 1024, 2 * 60 },
+ { 500, 64 * 1024 * 1024, 2 * 60 } };
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..7ea251b
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Mina3ClientVsMina3ServerUdpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Mina3UdpBenchmarkClient();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ // Note : depending on your OS, the maximum PDU you can send can vary. See sysctl net.inet.udp.maxdgram
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 },
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 2 * 1024, 2 * 60 },
+ { 1000000, 4 * 1024, 2 * 60 },
+ { 500000, 8 * 1024, 2 * 60 }}; // No need to test any further, the maximum size for an UDP message is 64Kb
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkClient.java b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkClient.java
new file mode 100644
index 0000000..fe0c062
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkClient.java
@@ -0,0 +1,80 @@
+/*
+ * 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.mina.core.bio.udp;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.mina.core.BenchmarkClient;
+
+/**
+ * A client that uses a BIO datagram to communicate with the server
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BioUdpBenchmarkClient implements BenchmarkClient {
+ // The UDP client
+ private DatagramSocket sender;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
+ InetAddress serverAddress = InetAddress.getLocalHost();
+ byte[] buffer = new byte[65507];
+ sender = new DatagramSocket(port + 1);
+
+ DatagramPacket pduSent = new DatagramPacket(data, data.length, serverAddress, port);
+ DatagramPacket pduReceived = new DatagramPacket(buffer, data.length);
+ sender.send(pduSent);
+
+ boolean done = false;
+
+ while (!done) {
+ try {
+ sender.receive(pduReceived);
+
+ for (int i = 0; i < pduReceived.getLength(); ++i) {
+ counter.countDown();
+
+ if (counter.getCount() > 0) {
+ sender.send(pduSent);
+ break;
+ } else {
+ done = true;
+ }
+ }
+ } catch (IOException ioe) {
+ // Nothing to do
+ }
+ }
+
+ sender.close();
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void stop() throws IOException {
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
new file mode 100644
index 0000000..fd9af8d
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/bio/udp/BioUdpBenchmarkServer.java
@@ -0,0 +1,167 @@
+/*
+ * 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.mina.core.bio.udp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.apache.mina.session.AttributeKey;
+import org.apache.mina.transport.bio.BioUdpServer;
+import org.apache.mina.transport.udp.DefaultUdpSessionConfig;
+import org.apache.mina.transport.udp.UdpSessionConfig;
+
+/**
+ * A Server that uses a BIO datagram to communicate with the server
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class BioUdpBenchmarkServer implements BenchmarkServer {
+ private static enum State {
+ WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
+ }
+
+ private static final ByteBuffer ACK = ByteBuffer.allocate(1);
+
+ static {
+ ACK.put((byte) 0);
+ ACK.rewind();
+ }
+
+ private static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>(State.class,
+ Mina3UdpBenchmarkServer.class.getName() + ".state");
+
+ private static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>(Integer.class,
+ Mina3UdpBenchmarkServer.class.getName() + ".length");
+
+ private BioUdpServer udpServer;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void start(int port) throws IOException {
+ UdpSessionConfig config = new DefaultUdpSessionConfig();
+ config.setReadBufferSize(65536);
+ udpServer = new BioUdpServer(config, null);
+ udpServer.setIoHandler(new IoHandler() {
+ @Override
+ public void sessionOpened(IoSession session) {
+ session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
+ }
+
+ @Override
+ public void messageReceived(IoSession session, Object message) {
+ //System.out.println("Server Message received : " + message);
+ if (message instanceof ByteBuffer) {
+ ByteBuffer buffer = (ByteBuffer) message;
+
+ State state = session.getAttribute(STATE_ATTRIBUTE);
+ int length = 0;
+
+ if (session.getAttribute(LENGTH_ATTRIBUTE) != null) {
+ length = session.getAttribute(LENGTH_ATTRIBUTE);
+ }
+
+ while (buffer.remaining() > 0) {
+ switch (state) {
+ case WAIT_FOR_FIRST_BYTE_LENGTH:
+ length = (buffer.get() & 255) << 24;
+ state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_SECOND_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 16;
+ state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_THIRD_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 8;
+ state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_FOURTH_BYTE_LENGTH:
+ length += (buffer.get() & 255);
+ state = State.READING;
+ if ((length == 0) && (buffer.remaining() == 0)) {
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ }
+ break;
+ case READING:
+ int remaining = buffer.remaining();
+ if (length > remaining) {
+ length -= remaining;
+ buffer.position(buffer.position() + remaining);
+ } else {
+ buffer.position(buffer.position() + length);
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ length = 0;
+ }
+ }
+ }
+ session.setAttribute(LENGTH_ATTRIBUTE, length);
+ session.setAttribute(STATE_ATTRIBUTE, state);
+ }
+ }
+
+ @Override
+ public void exceptionCaught(IoSession session, Exception cause) {
+ cause.printStackTrace();
+ }
+
+ @Override
+ public void sessionClosed(IoSession session) {
+ }
+
+ @Override
+ public void sessionIdle(IoSession session, IdleStatus status) {
+ }
+
+ @Override
+ public void messageSent(IoSession session, Object message) {
+ CounterFilter.messageSent.getAndIncrement();
+ }
+
+ @Override
+ public void serviceActivated(IoService service) {
+ }
+
+ @Override
+ public void serviceInactivated(IoService service) {
+ }
+ });
+
+ udpServer.bind(new InetSocketAddress(port));
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ @Override
+ public void stop() throws IOException {
+ udpServer.unbind();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkClient.java b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkClient.java
new file mode 100644
index 0000000..44ceeb7
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkClient.java
@@ -0,0 +1,107 @@
+/*
+ * 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.mina.core.nio.tcp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.apache.mina.core.BenchmarkClient;
+import org.apache.mina.transport.nio.NioTcpClient;
+
+/**
+ * A MINA 3 TCP CLient.
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3TcpBenchmarkClient implements BenchmarkClient {
+ // The TCP client
+ private NioTcpClient client;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
+ client = new NioTcpClient();
+ client.getSessionConfig().setSendBufferSize(64 * 1024);
+ client.getSessionConfig().setTcpNoDelay(true);
+ client.setIoHandler(new IoHandler() {
+ private void sendMessage(IoSession session, byte[] data) {
+ ByteBuffer iobuf = ByteBuffer.wrap(data);
+ session.write(iobuf);
+ }
+
+ public void sessionOpened(IoSession session) {
+ sendMessage(session, data);
+ }
+
+ public void messageReceived(IoSession session, Object message) {
+ if (message instanceof ByteBuffer) {
+ ByteBuffer buffer = (ByteBuffer) message;
+
+ for (int i = 0; i < buffer.remaining(); ++i) {
+ counter.countDown();
+ long count = counter.getCount();
+ if (count > 0) {
+ sendMessage(session, data);
+ }
+ }
+ }
+ }
+
+ public void exceptionCaught(IoSession session, Exception cause) {
+ cause.printStackTrace();
+ }
+
+ @Override
+ public void sessionClosed(IoSession session) {
+ }
+
+ @Override
+ public void sessionIdle(IoSession session, IdleStatus status) {
+ }
+
+ @Override
+ public void messageSent(IoSession session, Object message) {
+ }
+
+ @Override
+ public void serviceActivated(IoService service) {
+ }
+
+ @Override
+ public void serviceInactivated(IoService service) {
+ }
+ });
+
+ client.connect(new InetSocketAddress(port));
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void stop() throws IOException {
+ client.disconnect();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkServer.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkServer.java b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkServer.java
new file mode 100644
index 0000000..c8153a2
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/nio/tcp/Mina3TcpBenchmarkServer.java
@@ -0,0 +1,159 @@
+/*
+ * 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.mina.core.nio.tcp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
+import org.apache.mina.session.AttributeKey;
+import org.apache.mina.transport.nio.FixedSelectorLoopPool;
+import org.apache.mina.transport.nio.NioTcpServer;
+
+/**
+ * A MINA 3 TCP Server.
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3TcpBenchmarkServer implements BenchmarkServer {
+
+ private static enum State {
+ WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
+ }
+
+ private static final ByteBuffer ACK = ByteBuffer.allocate(1);
+
+ static {
+ ACK.put((byte) 0);
+ ACK.rewind();
+ }
+
+ private static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>(State.class,
+ Mina3TcpBenchmarkServer.class.getName() + ".state");
+
+ private static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>(Integer.class,
+ Mina3TcpBenchmarkServer.class.getName() + ".length");
+
+ private NioTcpServer tcpServer;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(int port) throws IOException {
+ tcpServer = new NioTcpServer(new FixedSelectorLoopPool("Server", 1), null);
+ tcpServer.getSessionConfig().setReadBufferSize(128 * 1024);
+ tcpServer.getSessionConfig().setTcpNoDelay(true);
+ tcpServer.setIoHandler(new IoHandler() {
+ public void sessionOpened(IoSession session) {
+ session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
+ }
+
+ public void messageReceived(IoSession session, Object message) {
+ if (message instanceof ByteBuffer) {
+ ByteBuffer buffer = (ByteBuffer) message;
+
+ State state = session.getAttribute(STATE_ATTRIBUTE);
+ int length = 0;
+
+ if (session.getAttribute(LENGTH_ATTRIBUTE) != null) {
+ length = session.getAttribute(LENGTH_ATTRIBUTE);
+ }
+
+ while (buffer.remaining() > 0) {
+ switch (state) {
+ case WAIT_FOR_FIRST_BYTE_LENGTH:
+ length = (buffer.get() & 255) << 24;
+ state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_SECOND_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 16;
+ state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_THIRD_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 8;
+ state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_FOURTH_BYTE_LENGTH:
+ length += (buffer.get() & 255);
+ state = State.READING;
+ if ((length == 0) && (buffer.remaining() == 0)) {
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ }
+ break;
+ case READING:
+ int remaining = buffer.remaining();
+ if (length > remaining) {
+ length -= remaining;
+ buffer.position(buffer.position() + remaining);
+ } else {
+ buffer.position(buffer.position() + length);
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ length = 0;
+ }
+ }
+ }
+ session.setAttribute(LENGTH_ATTRIBUTE, length);
+ session.setAttribute(STATE_ATTRIBUTE, state);
+ }
+ }
+
+ public void exceptionCaught(IoSession session, Exception cause) {
+ cause.printStackTrace();
+ }
+
+ @Override
+ public void sessionClosed(IoSession session) {
+ }
+
+ @Override
+ public void sessionIdle(IoSession session, IdleStatus status) {
+ }
+
+ @Override
+ public void messageSent(IoSession session, Object message) {
+ CounterFilter.messageSent.getAndIncrement();
+ }
+
+ @Override
+ public void serviceActivated(IoService service) {
+ }
+
+ @Override
+ public void serviceInactivated(IoService service) {
+ }
+ });
+
+ tcpServer.bind(new InetSocketAddress(port));
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void stop() throws IOException {
+ tcpServer.unbind();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkClient.java b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkClient.java
new file mode 100644
index 0000000..a4dcf4d
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkClient.java
@@ -0,0 +1,116 @@
+/*
+ * 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.mina.core.nio.udp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoFuture;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.apache.mina.core.BenchmarkClient;
+import org.apache.mina.transport.nio.NioUdpClient;
+
+/**
+ * A MINA 3 based UDP client
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3UdpBenchmarkClient implements BenchmarkClient {
+ // The UDP client
+ private NioUdpClient udpClient;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void start(int port, final CountDownLatch counter, final byte[] data) throws IOException {
+ udpClient = new NioUdpClient();
+ udpClient.setIoHandler(new IoHandler() {
+ private void sendMessage(IoSession session, byte[] data) {
+ ByteBuffer iobuf = ByteBuffer.wrap(data);
+ session.write(iobuf);
+ }
+
+ public void sessionOpened(IoSession session) {
+ sendMessage(session, data);
+ }
+
+ public void messageReceived(IoSession session, Object message) {
+ if (message instanceof ByteBuffer) {
+ ByteBuffer buffer = (ByteBuffer) message;
+ for (int i = 0; i < buffer.remaining(); ++i) {
+ counter.countDown();
+ long count = counter.getCount();
+ if (count > 0) {
+ sendMessage(session, data);
+ }
+ }
+ }
+ }
+
+ public void exceptionCaught(IoSession session, Exception cause) {
+ cause.printStackTrace();
+ }
+
+ @Override
+ public void sessionClosed(IoSession session) {
+ }
+
+ @Override
+ public void sessionIdle(IoSession session, IdleStatus status) {
+ }
+
+ @Override
+ public void messageSent(IoSession session, Object message) {
+ }
+
+ @Override
+ public void serviceActivated(IoService service) {
+ }
+
+ @Override
+ public void serviceInactivated(IoService service) {
+ }
+ });
+
+ IoFuture<IoSession> future = udpClient.connect(new InetSocketAddress(port));
+
+ try {
+ IoSession session = future.get();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ExecutionException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void stop() throws IOException {
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
new file mode 100644
index 0000000..a9bf2a9
--- /dev/null
+++ b/benchmarks/common/src/test/java/org/apache/mina/core/nio/udp/Mina3UdpBenchmarkServer.java
@@ -0,0 +1,167 @@
+/*
+ * 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.mina.core.nio.udp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+
+import org.apache.mina.api.IdleStatus;
+import org.apache.mina.api.IoHandler;
+import org.apache.mina.api.IoService;
+import org.apache.mina.api.IoSession;
+import org.apache.mina.core.BenchmarkServer;
+import org.apache.mina.core.CounterFilter;
+import org.apache.mina.session.AttributeKey;
+import org.apache.mina.transport.nio.NioUdpServer;
+import org.apache.mina.transport.udp.DefaultUdpSessionConfig;
+import org.apache.mina.transport.udp.UdpSessionConfig;
+
+/**
+ * A MINA 3 based UDP server
+ *
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3UdpBenchmarkServer implements BenchmarkServer {
+
+ private static enum State {
+ WAIT_FOR_FIRST_BYTE_LENGTH, WAIT_FOR_SECOND_BYTE_LENGTH, WAIT_FOR_THIRD_BYTE_LENGTH, WAIT_FOR_FOURTH_BYTE_LENGTH, READING
+ }
+
+ private static final ByteBuffer ACK = ByteBuffer.allocate(1);
+
+ static {
+ ACK.put((byte) 0);
+ ACK.rewind();
+ }
+
+ private static final AttributeKey<State> STATE_ATTRIBUTE = new AttributeKey<State>(State.class,
+ Mina3UdpBenchmarkServer.class.getName() + ".state");
+
+ private static final AttributeKey<Integer> LENGTH_ATTRIBUTE = new AttributeKey<Integer>(Integer.class,
+ Mina3UdpBenchmarkServer.class.getName() + ".length");
+
+ private NioUdpServer udpServer;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void start(int port) throws IOException {
+ UdpSessionConfig config = new DefaultUdpSessionConfig();
+ config.setReadBufferSize(65536);
+ udpServer = new NioUdpServer(config);
+ udpServer.setIoHandler(new IoHandler() {
+ @Override
+ public void sessionOpened(IoSession session) {
+ session.setAttribute(STATE_ATTRIBUTE, State.WAIT_FOR_FIRST_BYTE_LENGTH);
+ }
+
+ @Override
+ public void messageReceived(IoSession session, Object message) {
+ //System.out.println("Server Message received : " + message);
+ if (message instanceof ByteBuffer) {
+ ByteBuffer buffer = (ByteBuffer) message;
+
+ State state = session.getAttribute(STATE_ATTRIBUTE);
+ int length = 0;
+
+ if (session.getAttribute(LENGTH_ATTRIBUTE) != null) {
+ length = session.getAttribute(LENGTH_ATTRIBUTE);
+ }
+
+ while (buffer.remaining() > 0) {
+ switch (state) {
+ case WAIT_FOR_FIRST_BYTE_LENGTH:
+ length = (buffer.get() & 255) << 24;
+ state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_SECOND_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 16;
+ state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_THIRD_BYTE_LENGTH:
+ length += (buffer.get() & 255) << 8;
+ state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
+ break;
+ case WAIT_FOR_FOURTH_BYTE_LENGTH:
+ length += (buffer.get() & 255);
+ state = State.READING;
+ if ((length == 0) && (buffer.remaining() == 0)) {
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ }
+ break;
+ case READING:
+ int remaining = buffer.remaining();
+ if (length > remaining) {
+ length -= remaining;
+ buffer.position(buffer.position() + remaining);
+ } else {
+ buffer.position(buffer.position() + length);
+ session.write(ACK.slice());
+ state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
+ length = 0;
+ }
+ }
+ }
+ session.setAttribute(LENGTH_ATTRIBUTE, length);
+ session.setAttribute(STATE_ATTRIBUTE, state);
+ }
+ }
+
+ @Override
+ public void exceptionCaught(IoSession session, Exception cause) {
+ cause.printStackTrace();
+ }
+
+ @Override
+ public void sessionClosed(IoSession session) {
+ }
+
+ @Override
+ public void sessionIdle(IoSession session, IdleStatus status) {
+ }
+
+ @Override
+ public void messageSent(IoSession session, Object message) {
+ CounterFilter.messageSent.getAndIncrement();
+ }
+
+ @Override
+ public void serviceActivated(IoService service) {
+ }
+
+ @Override
+ public void serviceInactivated(IoService service) {
+ }
+ });
+
+ udpServer.bind(new InetSocketAddress(port));
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ @Override
+ public void stop() throws IOException {
+ udpServer.unbind();
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/common/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/benchmarks/common/src/test/resources/log4j.properties b/benchmarks/common/src/test/resources/log4j.properties
new file mode 100644
index 0000000..696da6e
--- /dev/null
+++ b/benchmarks/common/src/test/resources/log4j.properties
@@ -0,0 +1,23 @@
+#############################################################################
+# 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.
+#############################################################################
+log4j.rootCategory=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss}] %p [%c] - %m%n
+
+
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/pom.xml
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/pom.xml b/benchmarks/netty3/pom.xml
new file mode 100644
index 0000000..39abc14
--- /dev/null
+++ b/benchmarks/netty3/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.mina</groupId>
+ <artifactId>mina-benchmarks</artifactId>
+ <version>3.0.0-M3-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>mina-benchmarks-netty3</artifactId>
+ <name>Apache MINA Benchmarks against Netty3 tests</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>mina-benchmarks-common</artifactId>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>${netty3.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..077f695
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
@@ -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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Mina3ClientVsNetty3ServerTcpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Mina3TcpBenchmarkClient();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Netty3TcpBenchmarkServer();
+ }
+
+ @Parameters()
+ public static Collection<Object[]> getParameters() {
+ Object[][] parameters = new Object[][] { { 1000000, 10, 2 * 60 }, { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 10 * 1024, 2 * 60 }, { 1000000, 20 * 1024, 2 * 60 }, { 500000, 50 * 1024, 2 * 60 },
+ { 200000, 100 * 1024, 2 * 60 }, { 100000, 200 * 1024, 2 * 60 }, { 50000, 500 * 1024, 2 * 60 },
+ { 20000, 1024 * 1024, 2 * 60 }, { 2000, 10 * 1024 * 1024, 2 * 60 }, { 500, 64 * 1024 * 1024, 2 * 60 } };
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..4c30661
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest.java
@@ -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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Netty3ClientVsMina3ServerTcpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Netty3TcpBenchmarkClient();
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Mina3TcpBenchmarkServer();
+ }
+
+ //TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ Object[][] parameters = new Object[][] { { 1000000, 10, 2 * 60 }, { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 10 * 1024, 2 * 60 }, { 1000000, 20 * 1024, 2 * 60 }, { 500000, 50 * 1024, 2 * 60 },
+ { 200000, 100 * 1024, 2 * 60 }, { 100000, 200 * 1024, 2 * 60 }, { 50000, 500 * 1024, 2 * 60 },
+ { 20000, 1024 * 1024, 2 * 60 }, { 2000, 10 * 1024 * 1024, 2 * 60 }, { 500, 64 * 1024 * 1024, 2 * 60 } };
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..5a6e08d
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Netty3ClientVsMina3ServerUdpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Netty3UdpBenchmarkClient();
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Mina3UdpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ // Note : depending on your OS, the maximum PDU you can send can vary. See sysctl net.inet.udp.maxdgram
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 } ,
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 2 * 1024, 2 * 60 },
+ { 1000000, 4 * 1024, 2 * 60 },
+ { 500000, 8 * 1024, 2 * 60 }}; // No need to test any further, the maximum size for an UDP message is 64Kb
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..a0bccd6
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest.java
@@ -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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkClient;
+import org.apache.mina.core.nio.tcp.Netty3TcpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Netty3ClientVsNetty3ServerTcpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Netty3TcpBenchmarkClient();
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Netty3TcpBenchmarkServer();
+ }
+
+ //TODO: analyze with Netty is so slow on large message: last test lower to 100 messages
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ Object[][] parameters = new Object[][] { { 1000000, 10, 2 * 60 }, { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 10 * 1024, 2 * 60 }, { 1000000, 20 * 1024, 2 * 60 }, { 500000, 50 * 1024, 2 * 60 },
+ { 200000, 100 * 1024, 2 * 60 }, { 100000, 200 * 1024, 2 * 60 }, { 50000, 500 * 1024, 2 * 60 },
+ { 20000, 1024 * 1024, 2 * 60 }, { 2000, 10 * 1024 * 1024, 2 * 60 }, { 500, 64 * 1024 * 1024, 2 * 60 } };
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
new file mode 100644
index 0000000..76d9bf8
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.mina.core;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkClient;
+import org.apache.mina.core.nio.udp.Netty3UdpBenchmarkServer;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest extends BenchmarkBinaryTest {
+
+ /**
+ * @param numberOfMessages
+ * @param messageSize
+ */
+ public Netty3ClientVsNetty3ServerUdpBenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) {
+ super(numberOfMessages, messageSize, timeout);
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkClient getClient() {
+ return new Netty3UdpBenchmarkClient();
+ }
+
+ /** {@inheritDoc}
+ */
+ @Override
+ public BenchmarkServer getServer() {
+ return new Netty3UdpBenchmarkServer();
+ }
+
+ @Parameters(name = "{0} messages of size {1}")
+ public static Collection<Object[]> getParameters() {
+ // Note : depending on your OS, the maximum PDU you can send can vary. See sysctl net.inet.udp.maxdgram
+ Object[][] parameters = new Object[][] {
+ { 1000000, 10, 2 * 60 },
+ { 1000000, 1 * 1024, 2 * 60 },
+ { 1000000, 2 * 1024, 2 * 60 },
+ { 1000000, 4 * 1024, 2 * 60 },
+ { 500000, 8 * 1024, 2 * 60 }}; // No need to test any further, the maximum size for an UDP message is 64Kb
+ return Arrays.asList(parameters);
+ }
+}
http://git-wip-us.apache.org/repos/asf/mina/blob/a79cb81b/benchmarks/netty3/src/test/java/org/apache/mina/core/nio/tcp/Netty3TcpBenchmarkClient.java
----------------------------------------------------------------------
diff --git a/benchmarks/netty3/src/test/java/org/apache/mina/core/nio/tcp/Netty3TcpBenchmarkClient.java b/benchmarks/netty3/src/test/java/org/apache/mina/core/nio/tcp/Netty3TcpBenchmarkClient.java
new file mode 100644
index 0000000..20ca67f
--- /dev/null
+++ b/benchmarks/netty3/src/test/java/org/apache/mina/core/nio/tcp/Netty3TcpBenchmarkClient.java
@@ -0,0 +1,104 @@
+/*
+ * 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.mina.core.nio.tcp;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.mina.core.BenchmarkClient;
+import org.jboss.netty.bootstrap.ClientBootstrap;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.ChannelFactory;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
+
+/**
+ * A Netty 3 TCP CLient.
+ * @author <a href="http://mina.apache.org">Apache MINA Project</a>
+ */
+public class Netty3TcpBenchmarkClient implements BenchmarkClient {
+
+ private ChannelFactory factory;
+
+ /**
+ *
+ */
+ public Netty3TcpBenchmarkClient() {
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void start(final int port, final CountDownLatch counter, final byte[] data) throws IOException {
+ factory = new NioClientSocketChannelFactory();
+ ClientBootstrap bootstrap = new ClientBootstrap(factory);
+ bootstrap.setOption("sendBufferSize", 64 * 1024);
+ bootstrap.setOption("tcpNoDelay", true);
+ bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
+ public ChannelPipeline getPipeline() throws Exception {
+ return Channels.pipeline(new SimpleChannelUpstreamHandler() {
+ private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
+ ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
+ ctx.getChannel().write(buffer);
+ }
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+ if (e.getMessage() instanceof ChannelBuffer) {
+ ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
+ for (int i = 0; i < buffer.readableBytes(); ++i) {
+ counter.countDown();
+ if (counter.getCount() > 0) {
+ sendMessage(ctx, data);
+ } else {
+ ctx.getChannel().close();
+ }
+ }
+ } else {
+ throw new IllegalArgumentException(e.getMessage().getClass().getName());
+ }
+ }
+
+ @Override
+ public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ sendMessage(ctx, data);
+ }
+
+ });
+ }
+ });
+ bootstrap.connect(new InetSocketAddress(port));
+ }
+
+ /**
+ * {@inheritedDoc}
+ */
+ public void stop() throws IOException {
+ factory.releaseExternalResources();
+ }
+}