优化client

This commit is contained in:
redkale
2023-03-28 13:16:10 +08:00
parent a61d515a49
commit d7655aa2be
5 changed files with 9 additions and 43 deletions

View File

@@ -96,27 +96,12 @@ public final class Application {
*/ */
public static final String RESNAME_APP_EXECUTOR = "APP_EXECUTOR"; public static final String RESNAME_APP_EXECUTOR = "APP_EXECUTOR";
/**
* 当前进程的客共享AsyncGroup, 有且只有一个server节点NodeServer此字段值才有效
*
* @since 2.8.0
*/
public static final String RESNAME_APP_GLOBAL_IOGROUP = "APP_GLOBAL_IOGROUP";
/**
* 当前进程的客户端组, 类型AsyncGroup
*
* @since 2.8.0
*/
public static final String RESNAME_APP_CLIENT_IOGROUP = "APP_CLIENT_IOGROUP";
/** /**
* 使用RESNAME_APP_CLIENT_IOGROUP代替 * 使用RESNAME_APP_CLIENT_IOGROUP代替
* *
* @since 2.3.0 * @since 2.3.0
* *
*/ */
@Deprecated(since = "2.8.0")
public static final String RESNAME_APP_CLIENT_ASYNCGROUP = "APP_CLIENT_ASYNCGROUP"; public static final String RESNAME_APP_CLIENT_ASYNCGROUP = "APP_CLIENT_ASYNCGROUP";
/** /**
@@ -178,9 +163,6 @@ public final class Application {
//配置项里的group信息, 注意: 只给SNCP使用 //配置项里的group信息, 注意: 只给SNCP使用
private final SncpRpcGroups sncpRpcGroups = new SncpRpcGroups(); private final SncpRpcGroups sncpRpcGroups = new SncpRpcGroups();
//
private final AsyncIOGroup globalAsyncGroup;
//给客户端使用包含SNCP客户端、自定义数据库客户端连接池 //给客户端使用包含SNCP客户端、自定义数据库客户端连接池
private final AsyncIOGroup clientAsyncGroup; private final AsyncIOGroup clientAsyncGroup;
@@ -589,14 +571,7 @@ public final class Application {
this.workExecutor = workExecutor0; this.workExecutor = workExecutor0;
this.resourceFactory.register(RESNAME_APP_EXECUTOR, Executor.class, this.workExecutor); this.resourceFactory.register(RESNAME_APP_EXECUTOR, Executor.class, this.workExecutor);
this.resourceFactory.register(RESNAME_APP_EXECUTOR, ExecutorService.class, this.workExecutor); this.resourceFactory.register(RESNAME_APP_EXECUTOR, ExecutorService.class, this.workExecutor);
{
if (config.getAnyValues("server").length < 2) { //只存在一个server节点
this.globalAsyncGroup = new AsyncIOGroup("Redkale-Global-IOThread-%s", workExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
this.resourceFactory.register(RESNAME_APP_GLOBAL_IOGROUP, AsyncGroup.class, this.globalAsyncGroup);
this.resourceFactory.register(RESNAME_APP_GLOBAL_IOGROUP, AsyncIOGroup.class, this.globalAsyncGroup);
this.clientAsyncGroup = this.globalAsyncGroup;
} else {
this.globalAsyncGroup = null;
ExecutorService clientExecutor = workExecutor0; ExecutorService clientExecutor = workExecutor0;
if (clientExecutor == null) { if (clientExecutor == null) {
//给所有client给一个默认的ExecutorService //给所有client给一个默认的ExecutorService
@@ -604,9 +579,8 @@ public final class Application {
} }
this.clientAsyncGroup = new AsyncIOGroup("Redkale-DefaultClient-IOThread-%s", clientExecutor, bufferCapacity, bufferPoolSize).skipClose(true); this.clientAsyncGroup = new AsyncIOGroup("Redkale-DefaultClient-IOThread-%s", clientExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
} }
this.resourceFactory.register(RESNAME_APP_CLIENT_IOGROUP, AsyncGroup.class, this.clientAsyncGroup);
this.resourceFactory.register(RESNAME_APP_CLIENT_IOGROUP, AsyncIOGroup.class, this.clientAsyncGroup);
this.resourceFactory.register(RESNAME_APP_CLIENT_ASYNCGROUP, AsyncGroup.class, this.clientAsyncGroup); this.resourceFactory.register(RESNAME_APP_CLIENT_ASYNCGROUP, AsyncGroup.class, this.clientAsyncGroup);
this.resourceFactory.register(RESNAME_APP_CLIENT_ASYNCGROUP, AsyncIOGroup.class, this.clientAsyncGroup);
this.excludelibs = excludelib0; this.excludelibs = excludelib0;
this.clusterAgent = cluster; this.clusterAgent = cluster;

View File

@@ -12,9 +12,7 @@ import java.util.Set;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
import java.util.function.*; import java.util.function.*;
import java.util.logging.Level; import java.util.logging.Level;
import org.redkale.annotation.Resource;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import static org.redkale.boot.Application.RESNAME_APP_GLOBAL_IOGROUP;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
@@ -32,7 +30,6 @@ class AsyncNioTcpProtocolServer extends ProtocolServer {
private Selector selector; private Selector selector;
@Resource(name = RESNAME_APP_GLOBAL_IOGROUP, required = false)
private AsyncIOGroup ioGroup; private AsyncIOGroup ioGroup;
private Thread acceptThread; private Thread acceptThread;

View File

@@ -15,9 +15,7 @@ import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.function.*; import java.util.function.*;
import java.util.logging.Level; import java.util.logging.Level;
import org.redkale.annotation.Resource;
import org.redkale.boot.Application; import org.redkale.boot.Application;
import static org.redkale.boot.Application.RESNAME_APP_GLOBAL_IOGROUP;
import org.redkale.util.*; import org.redkale.util.*;
/** /**
@@ -34,7 +32,6 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
private Selector selector; private Selector selector;
@Resource(name = RESNAME_APP_GLOBAL_IOGROUP, required = false)
private AsyncIOGroup ioGroup; private AsyncIOGroup ioGroup;
private Thread acceptThread; private Thread acceptThread;

View File

@@ -80,8 +80,6 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
protected int writeTimeoutSeconds; protected int writeTimeoutSeconds;
protected String connectionContextName;
//------------------ 可选项 ------------------ //------------------ 可选项 ------------------
//PING心跳的请求数据为null且pingInterval<1表示不需要定时ping //PING心跳的请求数据为null且pingInterval<1表示不需要定时ping
protected Supplier<R> pingRequestSupplier; protected Supplier<R> pingRequestSupplier;

View File

@@ -5,23 +5,23 @@
*/ */
package org.redkale.source; package org.redkale.source;
import java.io.*; import java.io.Serializable;
import java.math.*; import java.math.*;
import java.sql.*; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.*; import java.util.concurrent.atomic.*;
import java.util.function.*; import java.util.function.*;
import java.util.logging.*; import java.util.logging.*;
import java.util.stream.*; import java.util.stream.Stream;
import org.redkale.annotation.AutoLoad; import org.redkale.annotation.AutoLoad;
import org.redkale.annotation.*; import org.redkale.annotation.*;
import org.redkale.annotation.ResourceListener; import org.redkale.annotation.ResourceListener;
import org.redkale.annotation.ResourceType; import org.redkale.annotation.ResourceType;
import static org.redkale.boot.Application.*; import static org.redkale.boot.Application.*;
import org.redkale.net.*; import org.redkale.net.AsyncGroup;
import org.redkale.persistence.*; import org.redkale.persistence.Table;
import org.redkale.service.*; import org.redkale.service.Local;
import org.redkale.source.EntityInfo.EntityColumn; import org.redkale.source.EntityInfo.EntityColumn;
import org.redkale.util.*; import org.redkale.util.*;
@@ -59,7 +59,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
protected Properties writeConfProps; protected Properties writeConfProps;
@Resource(name = RESNAME_APP_CLIENT_IOGROUP, required = false) @Resource(name = RESNAME_APP_CLIENT_ASYNCGROUP, required = false)
protected AsyncGroup clientAsyncGroup; protected AsyncGroup clientAsyncGroup;
//配置<executor threads="0"> APP_EXECUTOR资源为null //配置<executor threads="0"> APP_EXECUTOR资源为null