Browse Source

update smart-socket to 1.4.1 (#4774)

* update dockerfile

* update to 1.0.10-SNAPSHOT

* update to 1.0.10-beta

* fix bug

* update to 1.0.10.1119-beta

* update to 1.0.10.1128-beta

* 还原代码

* update to 1.0.10.1206-beta

* update to 1.0.10.1209-beta

* update to 1.0.10.1214-beta

* 增加缓冲区

* update to 1.0.10-beta

* update to 1.0.10.1231-beta

* update to 1.0.10.0106-beta

* update to 1.0.0107-beta

* update to 1.0.10.0113-beta

* set new pageSize

* update smart-socket to 1.4.0-rc.2

* update to 1.4.0-rc.3

* update smart-socket to 1.4.0-rc.4

* update  to 1.0.10.0221-beta

* update smart-socket to 1.4.0-rc.5

* update maxCompletionHandlersOnStack

* config thread number

* update  to 1.0.10.0324-beta

* update smart-socket to 1.4.0-rc.9

* update smart-socket to 1.4.0-rc.10

* update smart-socket to 1.4.0-rc.11

* update smart-socket to 1.4.0-rc.13

* update smart-socket to 1.4.0

* update smart-socket to 1.4.1-rc.1

* update smart-socket to 1.4.1-rc.2

* update smart-http to 1.0.10.0501-beta

* set thread config

* update smart-socket to 1.4.1

* update smart-socket to 1.4.0-rc.4
三刀 6 years ago
parent
commit
fc1cb550cb

+ 8 - 8
frameworks/Java/smart-socket/pom.xml

@@ -22,15 +22,15 @@
             <groupId>org.smartboot.http</groupId>
             <artifactId>smart-http-server</artifactId>
         </dependency>
-        <!--<dependency>-->
-            <!--<groupId>org.smartboot.socket</groupId>-->
-            <!--<artifactId>aio-core</artifactId>-->
-            <!--<version>1.4.0</version>-->
-        <!--</dependency>-->
         <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>fastjson</artifactId>
-            <version>1.2.47</version>
+            <groupId>org.smartboot.socket</groupId>
+            <artifactId>aio-core</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.jsoniter</groupId>
+            <artifactId>jsoniter</artifactId>
+            <version>0.9.23</version>
         </dependency>
     </dependencies>
     <repositories>

+ 17 - 5
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java

@@ -8,6 +8,9 @@
 
 package org.smartboot.http;
 
+import com.jsoniter.output.JsonStream;
+import com.jsoniter.output.JsonStreamPool;
+import com.jsoniter.spi.JsonException;
 import org.smartboot.http.server.HttpMessageProcessor;
 import org.smartboot.http.server.decode.Http11Request;
 import org.smartboot.http.server.decode.HttpRequestProtocol;
@@ -40,10 +43,19 @@ public class Bootstrap {
 
             @Override
             public void doHandle(HttpRequest request, HttpResponse response) throws IOException {
-                byte[] b = JSON.toJson(new Message("Hello, World!"));
-                response.setContentLength(b.length);
+
                 response.setContentType("application/json");
-                response.getOutputStream().write(b);
+                JsonStream stream = JsonStreamPool.borrowJsonStream();
+                try {
+                    stream.reset(null);
+                    stream.writeVal(Message.class, new Message("Hello, World!"));
+                    response.setContentLength(stream.buffer().tail());
+                    response.getOutputStream().write(stream.buffer().data(), 0, stream.buffer().tail());
+                } catch (IOException e) {
+                    throw new JsonException(e);
+                } finally {
+                    JsonStreamPool.returnJsonStream(stream);
+                }
             }
         });
         http(processor);
@@ -55,10 +67,10 @@ public class Bootstrap {
         AioQuickServer<Http11Request> server = new AioQuickServer<>(8080, new HttpRequestProtocol(), processor);
         server.setReadBufferSize(1024 * 4);
         int cpuNum = Runtime.getRuntime().availableProcessors();
-        int shareNum = Runtime.getRuntime().availableProcessors() * 3 / 4;
+        int shareNum = Runtime.getRuntime().availableProcessors() * 7 / 8;
         server.setBossThreadNum(cpuNum);
         server.setBossShareToWorkerThreadNum(shareNum);
-        server.setWorkerThreadNum(cpuNum - shareNum);
+        server.setWorkerThreadNum((cpuNum - shareNum) * 2);
         try {
             server.start();
         } catch (IOException e) {

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

@@ -1,13 +0,0 @@
-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);
-    }
-}