Skip to content

Commit

Permalink
Fix some bugs (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuheng55555 authored Sep 12, 2023
1 parent fe76dc2 commit 0966152
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void loadProps() {
throw new RuntimeException(
"The database "
+ config.getDbConfig().getDB_SWITCH()
+ " can't use microsecond precision");
+ " can't use us/ns precision");
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;

public class Measurement {

Expand Down Expand Up @@ -120,36 +121,27 @@ public void calculateMetrics(List<Operation> operations) {
Metric.MAX_THREAD_LATENCY_SUM
.getTypeValueMap()
.put(operation, operationLatencySumThisClient.get(operation));
Metric.MIN_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.0));
Metric.MAX_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(1.0));
Metric.P10_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.1));
Metric.P25_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.25));
Metric.MEDIAN_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.50));
Metric.P75_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.75));
Metric.P90_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.90));
Metric.P95_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.95));
Metric.P99_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.99));
Metric.P999_LATENCY
.getTypeValueMap()
.put(operation, operationLatencyDigest.get(operation).quantile(0.999));
Function<Double, Double> quantileOrItself =
(q) -> {
if (operationLatencyDigest.get(operation).size() > 1) {
return operationLatencyDigest.get(operation).quantile(q);
} else {
// com.clearspring.analytics.stream.quantile.TDigest.quantile needs
// result size greater than 1 to calculate.
// If there is only one result, just return this result instead of quantile
return operationLatencyDigest.get(operation).centroids().iterator().next().mean();
}
};
Metric.MIN_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.0));
Metric.MAX_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(1.0));
Metric.P10_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.1));
Metric.P25_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.25));
Metric.MEDIAN_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.50));
Metric.P75_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.75));
Metric.P90_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.90));
Metric.P95_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.95));
Metric.P99_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.99));
Metric.P999_LATENCY.getTypeValueMap().put(operation, quantileOrItself.apply(0.999));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected static void finalMeasure(
} catch (IllegalArgumentException e) {
LOGGER.error(
"Failed to show metric, please check the relation between LOOP and OPERATION_PROPORTION");
e.printStackTrace();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

/** this class will create more than one connection. */
Expand Down Expand Up @@ -691,7 +692,7 @@ protected Status executeQueryAndGetStatus(String sql, Operation operation) {
LOGGER.info("{} query SQL: {}", Thread.currentThread().getName(), executeSQL);
}
AtomicInteger line = new AtomicInteger();
AtomicInteger queryResultPointNum = new AtomicInteger();
AtomicLong queryResultPointNum = new AtomicLong();
AtomicBoolean isOk = new AtomicBoolean(true);
try (Statement statement = ioTDBConnection.getConnection().createStatement()) {
List<List<Object>> records = new ArrayList<>();
Expand Down Expand Up @@ -724,8 +725,12 @@ protected Status executeQueryAndGetStatus(String sql, Operation operation) {
LOGGER.error("exception occurred when execute query={}", executeSQL, e);
isOk.set(false);
}
queryResultPointNum.set(
line.get() * config.getQUERY_SENSOR_NUM() * config.getQUERY_DEVICE_NUM());
long resultPointNum = line.get();
if (!Operation.LATEST_POINT_QUERY.equals(operation)) {
resultPointNum *= config.getQUERY_SENSOR_NUM();
resultPointNum *= config.getQUERY_DEVICE_NUM();
}
queryResultPointNum.set(resultPointNum);
});
try {
future.get(config.getREAD_OPERATION_TIMEOUT_MS(), TimeUnit.MILLISECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

public class IoTDBSessionBase extends IoTDB {
Expand Down Expand Up @@ -174,9 +175,8 @@ protected Status executeQueryAndGetStatus(String sql, Operation operation) {
LOGGER.info("{} query SQL: {}", Thread.currentThread().getName(), executeSQL);
}
AtomicInteger line = new AtomicInteger();
AtomicInteger queryResultPointNum = new AtomicInteger();
AtomicLong queryResultPointNum = new AtomicLong();
AtomicBoolean isOk = new AtomicBoolean(true);

try {
List<List<Object>> records = new ArrayList<>();
future =
Expand Down Expand Up @@ -224,8 +224,12 @@ protected Status executeQueryAndGetStatus(String sql, Operation operation) {
LOGGER.error("exception occurred when execute query={}", executeSQL, e);
isOk.set(false);
}
queryResultPointNum.set(
line.get() * config.getQUERY_SENSOR_NUM() * config.getQUERY_DEVICE_NUM());
long resultPointNum = line.get();
if (!Operation.LATEST_POINT_QUERY.equals(operation)) {
resultPointNum *= config.getQUERY_SENSOR_NUM();
resultPointNum *= config.getQUERY_DEVICE_NUM();
}
queryResultPointNum.set(resultPointNum);
});
try {
future.get(config.getREAD_OPERATION_TIMEOUT_MS(), TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit 0966152

Please sign in to comment.