浏览代码

smart-socket 1.0 (#3993)

* smart-socket 1.0

* smart-socket 1.0
三刀 7 年之前
父节点
当前提交
66606451d3

+ 1 - 0
.travis.yml

@@ -68,6 +68,7 @@ env:
      - "TESTDIR=Java/revenj-jvm"
      - "TESTDIR=Java/servlet"
      - "TESTDIR=Java/servlet3"
+     - "TESTDIR=Java/smart-socket"
      - "TESTDIR=Java/spark"
      - "TESTDIR=Java/spring"
      - "TESTDIR=Java/tapestry"

+ 23 - 0
frameworks/Java/smart-socket/README.md

@@ -0,0 +1,23 @@
+# smart-socket Benchmarking Test
+
+
+This is the smart-socket portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
+
+### JSON Encoding Test
+* [JSON test source](src/main/java/org/smartboot/http/HttpBootstrap.java)
+* [Plaintext test source](src/main/java/org/smartboot/http/HttpBootstrap.java)
+
+## Versions
+
+* [Java OpenJDK 1.8](http://openjdk.java.net/)
+* [smart-socket 1.3.12](https://github.com/smartboot/smart-socket)
+
+## Test URLs
+
+### JSON Encoding Test
+
+    http://localhost:8080/json
+    
+### Plaintext Encoding Test
+
+    http://localhost:8080/plaintext

+ 26 - 0
frameworks/Java/smart-socket/benchmark_config.json

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

+ 80 - 0
frameworks/Java/smart-socket/pom.xml

@@ -0,0 +1,80 @@
+<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>
+
+    <groupId>org.smartboot.socket</groupId>
+    <artifactId>smart-socket-benchmark</artifactId>
+    <version>1.0</version>
+    <packaging>jar</packaging>
+    <parent>
+        <groupId>org.smartboot.http</groupId>
+        <artifactId>smart-http-parent</artifactId>
+        <version>1.0.0</version>
+    </parent>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <commons.lang.version>2.6</commons.lang.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.smartboot.http</groupId>
+            <artifactId>smart-http-server</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.47</version>
+        </dependency>
+    </dependencies>
+    <repositories>
+        <repository>
+            <id>central</id>
+            <name>Central Repository</name>
+            <url>https://repo.maven.apache.org/maven2</url>
+        </repository>
+    </repositories>
+    <pluginRepositories>
+        <pluginRepository>
+            <id>central</id>
+            <name>Central Repository</name>
+            <url>https://repo.maven.apache.org/maven2</url>
+        </pluginRepository>
+    </pluginRepositories>
+    <build>
+        <plugins>
+
+            <plugin>
+                <inherited>true</inherited>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.7.0</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <optimize>true</optimize>
+                    <debug>false</debug>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>3.1.0</version>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+        </plugins>
+    </build>
+</project>

+ 10 - 0
frameworks/Java/smart-socket/smart-socket.dockerfile

@@ -0,0 +1,10 @@
+FROM maven:3.5.3-jdk-10-slim as maven
+WORKDIR /smart-socket
+COPY pom.xml pom.xml
+COPY src src
+RUN mvn compile assembly:single
+
+FROM openjdk:10-jre-slim
+WORKDIR /smart-socket
+COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-dependencies.jar app.jar
+CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-cp", "app.jar", "org.smartboot.http.HttpBootstrap"]

+ 62 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/HttpBootstrap.java

@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018, org.smartboot. All rights reserved.
+ * project name: smart-socket
+ * file name: HttpBootstrap.java
+ * Date: 2018-01-28
+ * Author: sandao
+ */
+
+package org.smartboot.http;
+
+import org.smartboot.http.common.HttpEntityV2;
+import org.smartboot.http.common.HttpRequestProtocol;
+import org.smartboot.http.common.utils.HttpHeaderConstant;
+import org.smartboot.http.server.handle.HttpHandle;
+import org.smartboot.http.server.http11.HttpResponse;
+import org.smartboot.socket.MessageProcessor;
+import org.smartboot.socket.transport.AioQuickServer;
+
+import java.io.IOException;
+
+public class HttpBootstrap {
+    static byte[] body = "Hello, World!".getBytes();
+
+    public static void main(String[] args) {
+        org.smartboot.http.server.HttpV2MessageProcessor processor = new org.smartboot.http.server.HttpV2MessageProcessor(System.getProperty("webapps.dir", "./"));
+        processor.route("/plaintext", new HttpHandle() {
+
+
+            @Override
+            public void doHandle(HttpEntityV2 request, HttpResponse response) throws IOException {
+
+                response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, body.length + "");
+                response.setHeader(HttpHeaderConstant.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
+                response.getOutputStream().write(body);
+            }
+        });
+        processor.route("/json", new HttpHandle() {
+            @Override
+            public void doHandle(HttpEntityV2 request, HttpResponse response) throws IOException {
+                byte[] b = JSON.toJson(new Message("Hello, World!"));
+                response.setHeader(HttpHeaderConstant.Names.CONTENT_LENGTH, b.length + "");
+                response.setHeader(HttpHeaderConstant.Names.CONTENT_TYPE, "application/json");
+                response.getOutputStream().write(b);
+            }
+        });
+        http(processor);
+//        https(processor);
+    }
+
+    public static void http(MessageProcessor<org.smartboot.http.common.HttpEntityV2> processor) {
+        // 定义服务器接受的消息类型以及各类消息对应的处理器
+        AioQuickServer<org.smartboot.http.common.HttpEntityV2> server = new AioQuickServer<org.smartboot.http.common.HttpEntityV2>(8080, new HttpRequestProtocol(), processor);
+        server.setWriteQueueSize(4);
+        server.setReadBufferSize(1024);
+//        server.setThreadNum(8);
+        try {
+            server.start();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 13 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JSON.java

@@ -0,0 +1,13 @@
+package org.smartboot.http;
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * @author 三刀
+ * @version V1.0 , 2018/8/12
+ */
+public class JSON {
+    public static byte[] toJson(Object obj) {
+        return JSONObject.toJSONBytes(obj);
+    }
+}

+ 21 - 0
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Message.java

@@ -0,0 +1,21 @@
+package org.smartboot.http;
+
+/**
+ * @author 三刀
+ * @version V1.0 , 2018/8/12
+ */
+public class Message {
+    private String message;
+
+    public Message(String message) {
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}