[
https://issues.apache.org/jira/browse/SPARK-34573?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17292563#comment-17292563
]
Gabriele Nizzoli commented on SPARK-34573:
------------------------------------------
Here I'm NOT talking about the *settings*, but I'm talking about *private[sql]
val sqlConfEntries*, which is defined in the SQLConf object:
([https://github.com/apache/spark/blob/5a48eb8d00faee3a7c8f023c0699296e22edb893/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L56])
Example of a call that will hit this global lock map:
* DataType.sameType
([https://github.com/apache/spark/blob/3a299aa6480ac22501512cd0310d31a441d7dfdc/sql/catalyst/src/main/scala/org/apache/spark/sql/types/DataType.scala#L95])
* SQLConf.get.caseSensitiveAnalysis
([https://github.com/apache/spark/blob/f494c5cff9d56744f8e7a2b646be6d01de8a09f4/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L3418])
* getConf
([https://github.com/apache/spark/blob/f494c5cff9d56744f8e7a2b646be6d01de8a09f4/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala#L3832])
And here getConf call sqlConfEntries.get(), and sqlConfEntries is defined in
the SQLConf object.
So every time we compare two datatypes with sameType, we hit a lock.
Currently testing replacing:
{code:scala}
private[sql] val sqlConfEntries = java.util.Collections.synchronizedMap(
new java.util.HashMap[String, ConfigEntry[_]]())
{code}
with:
{code:java}
private[sql] val sqlConfEntries =
new ConcurrentHashMap[String, ConfigEntry[_]]()
{code}
> SQLConf sqlConfEntries map has a global lock, should not lock on get
> --------------------------------------------------------------------
>
> Key: SPARK-34573
> URL: https://issues.apache.org/jira/browse/SPARK-34573
> Project: Spark
> Issue Type: Improvement
> Components: SQL
> Affects Versions: 2.4.7, 3.0.2
> Reporter: Gabriele Nizzoli
> Priority: Minor
>
> SQLConf sqlConfEntries map has a global lock (since it implements a
> Collections.synchronizedMap).
> Every operation (like get or set) blocks the full object.
> Concurrent threads may wait on lock.
> An example is the DatatType.sameType method, that queries SQLConf entries map:
> {code:scala}
> if (SQLConf.get.caseSensitiveAnalysis)
> ...
> {code}
> If this data type check is run in a custom piece of code on an executor with
> multiple cores (eg: 40), then a lot of time will be lost waiting on the lock.
> An easy fix is to use the a ConcurrentHashMap that does not lock on read
> SQLConf.get): " ... retrieval operations do not entail locking ..."
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]