Skip to content

Commit

Permalink
optimize: optimize the default values for some switches (apache#5183)
Browse files Browse the repository at this point in the history
  • Loading branch information
slievrly committed Dec 21, 2022
1 parent 512e605 commit 4bad625
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 51 deletions.
1 change: 1 addition & 0 deletions changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5120](https://github.com/seata/seata/pull/5120)] unify the format of configuration items in yml files
- [[#5180](https://github.com/seata/seata/pull/5180)] GlobalTransactionScanner,SeataAutoDataSourceProxyCreator declare @bean methods as static
- [[#5182](https://github.com/seata/seata/pull/5182)] fix some security vulnerabilities in GGEditor
- [[#5183](https://github.com/seata/seata/pull/5183)] optimize the default values for some switches

### test:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] add test for xxx
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [[#5120](https://github.com/seata/seata/pull/5120)] 统一yml文件中的配置项格式
- [[#5180](https://github.com/seata/seata/pull/5180)] GlobalTransactionScanner,SeataAutoDataSourceProxyCreator 创建bean用static修饰
- [[#5182](https://github.com/seata/seata/pull/5182)] 修复 Saga 可视化设计器 GGEditor 安全漏洞
- [[#5183](https://github.com/seata/seata/pull/5183)] 优化配置开关的默认值

### test:
- [[#xxx](https://github.com/seata/seata/pull/xxx)] 增加 xxx 测试
Expand Down
16 changes: 14 additions & 2 deletions common/src/main/java/io/seata/common/DefaultValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public interface DefaultValues {
/**
* the constant DEFAULT_RPC_RM_REQUEST_TIMEOUT
*/
long DEFAULT_RPC_RM_REQUEST_TIMEOUT = Duration.ofSeconds(30).toMillis();
long DEFAULT_RPC_RM_REQUEST_TIMEOUT = Duration.ofSeconds(15).toMillis();

/**
* the constant DEFAULT_RPC_TM_REQUEST_TIMEOUT
Expand All @@ -178,7 +178,7 @@ public interface DefaultValues {
/**
* the constant DEFAULT_RPC_TC_REQUEST_TIMEOUT
*/
long DEFAULT_RPC_TC_REQUEST_TIMEOUT = Duration.ofSeconds(30).toMillis();
long DEFAULT_RPC_TC_REQUEST_TIMEOUT = Duration.ofSeconds(15).toMillis();

/**
* the constant DEFAULT_XAER_NOTA_RETRY_TIMEOUT
Expand Down Expand Up @@ -269,4 +269,16 @@ public interface DefaultValues {
* DEFAULT_ENABLE_BRANCH_ASYNC_REMOVE
*/
boolean DEFAULT_ENABLE_BRANCH_ASYNC_REMOVE = false;

int DEFAULT_DB_MAX_CONN = 100;

int DEFAULT_DB_MIN_CONN = 10;

int DEFAULT_REDIS_MAX_IDLE = 100;

int DEFAULT_REDIS_MAX_TOTAL = 100;

int DEFAULT_REDIS_MIN_IDLE = 10;

int DEFAULT_QUERY_LIMIT = 1000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class ServerOnRequestProcessor implements RemotingProcessor, Disposable {
private static final long KEEP_ALIVE_TIME = Integer.MAX_VALUE;
private static final String BATCH_RESPONSE_THREAD_PREFIX = "rpcBatchResponse";
private static final boolean PARALLEL_REQUEST_HANDLE =
ConfigurationFactory.getInstance().getBoolean(ConfigurationKeys.ENABLE_PARALLEL_REQUEST_HANDLE_KEY, false);
ConfigurationFactory.getInstance().getBoolean(ConfigurationKeys.ENABLE_PARALLEL_REQUEST_HANDLE_KEY, true);

public ServerOnRequestProcessor(RemotingServer remotingServer, TransactionMessageHandler transactionMessageHandler) {
this.remotingServer = remotingServer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static io.seata.common.DefaultValues.DEFAULT_DB_MAX_CONN;
import static io.seata.common.DefaultValues.DEFAULT_DB_MIN_CONN;

/**
* The abstract datasource provider
*
Expand All @@ -60,10 +63,6 @@ public abstract class AbstractDataSourceProvider implements DataSourceProvider,

private final static Map<String, ClassLoader> MYSQL_DRIVER_LOADERS;

private static final int DEFAULT_DB_MAX_CONN = 20;

private static final int DEFAULT_DB_MIN_CONN = 1;

private static final long DEFAULT_DB_MAX_WAIT = 5000;

static {
Expand Down
4 changes: 3 additions & 1 deletion script/client/conf/file.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ transport {
# the rm client rpc request timeout
rpcRmRequestTimeout = 2000
# the tm client rpc request timeout
rpcTmRequestTimeout = 10000
rpcTmRequestTimeout = 30000
# the rm client rpc request timeout
rpcRmRequestTimeout = 15000
#thread factory for netty
threadFactory {
bossThreadPrefix = "NettyBoss"
Expand Down
2 changes: 1 addition & 1 deletion script/client/spring/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ seata.transport.serialization=seata
seata.transport.compressor=none
seata.transport.enable-tm-client-batch-send-request=false
seata.transport.enable-rm-client-batch-send-request=true
seata.transport.rpc-rm-request-timeout=30000
seata.transport.rpc-rm-request-timeout=15000
seata.transport.rpc-tm-request-timeout=30000

seata.config.type=file
Expand Down
2 changes: 1 addition & 1 deletion script/client/spring/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ seata:
compressor: none
enable-tm-client-batch-send-request: false
enable-rm-client-batch-send-request: true
rpc-rm-request-timeout: 30000
rpc-rm-request-timeout: 15000
rpc-tm-request-timeout: 30000
config:
type: file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import static io.seata.common.DefaultValues.DEFAULT_DB_MAX_CONN;
import static io.seata.common.DefaultValues.DEFAULT_DB_MIN_CONN;
import static io.seata.common.DefaultValues.DEFAULT_QUERY_LIMIT;
import static io.seata.spring.boot.autoconfigure.StarterConstants.STORE_DB_PREFIX;

/**
Expand All @@ -32,13 +35,13 @@ public class StoreDBProperties {
private String url = "jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true";
private String user = "mysql";
private String password = "mysql";
private Integer minConn = 5;
private Integer maxConn = 100;
private Integer minConn = DEFAULT_DB_MIN_CONN;
private Integer maxConn = DEFAULT_DB_MAX_CONN;
private String globalTable = "global_table";
private String branchTable = "branch_table";
private String lockTable = "lock_table";
private String distributedLockTable = "distributed_lock";
private Integer queryLimit = 100;
private Integer queryLimit = DEFAULT_QUERY_LIMIT;
private Integer maxWait = 5000;

public String getDatasource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import static io.seata.common.DefaultValues.DEFAULT_QUERY_LIMIT;
import static io.seata.common.DefaultValues.DEFAULT_REDIS_MAX_IDLE;
import static io.seata.common.DefaultValues.DEFAULT_REDIS_MIN_IDLE;
import static io.seata.spring.boot.autoconfigure.StarterConstants.STORE_REDIS_PREFIX;
import static io.seata.spring.boot.autoconfigure.StarterConstants.STORE_REDIS_SINGLE_PREFIX;
import static io.seata.spring.boot.autoconfigure.StarterConstants.STORE_REDIS_SENTINEL_PREFIX;
Expand All @@ -33,10 +36,10 @@ public class StoreRedisProperties {
*/
private String mode = "single";
private String password;
private Integer maxConn = 10;
private Integer minConn = 1;
private Integer maxConn = DEFAULT_REDIS_MAX_IDLE;
private Integer minConn = DEFAULT_REDIS_MIN_IDLE;
private Integer database = 0;
private Integer queryLimit = 100;
private Integer queryLimit = DEFAULT_QUERY_LIMIT;
private Integer maxTotal = 100;

public String getMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.sql.DataSource;

import io.seata.common.exception.StoreException;
Expand All @@ -37,12 +38,12 @@
import io.seata.core.store.db.DataSourceProvider;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionCondition;
import io.seata.server.storage.SessionConverter;
import io.seata.server.store.AbstractTransactionStoreManager;
import io.seata.server.store.SessionStorable;
import io.seata.server.store.TransactionStoreManager;
import io.seata.server.storage.SessionConverter;

import static io.seata.core.constants.RedisKeyConstants.DEFAULT_LOG_QUERY_LIMIT;
import static io.seata.common.DefaultValues.DEFAULT_QUERY_LIMIT;

/**
* The type Database transaction store manager.
Expand Down Expand Up @@ -87,7 +88,7 @@ public static DataBaseTransactionStoreManager getInstance() {
* Instantiates a new Database transaction store manager.
*/
private DataBaseTransactionStoreManager() {
logQueryLimit = CONFIG.getInt(ConfigurationKeys.STORE_DB_LOG_QUERY_LIMIT, DEFAULT_LOG_QUERY_LIMIT);
logQueryLimit = CONFIG.getInt(ConfigurationKeys.STORE_DB_LOG_QUERY_LIMIT, DEFAULT_QUERY_LIMIT);
String datasourceType = CONFIG.getConfig(ConfigurationKeys.STORE_DB_DATASOURCE_TYPE);
//init dataSource
DataSource logStoreDataSource = EnhancedServiceLoader.load(DataSourceProvider.class, datasourceType).provide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import static io.seata.common.DefaultValues.DEFAULT_REDIS_MAX_IDLE;
import static io.seata.common.DefaultValues.DEFAULT_REDIS_MAX_TOTAL;
import static io.seata.common.DefaultValues.DEFAULT_REDIS_MIN_IDLE;

/**
* @author funkye
*/
Expand All @@ -47,13 +51,6 @@ public class JedisPooledFactory {
private static final String HOST = "127.0.0.1";

private static final int PORT = 6379;

private static final int MINCONN = 1;

private static final int MAXCONN = 10;

private static final int MAXTOTAL = 100;

private static final int DATABASE = 0;

private static final int SENTINEL_HOST_NUMBER = 3;
Expand Down Expand Up @@ -87,9 +84,11 @@ public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisP
}
}
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMinIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MIN_CONN, MINCONN));
poolConfig.setMaxIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_CONN, MAXCONN));
poolConfig.setMaxTotal(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_TOTAL, MAXTOTAL));
poolConfig.setMinIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MIN_CONN,
DEFAULT_REDIS_MIN_IDLE));
poolConfig.setMaxIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_CONN,
DEFAULT_REDIS_MAX_IDLE));
poolConfig.setMaxTotal(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_TOTAL, DEFAULT_REDIS_MAX_TOTAL));
String mode = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_MODE,ConfigurationKeys.REDIS_SINGLE_MODE);
if (mode.equals(ConfigurationKeys.REDIS_SENTINEL_MODE)) {
String masterName = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_MASTERNAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,57 @@
*/
package io.seata.server.storage.redis.store;

import java.util.Iterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.server.session.SessionStatusValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap;
import io.seata.common.XID;
import io.seata.common.exception.RedisException;
import io.seata.common.exception.StoreException;
import io.seata.common.util.BeanUtils;
import io.seata.common.util.CollectionUtils;
import io.seata.common.util.StringUtils;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.config.Configuration;
import io.seata.config.ConfigurationFactory;
import io.seata.core.model.GlobalStatus;
import io.seata.core.store.BranchTransactionDO;
import io.seata.core.store.GlobalTransactionDO;
import io.seata.server.console.param.GlobalSessionParam;
import io.seata.server.session.GlobalSession;
import io.seata.server.session.SessionCondition;
import io.seata.server.session.SessionStatusValidator;
import io.seata.server.storage.SessionConverter;
import io.seata.server.storage.redis.JedisPooledFactory;
import io.seata.server.store.AbstractTransactionStoreManager;
import io.seata.server.store.SessionStorable;
import io.seata.server.store.TransactionStoreManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Transaction;

import static io.seata.common.ConfigurationKeys.STORE_REDIS_QUERY_LIMIT;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_XID;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_GLOBAL_XID;
import static io.seata.core.constants.RedisKeyConstants.DEFAULT_LOG_QUERY_LIMIT;
import static io.seata.common.DefaultValues.DEFAULT_QUERY_LIMIT;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_APPLICATION_DATA;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_GMT_MODIFIED;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_STATUS;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_GLOBAL_STATUS;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_XID;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_GLOBAL_GMT_MODIFIED;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_GMT_MODIFIED;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_BRANCH_APPLICATION_DATA;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_GLOBAL_STATUS;
import static io.seata.core.constants.RedisKeyConstants.REDIS_KEY_GLOBAL_XID;

/**
* The redis transaction store manager
Expand Down Expand Up @@ -126,7 +128,7 @@ public RedisTransactionStoreManager() {
super();
initGlobalMap();
initBranchMap();
logQueryLimit = CONFIG.getInt(STORE_REDIS_QUERY_LIMIT, DEFAULT_LOG_QUERY_LIMIT);
logQueryLimit = CONFIG.getInt(STORE_REDIS_QUERY_LIMIT, DEFAULT_QUERY_LIMIT);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions server/src/main/resources/application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ seata:
enable-parallel-request-handle: true
retry-dead-threshold: 130000
xaer-nota-retry-timeout: 60000
enableParallelRequestHandle: true
recovery:
committing-retry-period: 1000
async-committing-retry-period: 1000
Expand Down Expand Up @@ -156,22 +157,22 @@ seata:
url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true
user: mysql
password: mysql
min-conn: 5
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 100
query-limit: 1000
max-wait: 5000
redis:
mode: single
database: 0
min-conn: 1
max-conn: 10
min-conn: 10
max-conn: 100
password:
max-total: 100
query-limit: 100
query-limit: 1000
single:
host: 127.0.0.1
port: 6379
Expand All @@ -184,7 +185,7 @@ seata:
exporter-list: prometheus
exporter-prometheus-port: 9898
transport:
rpc-tc-request-timeout: 30000
rpc-tc-request-timeout: 15000
enable-tc-server-batch-send-response: false
shutdown:
wait: 3
Expand Down

0 comments on commit 4bad625

Please sign in to comment.