Uh oh!
There was an error while loading. Please reload this page.
Update SQLConf.scala - #1272
Conversation
use concurrent.ConcurrentHashMap instead of util.Collections.synchronizedMap
AmplabJenkins
commented
Jul 1, 2014
Can one of the admins verify this patch? |
aarondav
commented
Jul 1, 2014
Jenkins, test this please. |
AmplabJenkins
commented
Jul 1, 2014
Merged build triggered. |
AmplabJenkins
commented
Jul 1, 2014
Merged build started. |
aarondav
commented
Jul 1, 2014
Out of curiosity, what motivates this change? I thought typically ConcurrentHashMap is used for more heavyweight concurrent data structures, while synchronizedMap() is used when concurrency is rare. Either way, our usage is not threadsafe, since we do things like if (map.contains(x)) map.get(x) else defaultValue |
AmplabJenkins
commented
Jul 1, 2014
Merged build finished. |
AmplabJenkins
commented
Jul 1, 2014
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16277/ |
add some synchronized
baishuo
commented
Jul 1, 2014
I add some synchronized please see if it is thread safe,and Jenkins should test this once more |
aarondav
commented
Jul 1, 2014
This is indeed threadsafe, but perhaps overeager. I think we should aim for get()s to be relatively fast, and I think we can avoid extra synchronization there. |
There was a problem hiding this comment.
Perhaps we can remove this synchronized, I don't think we care about the consistency guarantees of inserting multiple properties at once :)
cloud-fan
commented
Jul 1, 2014
With the new |
There was a problem hiding this comment.
Similarly, here, just
Option(settings.get(key))baishuo
commented
Jul 1, 2014
thanks @aarondav ,had modified according to your comment,please help me to check if it is proper |
rxin
commented
Jul 1, 2014
Can you undo the indent spacing change? |
There was a problem hiding this comment.
Probably adding the checking logic is better.
There was a problem hiding this comment.
Agree. How about Option(settings.get(key)).orElse(throw new NoSuchElementException(key))?
chenghao-intel
commented
Jul 1, 2014
And I also saw the code: Should we remove the synchronized block also? since we use the ConcurrentHashMap instead. |
There was a problem hiding this comment.
We should not be using ConcurrentHashMap because this will be a very low contention code path. For low contention code path, ConcurrentHashMap is a very poor choice (as a matter of fact it'll likely be much slower than synchronized, and use a lot more memory)
There was a problem hiding this comment.
back to Collections.synchronizedMap
There was a problem hiding this comment.
@rxin I think the performance distinction is extremely minor in this case, as there is only one ConcurrentHashMap. ConcurrentHashMap's API tends to be nicer to use, though, as people may not realize that iteration over a SynchronizedMap is not threadsafe, like in the current implementation of SQLConf.
As @baishuo mentioned, if we use synchronizedMap we'll have to add settings.synchronized {} in a few places now.
baishuo
commented
Jul 1, 2014
Hi,@rxin ,had remove indent spacing on |
baishuo
commented
Jul 1, 2014
hi @rxin, how to modify is proper? |
concretevitamin
commented
Jul 1, 2014
Yeah, what is motivating this change? When this class got introduced, @rxin commented that java.util.ConcurrentHashMap had bad memory footprint and suggested the current approach instead. |
concretevitamin
commented
Jul 1, 2014
Sorry, I didn't realize Reynold had already commented on this thread. The current changes with Option look good. |
concretevitamin
commented
Jul 3, 2014
Jenkins, ok to test. |
AmplabJenkins
commented
Jul 3, 2014
Merged build triggered. |
AmplabJenkins
commented
Jul 3, 2014
Merged build started. |
AmplabJenkins
commented
Jul 3, 2014
Merged build finished. |
AmplabJenkins
commented
Jul 3, 2014
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16302/ |
aarondav
commented
Jul 3, 2014
@rxin wins because he says that SQLConf will become a Thread-local variable. This looks good, the only thing to change for thread-safety is to add a synchronized for getAll(). |
rxin
commented
Jul 3, 2014
Note that the latest code no longer compiles .... |
There was a problem hiding this comment.
This follows code style from BlockManager:
def getLocalFromDisk(blockId: BlockId, serializer: Serializer): Option[Iterator[Any]] = {
diskStore.getValues(blockId, serializer).orElse(
sys.error("Block " + blockId + " not found on disk, though it should be"))
}
Anyway throw expression return Nothing, which can work with both getOrElse and orElse
There was a problem hiding this comment.
orElse literally does not compile here, as it returns Option(Nothing).
There was a problem hiding this comment.
Ah, I see. get(key: String) need to return a String which I missed. My bad :P
baishuo
commented
Jul 4, 2014
ooh,sorry about the compile error,had change orElse to getOrElse. thank you @rxin |
AmplabJenkins
commented
Jul 4, 2014
Merged build triggered. |
AmplabJenkins
commented
Jul 4, 2014
Merged build started. |
AmplabJenkins
commented
Jul 4, 2014
Merged build finished. |
AmplabJenkins
commented
Jul 4, 2014
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16335/ |
rxin
commented
Jul 4, 2014
Jenkins, retest this please. |
AmplabJenkins
commented
Jul 4, 2014
Merged build triggered. |
AmplabJenkins
commented
Jul 4, 2014
Merged build started. |
AmplabJenkins
commented
Jul 4, 2014
Merged build finished. All automated tests passed. |
AmplabJenkins
commented
Jul 4, 2014
All automated tests passed. |
rxin
commented
Jul 4, 2014
Thanks. I'm merging this in master & branch-1.0. |
use concurrent.ConcurrentHashMap instead of util.Collections.synchronizedMap Author: baishuo(白硕) <vc_java@hotmail.com> Closes#1272 from baishuo/master and squashes the following commits: 51ec55d [baishuo(白硕)] Update SQLConf.scala 63da043 [baishuo(白硕)] Update SQLConf.scala 36b6dbd [baishuo(白硕)] Update SQLConf.scala 864faa0 [baishuo(白硕)] Update SQLConf.scala 593096b [baishuo(白硕)] Update SQLConf.scala 7304d9b [baishuo(白硕)] Update SQLConf.scala 843581c [baishuo(白硕)] Update SQLConf.scala 1d3e4a2 [baishuo(白硕)] Update SQLConf.scala 0740f28 [baishuo(白硕)] Update SQLConf.scala (cherry picked from commit 0bbe612) Signed-off-by: Reynold Xin <rxin@apache.org>
use concurrent.ConcurrentHashMap instead of util.Collections.synchronizedMap Author: baishuo(白硕) <vc_java@hotmail.com> Closes#1272 from baishuo/master and squashes the following commits: 51ec55d [baishuo(白硕)] Update SQLConf.scala 63da043 [baishuo(白硕)] Update SQLConf.scala 36b6dbd [baishuo(白硕)] Update SQLConf.scala 864faa0 [baishuo(白硕)] Update SQLConf.scala 593096b [baishuo(白硕)] Update SQLConf.scala 7304d9b [baishuo(白硕)] Update SQLConf.scala 843581c [baishuo(白硕)] Update SQLConf.scala 1d3e4a2 [baishuo(白硕)] Update SQLConf.scala 0740f28 [baishuo(白硕)] Update SQLConf.scala (cherry picked from commit 0bbe612) Signed-off-by: Reynold Xin <rxin@apache.org>
use concurrent.ConcurrentHashMap instead of util.Collections.synchronizedMap Author: baishuo(白硕) <vc_java@hotmail.com> Closesapache#1272 from baishuo/master and squashes the following commits: 51ec55d [baishuo(白硕)] Update SQLConf.scala 63da043 [baishuo(白硕)] Update SQLConf.scala 36b6dbd [baishuo(白硕)] Update SQLConf.scala 864faa0 [baishuo(白硕)] Update SQLConf.scala 593096b [baishuo(白硕)] Update SQLConf.scala 7304d9b [baishuo(白硕)] Update SQLConf.scala 843581c [baishuo(白硕)] Update SQLConf.scala 1d3e4a2 [baishuo(白硕)] Update SQLConf.scala 0740f28 [baishuo(白硕)] Update SQLConf.scala
use concurrent.ConcurrentHashMap instead of util.Collections.synchronizedMap