Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VL] Should convert kSpillReadBufferSize and kShuffleSpillDiskWriteBufferSize to number #8684

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.spark.sql.internal

import org.apache.spark.network.util.ByteUnit

import org.scalatest.funsuite.AnyFunSuite

class GlutenConfigUtilSuite extends AnyFunSuite {

test("mapByteConfValue should return correct value") {
val conf = Map(
"spark.unsafe.sorter.spill.reader.buffer.size" -> "2m"
)

GlutenConfigUtil.mapByteConfValue(
conf,
"spark.unsafe.sorter.spill.reader.buffer.size",
ByteUnit.BYTE)(v => assert(2097152L.equals(v)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.apache.gluten.config

import org.apache.spark.internal.Logging
import org.apache.spark.network.util.{ByteUnit, JavaUtils}
import org.apache.spark.sql.internal.{SQLConf, SQLConfProvider}
import org.apache.spark.network.util.ByteUnit
import org.apache.spark.sql.internal.{GlutenConfigUtil, SQLConf, SQLConfProvider}

import com.google.common.collect.ImmutableList
import org.apache.hadoop.security.UserGroupInformation
Expand Down Expand Up @@ -428,9 +428,7 @@ object GlutenConfig {
val SPARK_REDACTION_REGEX = "spark.redaction.regex"
val SPARK_SHUFFLE_FILE_BUFFER = "spark.shuffle.file.buffer"
val SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE = "spark.unsafe.sorter.spill.reader.buffer.size"
val SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE_DEFAULT: Int = 1024 * 1024
val SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE = "spark.shuffle.spill.diskWriteBufferSize"
val SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE_DEFAULT: Int = 1024 * 1024
val SPARK_SHUFFLE_SPILL_COMPRESS = "spark.shuffle.spill.compress"
val SPARK_SHUFFLE_SPILL_COMPRESS_DEFAULT: Boolean = true

Expand All @@ -449,7 +447,7 @@ object GlutenConfig {
*/
def getNativeSessionConf(
backendName: String,
conf: scala.collection.Map[String, String]): util.Map[String, String] = {
conf: Map[String, String]): util.Map[String, String] = {
val nativeConfMap = new util.HashMap[String, String]()
val keys = Set(
DEBUG_ENABLED.key,
Expand Down Expand Up @@ -504,24 +502,20 @@ object GlutenConfig {
(
GLUTEN_COLUMNAR_TO_ROW_MEM_THRESHOLD.key,
GLUTEN_COLUMNAR_TO_ROW_MEM_THRESHOLD.defaultValue.get.toString),
(
SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE,
SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE_DEFAULT.toString),
(
SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE,
SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE_DEFAULT.toString),
(SPARK_SHUFFLE_SPILL_COMPRESS, SPARK_SHUFFLE_SPILL_COMPRESS_DEFAULT.toString)
)
keyWithDefault.forEach(e => nativeConfMap.put(e._1, conf.getOrElse(e._1, e._2)))

conf
.get(SPARK_SHUFFLE_FILE_BUFFER)
.foreach(
v =>
nativeConfMap
.put(
SPARK_SHUFFLE_FILE_BUFFER,
(JavaUtils.byteStringAs(v, ByteUnit.KiB) * 1024).toString))
GlutenConfigUtil.mapByteConfValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a new list like keyWithDefault, move the bytes config together, it will be more easier for users to add byte config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is byteKeys

conf,
SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE,
ByteUnit.BYTE)(
v => nativeConfMap.put(SPARK_UNSAFE_SORTER_SPILL_READER_BUFFER_SIZE, v.toString))
GlutenConfigUtil.mapByteConfValue(
conf,
SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE,
ByteUnit.BYTE)(v => nativeConfMap.put(SPARK_SHUFFLE_SPILL_DISK_WRITE_BUFFER_SIZE, v.toString))
GlutenConfigUtil.mapByteConfValue(conf, SPARK_SHUFFLE_FILE_BUFFER, ByteUnit.KiB)(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is JavaUtils.byteStringAs(v, ByteUnit.KiB) * 1024) equal to JavaUtils.byteStringAs(v, ByteUnit.BYTE)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, if v doesn't provide unit, then this unit provided will be used. E.g, when v is 1024, then JavaUtils.byteStringAs(v, ByteUnit.KiB) * 1024) will be 1024 * 1024, while JavaUtils.byteStringAs(v, ByteUnit.BYTE) is 1024.

v => nativeConfMap.put(SPARK_SHUFFLE_FILE_BUFFER, (v * 1024).toString))

conf
.get(LEGACY_TIME_PARSER_POLICY.key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package org.apache.spark.sql.internal

import org.apache.gluten.config._

import org.apache.spark.network.util.{ByteUnit, JavaUtils}

object GlutenConfigUtil {
private def getConfString(configProvider: ConfigProvider, key: String, value: String): String = {
Option(ConfigEntry.findEntry(key))
Expand All @@ -42,4 +44,9 @@ object GlutenConfigUtil {
}
}.toMap
}

def mapByteConfValue(conf: Map[String, String], key: String, unit: ByteUnit)(
f: Long => Unit): Unit = {
conf.get(key).foreach(v => f(JavaUtils.byteStringAs(v, unit)))
}
}
Loading