Quellcode durchsuchen

改用longAdder改进性能

FutureYu vor 1 Jahr
Ursprung
Commit
81efbd5604

+ 20 - 19
insert-app/src/main/java/db/entity/Statistic.java

@@ -6,6 +6,7 @@ import lombok.Data;
 
 import java.text.ParseException;
 import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
 
 /**
  * 功能描述
@@ -16,51 +17,51 @@ import java.util.concurrent.atomic.AtomicLong;
 @Data
 public class Statistic {
     long beginTime;
-    AtomicLong dataCount = new AtomicLong();
-    AtomicLong dataCountTsdbSuccess = new AtomicLong();
-    AtomicLong dataCountDiskSuccess = new AtomicLong();
+    LongAdder dataCount = new LongAdder();
+    LongAdder dataCountTsdbSuccess = new LongAdder();
+    LongAdder dataCountDiskSuccess = new LongAdder();
 
     public Statistic() {
         beginTime = System.currentTimeMillis();
     }
 
-    public long incrDataCount() {
-        return this.dataCount.incrementAndGet();
+    public void incrDataCount() {
+        this.dataCount.increment();
     }
 
-    public long increDataCountTsdbSuccess() {
-        return this.dataCountTsdbSuccess.incrementAndGet();
+    public void increDataCountTsdbSuccess() {
+        this.dataCountTsdbSuccess.increment();
     }
 
-    public long increDataCountTsdbSuccess(int count) {
-        return this.dataCountTsdbSuccess.addAndGet(count);
+    public void increDataCountTsdbSuccess(int count) {
+        this.dataCountTsdbSuccess.add(count);
     }
 
-    public long increDataCountDiskSuccess() {
-        return this.dataCountDiskSuccess.incrementAndGet();
+    public void increDataCountDiskSuccess() {
+        this.dataCountDiskSuccess.increment();
     }
 
-    public long increDataCountDiskSuccess(int count) {
-        return this.dataCountDiskSuccess.addAndGet(count);
+    public void increDataCountDiskSuccess(int count) {
+        this.dataCountDiskSuccess.add(count);
     }
 
     public double dataRate() {
         long time = System.currentTimeMillis() - this.beginTime;
-        return dataCount.get() * 1000.0 / time;
+        return dataCount.longValue() * 1000.0 / time;
     }
 
     public StatisticDto toDto() {
-        StatisticDto statisticDto = new StatisticDto(this.beginTime, this.dataCount.get(),
-                this.dataCountTsdbSuccess.get(), this.dataCountDiskSuccess.get());
+        StatisticDto statisticDto = new StatisticDto(this.beginTime, this.dataCount.longValue(),
+                this.dataCountTsdbSuccess.longValue(), this.dataCountDiskSuccess.longValue());
         return statisticDto;
     }
 
     @Override
     public String toString() {
         long time = System.currentTimeMillis() - this.beginTime;
-        double dataRate = dataCount.get() * 1000.0 / time;
-        double dataCountTsdbSuccessRate = dataCountTsdbSuccess.get() * 1000.0 / time;
-        double dataCountDiskSuccessRate = dataCountDiskSuccess.get() * 1000.0 / time;
+        double dataRate = dataCount.longValue() * 1000.0 / time;
+        double dataCountTsdbSuccessRate = dataCountTsdbSuccess.longValue() * 1000.0 / time;
+        double dataCountDiskSuccessRate = dataCountDiskSuccess.longValue() * 1000.0 / time;
 
         String beginTimeString = "";
         try {

+ 10 - 10
insert-app/src/main/java/db/service/StatisticService.java

@@ -15,24 +15,24 @@ public class StatisticService {
 
     Statistic statistic = new Statistic();
 
-    public long incrDataCount() {
-        return this.statistic.incrDataCount();
+    public void incrDataCount() {
+        this.statistic.incrDataCount();
     }
 
-    public long increDataCountTsdbSuccess() {
-        return this.statistic.increDataCountTsdbSuccess();
+    public void increDataCountTsdbSuccess() {
+        this.statistic.increDataCountTsdbSuccess();
     }
 
-    public long increDataCountTsdbSuccess(int count) {
-        return this.statistic.increDataCountTsdbSuccess(count);
+    public void increDataCountTsdbSuccess(int count) {
+        this.statistic.increDataCountTsdbSuccess(count);
     }
 
-    public long increDataCountDiskSuccess() {
-        return this.statistic.increDataCountDiskSuccess();
+    public void increDataCountDiskSuccess() {
+        this.statistic.increDataCountDiskSuccess();
     }
 
-    public long increDataCountDiskSuccess(int count) {
-        return this.statistic.increDataCountDiskSuccess(count);
+    public void increDataCountDiskSuccess(int count) {
+        this.statistic.increDataCountDiskSuccess(count);
     }
 
     public Statistic getStatistic() {