Przeglądaj źródła

Upgrade hserver Framework version and optimize configuration (#7163)

* hserver framework submit

* hserver framework submit

* lowercase fix

* Required response header missing: Date fix

* Date format fix

* update hserver version

* update hserver threadPool

* update hserver

* update hserver

* update hserver query

* update hserver query

* Update README.md

* update hserver query

* update hserver query

* update hserver query

* update hserver query

* update hserver query

* update hserver query

* Optimal configuration of hserver framework

* Optimal configuration of hserver framework

* Optimal configuration of hserver framework

* Upgrade hserver Framework version and optimize configuration

Co-authored-by: 黑小马 <[email protected]>
黑小马 3 lat temu
rodzic
commit
58118098e2

+ 1 - 1
frameworks/Java/hserver/pom.xml

@@ -11,7 +11,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <version.hikaricp>3.3.1</version.hikaricp>
         <version.postgres>42.3.3</version.postgres>
-        <version.hserver>2.9.80</version.hserver>
+        <version.hserver>2.9.81</version.hserver>
     </properties>
 
     <dependencies>

+ 1 - 0
frameworks/Java/hserver/src/main/java/com/test/hserver/StartApp.java

@@ -11,6 +11,7 @@ import top.hserver.core.server.context.ConstConfig;
 public class StartApp {
 
     public static void main(String[] args) {
+        ConstConfig.workerPool=Runtime.getRuntime().availableProcessors();
         HServerApplication.run(StartApp.class, 8888, args);
     }
 }

+ 6 - 6
frameworks/Java/hserver/src/main/java/com/test/hserver/controller/TestController.java

@@ -32,13 +32,13 @@ public class TestController {
 
     @GET("/json")
     public Message json(HttpResponse response) {
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         return new Message();
     }
 
     @GET("/plaintext")
     public String plaintext(HttpResponse response) {
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         return HELLO;
     }
 
@@ -54,7 +54,7 @@ public class TestController {
                 }
             }
         }
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         response.sendJson(result);
     }
 
@@ -72,7 +72,7 @@ public class TestController {
                 }
             }
         }
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         response.sendJson(result);
     }
 
@@ -107,7 +107,7 @@ public class TestController {
                 statement.executeUpdate();
             }
         }
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         response.sendJson(result);
     }
 
@@ -125,7 +125,7 @@ public class TestController {
         }
         fortunes.add(new Fortune(0, "Additional fortune added at request time."));
         Collections.sort(fortunes);
-        response.setHeader("Date", DateUtil.getNow());
+        response.setHeader("Date", DateUtil.getTime());
         Map<String,Object> data=new HashMap<>();
         data.put("data",fortunes);
         response.sendTemplate("fortunes.ftl",data);

+ 15 - 0
frameworks/Java/hserver/src/main/java/com/test/hserver/task/TimeAdd.java

@@ -0,0 +1,15 @@
+package com.test.hserver.task;
+
+import com.test.hserver.util.DateUtil;
+import top.hserver.core.ioc.annotation.Bean;
+import top.hserver.core.ioc.annotation.Task;
+
+@Bean
+public class TimeAdd {
+
+    @Task(name = "时间计算", time = "1000")
+    public void add() {
+        DateUtil.time = DateUtil.getNow();
+    }
+
+}

+ 8 - 1
frameworks/Java/hserver/src/main/java/com/test/hserver/util/DateUtil.java

@@ -14,5 +14,12 @@ public class DateUtil {
     public static String getNow() {
         return GMT_FMT.format(LocalDateTime.now().atZone(zoneId));
     }
-
+    public static String time;
+    public static String getTime(){
+        if (time==null){
+            time=getNow();
+            return time;
+        }
+        return time;
+    }
 }

+ 1 - 0
frameworks/Java/hserver/src/main/resources/app.properties

@@ -3,4 +3,5 @@ username= benchmarkdbuser
 password= benchmarkdbpass
 maximumPoolSize= 256
 level=info
+businessPool=-1