You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "YannByron (via GitHub)" <gi...@apache.org> on 2023/12/11 09:37:57 UTC
[PR] [spark] Dynamically adjust the concurrency of scan [incubator-paimon]
YannByron opened a new pull request, #2482:
URL: https://github.com/apache/incubator-paimon/pull/2482
<!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
### Purpose
<!-- Linking this pull request to the issue -->
Linked issue: https://github.com/apache/incubator-paimon/issues/2404
<!-- What is the purpose of the change -->
### Tests
<!-- List UT and IT cases to verify this change -->
### API and Format
<!-- Does this change affect API or storage format -->
### Documentation
<!-- Does this change introduce a new feature -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [spark] Dynamically adjust the parallelism of scan [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #2482:
URL: https://github.com/apache/incubator-paimon/pull/2482
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [spark] Dynamically adjust the parallelism of scan [incubator-paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #2482:
URL: https://github.com/apache/incubator-paimon/pull/2482#discussion_r1427767364
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/ScanHelper.scala:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.paimon.spark
+
+import org.apache.paimon.CoreOptions
+import org.apache.paimon.io.DataFileMeta
+import org.apache.paimon.table.source.{DataSplit, RawFile, Split}
+
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
+
+trait ScanHelper {
+
+ private val spark = SparkSession.active
+
+ val coreOptions: CoreOptions
+
+ private lazy val openCostInBytes: Long = coreOptions.splitOpenFileCost()
+
+ private lazy val leafNodeDefaultParallelism: Int = {
+ spark.conf
+ .get("spark.sql.leafNodeDefaultParallelism", spark.sparkContext.defaultParallelism.toString)
+ .toInt
+ }
+
+ def reshuffleSplits(splits: Array[Split]): Array[Split] = {
+ if (splits.length < leafNodeDefaultParallelism) {
+ val (toReshuffle, reserved) = splits.partition {
+ case split: DataSplit => split.beforeFiles().isEmpty && split.convertToRawFiles.isPresent
+ case _ => false
+ }
+ val reshuffled = reshuffleSplits0(toReshuffle.collect { case ds: DataSplit => ds })
+ reshuffled ++ reserved
+ } else {
+ splits
+ }
+ }
+
+ private def reshuffleSplits0(splits: Array[DataSplit]): Array[DataSplit] = {
Review Comment:
Can you add a test for this method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [spark] Dynamically adjust the parallelism of scan [incubator-paimon]
Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on code in PR #2482:
URL: https://github.com/apache/incubator-paimon/pull/2482#discussion_r1427771841
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/ScanHelper.scala:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.paimon.spark
+
+import org.apache.paimon.CoreOptions
+import org.apache.paimon.io.DataFileMeta
+import org.apache.paimon.table.source.{DataSplit, RawFile, Split}
+
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
+
+trait ScanHelper {
+
+ private val spark = SparkSession.active
+
+ val coreOptions: CoreOptions
+
+ private lazy val openCostInBytes: Long = coreOptions.splitOpenFileCost()
+
+ private lazy val leafNodeDefaultParallelism: Int = {
+ spark.conf
+ .get("spark.sql.leafNodeDefaultParallelism", spark.sparkContext.defaultParallelism.toString)
+ .toInt
+ }
+
+ def reshuffleSplits(splits: Array[Split]): Array[Split] = {
+ if (splits.length < leafNodeDefaultParallelism) {
+ val (toReshuffle, reserved) = splits.partition {
+ case split: DataSplit => split.beforeFiles().isEmpty && split.convertToRawFiles.isPresent
+ case _ => false
+ }
+ val reshuffled = reshuffleSplits0(toReshuffle.collect { case ds: DataSplit => ds })
+ reshuffled ++ reserved
+ } else {
+ splits
+ }
+ }
+
+ private def reshuffleSplits0(splits: Array[DataSplit]): Array[DataSplit] = {
Review Comment:
OK~
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [spark] Dynamically adjust the concurrency of scan [incubator-paimon]
Posted by "YannByron (via GitHub)" <gi...@apache.org>.
YannByron commented on PR #2482:
URL: https://github.com/apache/incubator-paimon/pull/2482#issuecomment-1849674122
This optimization is similar to `FilePartition.getFilePartitions` in DataSource V1, which adjust the parallelism based on available cores.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org