You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/03/19 10:07:27 UTC
[shardingsphere] branch master updated: improve performance for
proxy by caching instances (#9746)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b1e8607 improve performance for proxy by caching instances (#9746)
b1e8607 is described below
commit b1e86074473ddb909daf17af6bc1189089d134e0
Author: Zhang Yonglun <zh...@apache.org>
AuthorDate: Fri Mar 19 18:06:49 2021 +0800
improve performance for proxy by caching instances (#9746)
---
.../java/org/apache/shardingsphere/infra/audit/SQLCheckEngine.java | 5 +++--
.../infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java | 6 +++++-
.../executor/sql/prepare/driver/DriverExecutionPrepareEngine.java | 7 ++++++-
.../java/org/apache/shardingsphere/infra/merge/MergeEngine.java | 6 +++++-
.../org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java | 6 +++++-
.../infra/route/engine/impl/PartialSQLRouteExecutor.java | 6 +++++-
6 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/audit/SQLCheckEngine.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/audit/SQLCheckEngine.java
index 60ceed2..6c86b4a 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/audit/SQLCheckEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/audit/SQLCheckEngine.java
@@ -34,6 +34,8 @@ import java.util.List;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SQLCheckEngine {
+ private static final Collection<SQLChecker> AUDITORS = OrderedSPIRegistry.getRegisteredServices(SQLChecker.class);
+
static {
ShardingSphereServiceLoader.register(SQLChecker.class);
}
@@ -47,8 +49,7 @@ public final class SQLCheckEngine {
* @param auth auth
*/
public static void check(final SQLStatement sqlStatement, final List<Object> parameters, final ShardingSphereMetaData metaData, final Authentication auth) {
- Collection<SQLChecker> auditors = OrderedSPIRegistry.getRegisteredServices(SQLChecker.class);
- for (SQLChecker each : auditors) {
+ for (SQLChecker each : AUDITORS) {
SQLCheckResult auditResult = each.check(sqlStatement, parameters, metaData, auth);
if (!auditResult.isPassed()) {
throw new SQLCheckException(each.getSQLCheckType(), auditResult.getErrorMessage());
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
index d06c11e..9528283 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/AbstractExecutionPrepareEngine.java
@@ -35,6 +35,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Abstract execution prepare engine.
@@ -47,6 +48,9 @@ public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrep
ShardingSphereServiceLoader.register(ExecutionPrepareDecorator.class);
}
+ @SuppressWarnings("rawtypes")
+ private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, ExecutionPrepareDecorator>> RULES_TO_DECORATORS_MAP = new ConcurrentHashMap<>(32, 1);
+
private final int maxConnectionsSizePerQuery;
@SuppressWarnings("rawtypes")
@@ -54,7 +58,7 @@ public abstract class AbstractExecutionPrepareEngine<T> implements ExecutionPrep
protected AbstractExecutionPrepareEngine(final int maxConnectionsSizePerQuery, final Collection<ShardingSphereRule> rules) {
this.maxConnectionsSizePerQuery = maxConnectionsSizePerQuery;
- decorators = OrderedSPIRegistry.getRegisteredServices(rules, ExecutionPrepareDecorator.class);
+ decorators = RULES_TO_DECORATORS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, ExecutionPrepareDecorator.class));
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
index 5ea0134..95e41c1 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/prepare/driver/DriverExecutionPrepareEngine.java
@@ -31,7 +31,9 @@ import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Driver execution prepare engine.
@@ -41,6 +43,9 @@ import java.util.Properties;
*/
public final class DriverExecutionPrepareEngine<T extends DriverExecutionUnit<?>, C> extends AbstractExecutionPrepareEngine<T> {
+ @SuppressWarnings("rawtypes")
+ private static final Map<String, SQLExecutionUnitBuilder> TYPE_TO_BUILDER_MAP = new ConcurrentHashMap<>(8, 1);
+
private final ExecutorDriverManager<C, ?, ?> executorDriverManager;
private final StorageResourceOption option;
@@ -57,7 +62,7 @@ public final class DriverExecutionPrepareEngine<T extends DriverExecutionUnit<?>
super(maxConnectionsSizePerQuery, rules);
this.executorDriverManager = executorDriverManager;
this.option = option;
- sqlExecutionUnitBuilder = TypedSPIRegistry.getRegisteredService(SQLExecutionUnitBuilder.class, type, new Properties());
+ sqlExecutionUnitBuilder = TYPE_TO_BUILDER_MAP.computeIfAbsent(type, key -> TypedSPIRegistry.getRegisteredService(SQLExecutionUnitBuilder.class, key, new Properties()));
}
@Override
diff --git a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
index d9b3338..0d3b442 100644
--- a/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
+++ b/shardingsphere-infra/shardingsphere-infra-merge/src/main/java/org/apache/shardingsphere/infra/merge/MergeEngine.java
@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Merge engine.
@@ -49,6 +50,9 @@ public final class MergeEngine {
ShardingSphereServiceLoader.register(ResultProcessEngine.class);
}
+ @SuppressWarnings("rawtypes")
+ private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, ResultProcessEngine>> RULES_TO_ENGINES_MAP = new ConcurrentHashMap<>(32, 1);
+
private final DatabaseType databaseType;
private final ShardingSphereSchema schema;
@@ -62,7 +66,7 @@ public final class MergeEngine {
this.databaseType = databaseType;
this.schema = schema;
this.props = props;
- engines = OrderedSPIRegistry.getRegisteredServices(rules, ResultProcessEngine.class);
+ engines = RULES_TO_ENGINES_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, ResultProcessEngine.class));
}
/**
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
index 0dd00e5..88261e7 100644
--- a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntry.java
@@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* SQL rewrite entry.
@@ -43,6 +44,9 @@ public final class SQLRewriteEntry {
ShardingSphereServiceLoader.register(SQLRewriteContextDecorator.class);
}
+ @SuppressWarnings("rawtypes")
+ private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, SQLRewriteContextDecorator>> RULES_TO_DECORATORS_MAP = new ConcurrentHashMap<>(32, 1);
+
private final ShardingSphereSchema schema;
private final ConfigurationProperties props;
@@ -53,7 +57,7 @@ public final class SQLRewriteEntry {
public SQLRewriteEntry(final ShardingSphereSchema schema, final ConfigurationProperties props, final Collection<ShardingSphereRule> rules) {
this.schema = schema;
this.props = props;
- decorators = OrderedSPIRegistry.getRegisteredServices(rules, SQLRewriteContextDecorator.class);
+ decorators = RULES_TO_DECORATORS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, SQLRewriteContextDecorator.class));
}
/**
diff --git a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
index c0cd197..8c179c6 100644
--- a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
+++ b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/engine/impl/PartialSQLRouteExecutor.java
@@ -33,6 +33,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Partial SQL route executor.
@@ -43,6 +44,9 @@ public final class PartialSQLRouteExecutor implements SQLRouteExecutor {
ShardingSphereServiceLoader.register(SQLRouter.class);
}
+ @SuppressWarnings("rawtypes")
+ private static final Map<Collection<ShardingSphereRule>, Map<ShardingSphereRule, SQLRouter>> RULES_TO_ROUTERS_MAP = new ConcurrentHashMap<>(32, 1);
+
private final ConfigurationProperties props;
@SuppressWarnings("rawtypes")
@@ -50,7 +54,7 @@ public final class PartialSQLRouteExecutor implements SQLRouteExecutor {
public PartialSQLRouteExecutor(final Collection<ShardingSphereRule> rules, final ConfigurationProperties props) {
this.props = props;
- routers = OrderedSPIRegistry.getRegisteredServices(rules, SQLRouter.class);
+ routers = RULES_TO_ROUTERS_MAP.computeIfAbsent(rules, key -> OrderedSPIRegistry.getRegisteredServices(key, SQLRouter.class));
}
@Override