Ver código fonte

add new test [Java/baseio] (#4157)

* * tfb test for baseio

* fix word spell

* * add new test baseio to .travis.yml

* Update README.md

* * add json test case
Kai Wang 7 anos atrás
pai
commit
d84214bab7

+ 1 - 0
.travis.yml

@@ -40,6 +40,7 @@ env:
      - "TESTDIR=Java/activeweb"
      - "TESTDIR=Java/armeria"
      - "TESTDIR=Java/baratine"
+     - "TESTDIR=Java/baseio"
      - "TESTDIR=Java/bayou"
      - "TESTDIR=Java/blade"
      - "TESTDIR=Java/comsat"

+ 24 - 0
frameworks/Java/baseio/README.md

@@ -0,0 +1,24 @@
+# Baseio Benchmarking Test
+
+ [Baseio](https://github.com/generallycloud/baseio) is an easy of use io framework project based on java nio
+ 
+### Test Type Implementation Source Code
+
+* [JSON](src/main/java/hello/TestHttpLoadServer.java)
+* [PLAINTEXT](src/main/java/hello/TestHttpLoadServer.java)
+
+
+## Important Libraries
+The tests were run with:
+* [baseio](https://github.com/generallycloud/baseio/)
+* [fastjson](https://github.com/alibaba/fastjson/)
+
+## Test URLs
+### JSON
+
+http://localhost:8080/json
+
+### PLAINTEXT
+
+http://localhost:8080/plaintext
+

+ 10 - 0
frameworks/Java/baseio/baseio.dockerfile

@@ -0,0 +1,10 @@
+FROM maven:3.5.3-jdk-10-slim as maven
+WORKDIR /baseio
+COPY pom.xml pom.xml
+COPY src src
+RUN mvn compile assembly:single -q
+
+FROM openjdk:10-jre-slim
+WORKDIR /baseio
+COPY --from=maven /baseio/target/baseio-example-0.1-jar-with-dependencies.jar app.jar
+CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-jar", "app.jar"]

+ 25 - 0
frameworks/Java/baseio/benchmark_config.json

@@ -0,0 +1,25 @@
+{
+  "framework": "baseio",
+  "tests": [{
+      "default": {
+      	"json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Platform",
+        "database": "None",
+        "framework": "None",
+        "language": "Java",
+        "flavor": "None",
+        "orm": "None",
+        "platform": "baseio",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "baseio",
+        "notes": "",
+        "versus": "baseio"
+      }
+    }
+  ]
+}

+ 68 - 0
frameworks/Java/baseio/pom.xml

@@ -0,0 +1,68 @@
+<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/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+
+	<groupId>com.techempower</groupId>
+	<artifactId>baseio-example</artifactId>
+	<version>0.1</version>
+
+	<properties>
+		<maven.compiler.source>1.8</maven.compiler.source>
+		<maven.compiler.target>1.8</maven.compiler.target>
+	</properties>
+
+	<packaging>jar</packaging>
+
+	<dependencies>
+
+		<dependency>
+			<groupId>com.generallycloud</groupId>
+			<artifactId>baseio-all</artifactId>
+			<version>3.2.8.RELEASE</version>
+		</dependency>
+		
+		<dependency>
+		    <groupId>com.alibaba</groupId>
+		    <artifactId>fastjson</artifactId>
+		    <version>1.2.51</version>
+		</dependency>
+
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<inherited>true</inherited>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.8.0</version>
+				<configuration>
+					<debug>false</debug>
+				</configuration>
+			</plugin>
+			<plugin>
+				<artifactId>maven-assembly-plugin</artifactId>
+				<configuration>
+					<archive>
+						<manifest>
+							<mainClass>hello.TestHttpLoadServer</mainClass>
+						</manifest>
+					</archive>
+					<descriptorRefs>
+						<descriptorRef>jar-with-dependencies</descriptorRef>
+					</descriptorRefs>
+				</configuration>
+				<executions>
+					<execution>
+						<id>make-assembly</id> <!-- this is used for inheritance merges -->
+						<phase>package</phase> <!-- bind to the packaging phase -->
+						<goals>
+							<goal>single</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+</project>

+ 94 - 0
frameworks/Java/baseio/src/main/java/hello/TestHttpLoadServer.java

@@ -0,0 +1,94 @@
+/*
+ * Copyright 2015-2017 GenerallyCloud.com
+ *  
+ * Licensed 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 hello;
+
+import com.alibaba.fastjson.JSON;
+import com.generallycloud.baseio.Constants;
+import com.generallycloud.baseio.buffer.ByteBuf;
+import com.generallycloud.baseio.codec.http11.HttpHeader;
+import com.generallycloud.baseio.codec.http11.HttpStatic;
+import com.generallycloud.baseio.codec.http11.HttpStatus;
+import com.generallycloud.baseio.codec.http11.ServerHttpCodec;
+import com.generallycloud.baseio.codec.http11.ServerHttpFrame;
+import com.generallycloud.baseio.common.Encoding;
+import com.generallycloud.baseio.component.ChannelAcceptor;
+import com.generallycloud.baseio.component.ChannelContext;
+import com.generallycloud.baseio.component.IoEventHandle;
+import com.generallycloud.baseio.component.NioEventLoopGroup;
+import com.generallycloud.baseio.component.NioSocketChannel;
+import com.generallycloud.baseio.log.LoggerFactory;
+import com.generallycloud.baseio.protocol.Frame;
+
+public class TestHttpLoadServer {
+    
+    static final byte[] STATIC_PLAINTEXT = "Hello, World!".getBytes(Encoding.UTF8);
+    static final byte[] CONTENT_TYPE_JSON = "application/json".getBytes(Encoding.UTF8);
+	
+    public static void main(String[] args) throws Exception {
+    	LoggerFactory.setLogLevel(LoggerFactory.LEVEL_ERROR);
+    	System.setProperty(Constants.DEVELOP_DEBUG_KEY, "false");
+        
+        IoEventHandle eventHandle = new IoEventHandle() {
+
+            @Override
+            public void accept(NioSocketChannel ch, Frame frame) throws Exception {
+            	ServerHttpFrame f = (ServerHttpFrame) frame;
+            	String action = f.getRequestURI();
+            	f.setResponseHeader(HttpHeader.Connection_Bytes, null);
+                
+            	if("/plaintext".equals(action)){
+            		frame.write(STATIC_PLAINTEXT);
+            		f.setResponseHeader(HttpHeader.Content_Type_Bytes, HttpStatic.plain_bytes);
+            	}else if("/json".equals(action)){
+            		frame.write(JSON.toJSONString(new Message("Hello, World!")), ch);
+            		f.setResponseHeader(HttpHeader.Content_Type_Bytes, CONTENT_TYPE_JSON);
+            	}else{
+            		frame.write("404,page not found!",ch);
+            		f.setStatus(HttpStatus.C404);
+            	}
+                ByteBuf buf = ch.encode(frame);
+                ch.flush(buf);
+                f.release(ch.getEventLoop());
+            }
+
+        };
+
+        NioEventLoopGroup group = new NioEventLoopGroup();
+        group.setMemoryPoolCapacity(1024 * 256);
+        group.setMemoryPoolUnit(512);
+        ChannelContext context = new ChannelContext(8080);
+        ChannelAcceptor acceptor = new ChannelAcceptor(context, group);
+        context.setProtocolCodec(new ServerHttpCodec(1024 * 8));
+        context.setIoEventHandle(eventHandle);
+
+        acceptor.bind();
+    }
+    
+    static class Message {
+
+    	private final String message;
+
+    	public Message(String message) {
+    		this.message = message;
+    	}
+
+    	public String getMessage() {
+    		return message;
+    	}
+
+    }
+    
+}