You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2024/08/23 11:48:16 UTC

(shardingsphere) branch master updated: Add SHARDING_TOTAL_COUNT impl of JobExecutorServiceHandler to improve CPU core requirement (#32645)

This is an automated email from the ASF dual-hosted git repository.

menghaoran 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 d4a716f4768 Add SHARDING_TOTAL_COUNT impl of JobExecutorServiceHandler to improve CPU core requirement (#32645)
d4a716f4768 is described below

commit d4a716f4768f445ff13bfbd02b45dbdb62324f48
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Fri Aug 23 19:48:10 2024 +0800

    Add SHARDING_TOTAL_COUNT impl of JobExecutorServiceHandler to improve CPU core requirement (#32645)
---
 ...ngTotalCountUsageJobExecutorServiceHandler.java | 52 ++++++++++++++++++++++
 .../service/PipelineJobConfigurationManager.java   |  2 +
 ...ra.handler.threadpool.JobExecutorServiceHandler | 18 ++++++++
 ...lineDataConsistencyCalculateSQLBuilderTest.java | 33 --------------
 4 files changed, 72 insertions(+), 33 deletions(-)

diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingTotalCountUsageJobExecutorServiceHandler.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingTotalCountUsageJobExecutorServiceHandler.java
new file mode 100644
index 00000000000..2fd810d597d
--- /dev/null
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/execute/ShardingTotalCountUsageJobExecutorServiceHandler.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.execute;
+
+import org.apache.shardingsphere.data.pipeline.core.job.id.PipelineJobIdUtils;
+import org.apache.shardingsphere.elasticjob.infra.concurrent.ElasticJobExecutorService;
+import org.apache.shardingsphere.elasticjob.infra.handler.threadpool.JobExecutorServiceHandler;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Sharding total count usage job executor service handler.
+ */
+public final class ShardingTotalCountUsageJobExecutorServiceHandler implements JobExecutorServiceHandler {
+    
+    public static final String TYPE = "SHARDING_TOTAL_COUNT";
+    
+    @Override
+    public ExecutorService createExecutorService(final String jobName) {
+        int poolSize;
+        try {
+            JobConfigurationPOJO jobConfigPOJO = PipelineJobIdUtils.getElasticJobConfigurationPOJO(jobName);
+            poolSize = jobConfigPOJO.getShardingTotalCount();
+            // CHECKSTYLE:OFF
+        } catch (final RuntimeException ignored) {
+            // CHECKSTYLE:ON
+            poolSize = Runtime.getRuntime().availableProcessors() * 4;
+        }
+        return new ElasticJobExecutorService("elasticjob-" + jobName, poolSize).createExecutorService();
+    }
+    
+    @Override
+    public String getType() {
+        return TYPE;
+    }
+}
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/service/PipelineJobConfigurationManager.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/service/PipelineJobConfigurationManager.java
index 4be4ed1035a..a8b6a3c822d 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/service/PipelineJobConfigurationManager.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/job/service/PipelineJobConfigurationManager.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.data.pipeline.core.job.service;
 
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.data.pipeline.core.execute.ShardingTotalCountUsageJobExecutorServiceHandler;
 import org.apache.shardingsphere.data.pipeline.core.job.config.PipelineJobConfiguration;
 import org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType;
 import org.apache.shardingsphere.data.pipeline.core.listener.PipelineElasticJobListener;
@@ -65,6 +66,7 @@ public final class PipelineJobConfigurationManager {
         result.getProps().setProperty("start_time_millis", String.valueOf(System.currentTimeMillis()));
         result.getProps().setProperty("run_count", "1");
         result.setJobListenerTypes(Collections.singletonList(PipelineElasticJobListener.class.getName()));
+        result.setJobExecutorServiceHandlerType(ShardingTotalCountUsageJobExecutorServiceHandler.TYPE);
         return result;
     }
 }
diff --git a/kernel/data-pipeline/core/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.handler.threadpool.JobExecutorServiceHandler b/kernel/data-pipeline/core/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.handler.threadpool.JobExecutorServiceHandler
new file mode 100644
index 00000000000..7af0d3e8491
--- /dev/null
+++ b/kernel/data-pipeline/core/src/main/resources/META-INF/services/org.apache.shardingsphere.elasticjob.infra.handler.threadpool.JobExecutorServiceHandler
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.data.pipeline.core.execute.ShardingTotalCountUsageJobExecutorServiceHandler
diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java
index 83ad0f9ac0f..90ff549657d 100644
--- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java
+++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/PipelineDataConsistencyCalculateSQLBuilderTest.java
@@ -60,29 +60,6 @@ class PipelineDataConsistencyCalculateSQLBuilderTest {
         assertThat(actual, is("SELECT order_id,user_id,status FROM t_order ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
     }
     
-    @Test
-    void assertBuildQueryRangeOrderingSQLWithQueryCondition() {
-        String actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
-                new QueryRange(1, true, 5), SHARDING_COLUMNS_NAMES);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=? AND order_id<=?"
-                + " ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
-        actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
-                new QueryRange(1, false, 5), SHARDING_COLUMNS_NAMES);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>? AND order_id<=?"
-                + " ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
-        actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
-                new QueryRange(1, true, null), SHARDING_COLUMNS_NAMES);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id>=?"
-                + " ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
-        actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
-                new QueryRange(null, true, 5), SHARDING_COLUMNS_NAMES);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id<=?"
-                + " ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
-        actual = pipelineSQLBuilder.buildQueryRangeOrderingSQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS,
-                new QueryRange(null, false, null), SHARDING_COLUMNS_NAMES);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order ORDER BY order_id ASC, status ASC, user_id ASC LIMIT ?"));
-    }
-    
     @Test
     void assertBuildPointQuerySQLWithoutQueryCondition() {
         String actual = pipelineSQLBuilder.buildPointQuerySQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS, null);
@@ -92,14 +69,4 @@ class PipelineDataConsistencyCalculateSQLBuilderTest {
         actual = pipelineSQLBuilder.buildPointQuerySQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS, Collections.singletonList("user_id"));
         assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id=? AND status=? AND user_id=?"));
     }
-    
-    @Test
-    void assertBuildPointQuerySQLWithQueryCondition() {
-        String actual = pipelineSQLBuilder.buildPointQuerySQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS, null);
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id=? AND status=?"));
-        actual = pipelineSQLBuilder.buildPointQuerySQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS, Collections.emptyList());
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id=? AND status=?"));
-        actual = pipelineSQLBuilder.buildPointQuerySQL(null, "t_order", COLUMN_NAMES, UNIQUE_KEYS, Collections.singletonList("user_id"));
-        assertThat(actual, is("SELECT order_id,user_id,status FROM t_order WHERE order_id=? AND status=? AND user_id=?"));
-    }
 }