forked from apache/mina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the benchmark module for Netty4
- Loading branch information
Showing
18 changed files
with
1,569 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?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-parent</artifactId> | ||
<version>3.0.0-M1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>mina-benchmarks2</artifactId> | ||
<groupId>org.apache.mina</groupId> | ||
<name>Apache MINA Benchmarks tests for Netty4</name> | ||
|
||
<properties> | ||
<!-- defined in order to run against a different MINA version --> | ||
<mina.version>${project.version}</mina.version> | ||
<netty.version>4.0.0.CR3</netty.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mina-core</artifactId> | ||
<version>${mina.version}</version> | ||
<type>bundle</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-all</artifactId> | ||
<version>${netty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
124 changes: 124 additions & 0 deletions
124
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkBinaryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* 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.apache.mina.core.BenchmarkFactory.Type; | ||
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; | ||
|
||
/** | ||
* @author <a href="http://mina.apache.org">Apache MINA Project</a> | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public abstract class BenchmarkBinaryTest { | ||
private int numberOfMessages; | ||
|
||
private int port; | ||
|
||
private BenchmarkServer server; | ||
|
||
private BenchmarkClient client; | ||
|
||
private int messageSize; | ||
|
||
private int timeout; | ||
|
||
private byte[] data; | ||
|
||
public BenchmarkBinaryTest(int numberOfMessages, int messageSize, int timeout) { | ||
this.numberOfMessages = numberOfMessages; | ||
this.messageSize = messageSize; | ||
this.timeout = timeout; | ||
} | ||
|
||
public abstract Type getClientType(); | ||
|
||
public abstract Type getServerType(); | ||
|
||
@Parameters(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 = 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 | ||
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); | ||
|
||
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
42 changes: 42 additions & 0 deletions
42
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkClient; | ||
import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkClient; | ||
|
||
/** | ||
* @author <a href="http://mina.apache.org">Apache MINA Project</a> | ||
*/ | ||
public class BenchmarkClientFactory implements BenchmarkFactory<BenchmarkClient> { | ||
|
||
public static final BenchmarkClientFactory INSTANCE = new BenchmarkClientFactory(); | ||
|
||
public BenchmarkClient get(Type type) { | ||
switch (type) { | ||
case Netty4_tcp: | ||
return new Netty4TcpBenchmarkClient(); | ||
case Netty4_udp: | ||
return new Netty4UdpBenchmarkClient(); | ||
default: | ||
throw new IllegalArgumentException("Invalid type " + type); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Common interface for client and server factories | ||
* | ||
* @author <a href="http://mina.apache.org">Apache MINA Project</a> | ||
*/ | ||
public interface BenchmarkFactory<T> { | ||
/** | ||
* The different types of providers | ||
*/ | ||
public enum Type { | ||
Mina3_udp, Mina3_tcp, Netty4_tcp, Netty4_udp | ||
} | ||
|
||
/** | ||
* Allocate a provider. | ||
* | ||
* @param type the provider type | ||
* @return the allocated provider | ||
*/ | ||
public T get(Type type); | ||
} |
35 changes: 35 additions & 0 deletions
35
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
51 changes: 51 additions & 0 deletions
51
benchmarks2/src/test/java/org/apache/mina/core/BenchmarkServerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 org.apache.mina.core.nio.tcp.Mina3TcpBenchmarkServer; | ||
import org.apache.mina.core.nio.tcp.Netty4TcpBenchmarkServer; | ||
import org.apache.mina.core.nio.udp.Mina3UdpBenchmarkServer; | ||
import org.apache.mina.core.nio.udp.Netty4UdpBenchmarkServer; | ||
|
||
/** | ||
* @author <a href="http://mina.apache.org">Apache MINA Project</a> | ||
*/ | ||
public class BenchmarkServerFactory implements BenchmarkFactory<BenchmarkServer> { | ||
|
||
public static final BenchmarkServerFactory INSTANCE = new BenchmarkServerFactory(); | ||
|
||
/** | ||
* {@inheritedDoc} | ||
*/ | ||
public BenchmarkServer get(org.apache.mina.core.BenchmarkFactory.Type type) { | ||
switch (type) { | ||
case Mina3_tcp: | ||
return new Mina3TcpBenchmarkServer(); | ||
case Mina3_udp: | ||
return new Mina3UdpBenchmarkServer(); | ||
case Netty4_tcp: | ||
return new Netty4TcpBenchmarkServer(); | ||
case Netty4_udp: | ||
return new Netty4UdpBenchmarkServer(); | ||
default: | ||
throw new IllegalArgumentException("Invalid type " + type); | ||
} | ||
} | ||
} |
Oops, something went wrong.