diff --git a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/client/DataClient.java b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/client/DataClient.java index 6e09945a3..73f966994 100644 --- a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/client/DataClient.java +++ b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/client/DataClient.java @@ -32,6 +32,7 @@ import cn.edu.tsinghua.iot.benchmark.tsdb.DBConfig; import cn.edu.tsinghua.iot.benchmark.tsdb.DBWrapper; import cn.edu.tsinghua.iot.benchmark.tsdb.TsdbException; +import cn.edu.tsinghua.iot.benchmark.utils.NamedThreadFactory; import cn.edu.tsinghua.iot.benchmark.workload.DataWorkLoad; import cn.edu.tsinghua.iot.benchmark.workload.QueryWorkLoad; import cn.edu.tsinghua.iot.benchmark.workload.interfaces.IDataWorkLoad; @@ -57,7 +58,7 @@ public abstract class DataClient implements Runnable { /** QueryWorkload */ protected final IQueryWorkLoad queryWorkLoad; /** Log related */ - protected final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); + protected final ScheduledExecutorService service; /** Tested DataBase */ protected DBWrapper dbWrapper = null; /** Related Schema */ @@ -88,6 +89,9 @@ public DataClient(int id, CountDownLatch countDownLatch, CyclicBarrier barrier) this.deviceSchemas = MetaDataSchema.getInstance().getDeviceSchemaByClientId(clientThreadId); this.deviceSchemasSize = deviceSchemas.size(); this.measurement = new Measurement(); + this.service = + Executors.newSingleThreadScheduledExecutor( + new NamedThreadFactory("ShowWorkProgress-" + String.valueOf(clientThreadId))); initDBWrappers(); } diff --git a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/measurement/persistence/TestDataPersistence.java b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/measurement/persistence/TestDataPersistence.java index 3c07aa957..bd8dc4f47 100644 --- a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/measurement/persistence/TestDataPersistence.java +++ b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/measurement/persistence/TestDataPersistence.java @@ -22,6 +22,7 @@ import cn.edu.tsinghua.iot.benchmark.conf.Config; import cn.edu.tsinghua.iot.benchmark.conf.ConfigDescriptor; import cn.edu.tsinghua.iot.benchmark.measurement.enums.SystemMetrics; +import cn.edu.tsinghua.iot.benchmark.utils.NamedThreadFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +34,8 @@ public abstract class TestDataPersistence { protected static final Logger LOGGER = LoggerFactory.getLogger(TestDataPersistence.class); protected static final Config config = ConfigDescriptor.getInstance().getConfig(); protected ExecutorService service = - Executors.newFixedThreadPool(config.getTEST_DATA_MAX_CONNECTION()); + Executors.newFixedThreadPool( + config.getTEST_DATA_MAX_CONNECTION(), new NamedThreadFactory("ResultPersistence")); /** * Store system resources metrics data diff --git a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/mode/BaseMode.java b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/mode/BaseMode.java index 78b2b8fb0..58d7b785d 100644 --- a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/mode/BaseMode.java +++ b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/mode/BaseMode.java @@ -29,6 +29,7 @@ import cn.edu.tsinghua.iot.benchmark.tsdb.DBConfig; import cn.edu.tsinghua.iot.benchmark.tsdb.DBWrapper; import cn.edu.tsinghua.iot.benchmark.tsdb.TsdbException; +import cn.edu.tsinghua.iot.benchmark.utils.NamedThreadFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,9 +48,10 @@ public abstract class BaseMode { private static final double NANO_TO_SECOND = 1000000000.0d; protected ExecutorService schemaExecutorService = - Executors.newFixedThreadPool(config.getCLIENT_NUMBER()); + Executors.newFixedThreadPool( + config.getCLIENT_NUMBER(), new NamedThreadFactory("SchemaClient")); protected ExecutorService executorService = - Executors.newFixedThreadPool(config.getCLIENT_NUMBER()); + Executors.newFixedThreadPool(config.getCLIENT_NUMBER(), new NamedThreadFactory("DataClient")); protected CountDownLatch schemaDownLatch = new CountDownLatch(config.getCLIENT_NUMBER()); protected CyclicBarrier schemaBarrier = new CyclicBarrier(config.getCLIENT_NUMBER()); protected CountDownLatch dataDownLatch = new CountDownLatch(config.getCLIENT_NUMBER()); diff --git a/core/src/main/java/cn/edu/tsinghua/iot/benchmark/utils/NamedThreadFactory.java b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/utils/NamedThreadFactory.java new file mode 100644 index 000000000..ed9c1587a --- /dev/null +++ b/core/src/main/java/cn/edu/tsinghua/iot/benchmark/utils/NamedThreadFactory.java @@ -0,0 +1,27 @@ +package cn.edu.tsinghua.iot.benchmark.utils; + +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +public class NamedThreadFactory implements ThreadFactory { + private final String poolName; + private final AtomicInteger count = new AtomicInteger(1); + private final ThreadFactory threadFactory; + + public NamedThreadFactory(String name) { + this.poolName = name; + this.threadFactory = Executors.defaultThreadFactory(); + } + + private String getThreadName() { + return poolName + "-thread-" + String.valueOf(count.getAndIncrement()); + } + + @Override + public Thread newThread(Runnable r) { + Thread thread = threadFactory.newThread(r); + thread.setName(getThreadName()); + return thread; + } +} diff --git a/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java b/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java index f64ae606e..f31dfd584 100644 --- a/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java +++ b/iotdb-1.1/src/main/java/cn/edu/tsinghua/iot/benchmark/iotdb110/IoTDB.java @@ -43,6 +43,7 @@ import cn.edu.tsinghua.iot.benchmark.tsdb.DBConfig; import cn.edu.tsinghua.iot.benchmark.tsdb.IDatabase; import cn.edu.tsinghua.iot.benchmark.tsdb.TsdbException; +import cn.edu.tsinghua.iot.benchmark.utils.NamedThreadFactory; import cn.edu.tsinghua.iot.benchmark.utils.TimeUtils; import cn.edu.tsinghua.iot.benchmark.workload.query.impl.AggRangeQuery; import cn.edu.tsinghua.iot.benchmark.workload.query.impl.AggRangeValueQuery; @@ -115,7 +116,8 @@ public void init() throws TsdbException { try { ioTDBConnection = new SingleNodeJDBCConnection(dbConfig); ioTDBConnection.init(); - this.service = Executors.newSingleThreadExecutor(); + this.service = + Executors.newSingleThreadExecutor(new NamedThreadFactory("DataClientExecuteJob")); } catch (Exception e) { throw new TsdbException(e); }