优化ClientExecutor
This commit is contained in:
@@ -582,25 +582,25 @@ public final class Application {
|
||||
|
||||
ExecutorService workExecutor0 = null;
|
||||
ExecutorService clientExecutor;
|
||||
{
|
||||
if (executorConf == null) {
|
||||
executorConf = DefaultAnyValue.create();
|
||||
}
|
||||
final AtomicReference<ExecutorService> workref = new AtomicReference<>();
|
||||
final int workThreads = executorConf.getIntValue("threads", Math.max(2, Utility.cpus()));
|
||||
boolean workHash = executorConf.getBoolValue("hash", false);
|
||||
if (workThreads > 0) {
|
||||
if (workHash) {
|
||||
workExecutor0 = WorkThread.createHashExecutor(workThreads, "Redkale-HashWorkThread-%s");
|
||||
} else {
|
||||
workExecutor0 = WorkThread.createExecutor(workThreads, "Redkale-WorkThread-%s");
|
||||
}
|
||||
workref.set(workExecutor0);
|
||||
if (executorConf == null) {
|
||||
executorConf = DefaultAnyValue.create();
|
||||
}
|
||||
final int workThreads = executorConf.getIntValue("threads", Math.max(2, Utility.cpus()));
|
||||
boolean workHash = executorConf.getBoolValue("hash", false);
|
||||
if (workThreads > 0) {
|
||||
if (workHash) {
|
||||
workExecutor0 = WorkThread.createHashExecutor(workThreads, "Redkale-HashWorkThread-%s");
|
||||
} else {
|
||||
workExecutor0 = WorkThread.createExecutor(workThreads, "Redkale-WorkThread-%s");
|
||||
}
|
||||
}
|
||||
clientExecutor = workExecutor0;
|
||||
if (clientExecutor == null) {
|
||||
//给所有client给一个默认的ExecutorService
|
||||
final int clientThreads = Math.max(Math.max(2, Utility.cpus()), workThreads / 2);
|
||||
final int clientThreads = Math.max(Math.max(2, Utility.cpus()), workThreads);
|
||||
clientExecutor = WorkThread.createExecutor(clientThreads, "Redkale-DefaultClient-WorkThread-%s");
|
||||
}
|
||||
|
||||
this.workExecutor = workExecutor0;
|
||||
this.resourceFactory.register(RESNAME_APP_EXECUTOR, Executor.class, this.workExecutor);
|
||||
this.resourceFactory.register(RESNAME_APP_EXECUTOR, ExecutorService.class, this.workExecutor);
|
||||
|
||||
@@ -223,37 +223,6 @@ public abstract class ClientConnection<R extends ClientRequest, P> implements Co
|
||||
workThread = request.workThread;
|
||||
request.workThread = null;
|
||||
}
|
||||
// if (rs.exc != null) {
|
||||
// if (workThread == null || workThread == Thread.currentThread() || workThread.inIO()
|
||||
// || workThread.getState() != Thread.State.RUNNABLE) {
|
||||
// if (request != null) {
|
||||
// Traces.currTraceid(request.traceid);
|
||||
// }
|
||||
// respFuture.completeExceptionally(rs.exc);
|
||||
// } else {
|
||||
// workThread.execute(() -> {
|
||||
// if (request != null) {
|
||||
// Traces.currTraceid(request.traceid);
|
||||
// }
|
||||
// respFuture.completeExceptionally(rs.exc);
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// if (workThread == null || workThread == Thread.currentThread() || workThread.inIO()
|
||||
// || workThread.getState() != Thread.State.RUNNABLE) {
|
||||
// if (request != null) {
|
||||
// Traces.currTraceid(request.traceid);
|
||||
// }
|
||||
// respFuture.complete(rs.message);
|
||||
// } else {
|
||||
// workThread.execute(() -> {
|
||||
// if (request != null) {
|
||||
// Traces.currTraceid(request.traceid);
|
||||
// }
|
||||
// respFuture.complete(rs.message);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
if (workThread == null || workThread.getWorkExecutor() == null) {
|
||||
workThread = channel.getReadIOThread();
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import java.util.function.*;
|
||||
import java.util.stream.Stream;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.annotation.Comment;
|
||||
import org.redkale.annotation.*;
|
||||
import org.redkale.annotation.ResourceListener;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import static org.redkale.boot.Application.RESNAME_APP_EXECUTOR;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.WorkThread;
|
||||
import org.redkale.persistence.Entity;
|
||||
@@ -110,6 +112,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
|
||||
private int sourceThreads = Utility.cpus();
|
||||
|
||||
@Resource(name = RESNAME_APP_EXECUTOR, required = false)
|
||||
private ExecutorService sourceExecutor;
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user