Skip to content

Commit

Permalink
use NamedThreadFactory everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuheng55555 committed Sep 21, 2023
1 parent 0966152 commit 02e8b02
Showing 5 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
@@ -43,6 +44,7 @@
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public abstract class DataClient implements Runnable {
private static final Logger LOGGER = LoggerFactory.getLogger(DataClient.class);
@@ -57,7 +59,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 +90,7 @@ 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();
}

Original file line number Diff line number Diff line change
@@ -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,7 @@ 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
Original file line number Diff line number Diff line change
@@ -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,9 @@ 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());
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@

package cn.edu.tsinghua.iot.benchmark.iotdb110;

import cn.edu.tsinghua.iot.benchmark.utils.NamedThreadFactory;
import org.apache.iotdb.isession.template.Template;
import org.apache.iotdb.isession.util.Version;
import org.apache.iotdb.rpc.IoTDBConnectionException;
@@ -115,7 +116,7 @@ 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);
}

0 comments on commit 02e8b02

Please sign in to comment.