-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-36598][SHUFFLE][SQL] Avoid the memory leak of Guava cache by add maximumWeight limit #33848
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
98458fd
add Guava cache bad case
LuciferYang 8ec7525
try to upgrade guava version
LuciferYang 6c4b06d
Revert "try to upgrade guava version"
LuciferYang 0fade2a
add value check
LuciferYang 3b965c2
fix Line is longer than 100 characters
LuciferYang 5524c68
Merge branch 'upmaster' into SPARK-36598
LuciferYang f200546
Merge branch 'upmaster' into SPARK-36598
LuciferYang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,20 +17,28 @@ | |
|
|
||
| package org.apache.spark.network.shuffle; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.common.cache.LoadingCache; | ||
| import com.google.common.io.CharStreams; | ||
| import org.apache.spark.network.shuffle.protocol.ExecutorShuffleInfo; | ||
| import org.apache.spark.network.util.JavaUtils; | ||
| import org.apache.spark.network.util.MapConfigProvider; | ||
| import org.apache.spark.network.util.TransportConf; | ||
| import org.apache.spark.network.shuffle.ExternalShuffleBlockResolver.AppExecId; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| import static org.junit.Assert.*; | ||
|
|
||
|
|
@@ -110,6 +118,48 @@ public void testSortShuffleBlocks() throws IOException { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testShuffleIndexCacheEvictionBehavior() throws IOException, ExecutionException { | ||
| Map<String, String> config = new HashMap<>(); | ||
| String indexCacheSize = "8192m"; | ||
| config.put("spark.shuffle.service.index.cache.size", indexCacheSize); | ||
| TransportConf transportConf = new TransportConf("shuffle", new MapConfigProvider(config)); | ||
| ExternalShuffleBlockResolver resolver = new ExternalShuffleBlockResolver(transportConf, null); | ||
| resolver.registerExecutor("app0", "exec0", dataContext.createExecutorInfo(SORT_MANAGER)); | ||
|
|
||
| LoadingCache<File, ShuffleIndexInformation> shuffleIndexCache = resolver.shuffleIndexCache; | ||
|
|
||
| // 8g -> 8589934592 bytes | ||
| long maximumWeight = JavaUtils.byteStringAsBytes(indexCacheSize); | ||
| int unitSize = 1048575; | ||
| // CacheBuilder.DEFAULT_CONCURRENCY_LEVEL | ||
| int concurrencyLevel = 4; | ||
| int totalGetCount = 16384; | ||
| // maxCacheCount is 8192 | ||
| long maxCacheCount = maximumWeight / concurrencyLevel / unitSize * concurrencyLevel; | ||
| for (int i = 0; i < totalGetCount; i++) { | ||
| File indexFile = new File("shuffle_" + 0 + "_" + i + "_0.index"); | ||
| ShuffleIndexInformation indexInfo = Mockito.mock(ShuffleIndexInformation.class); | ||
| Mockito.when(indexInfo.getSize()).thenReturn(unitSize); | ||
| shuffleIndexCache.get(indexFile, () -> indexInfo); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not easy to mock the init behavior of ShuffleIndexInformation, so there re-write CacheLoader. |
||
| } | ||
|
|
||
| long totalWeight = | ||
| shuffleIndexCache.asMap().values().stream().mapToLong(ShuffleIndexInformation::getSize).sum(); | ||
| long size = shuffleIndexCache.size(); | ||
| try{ | ||
| Assert.assertTrue(size <= maxCacheCount); | ||
| Assert.assertTrue(totalWeight < maximumWeight); | ||
| fail("The tests code should not enter this line now."); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should enter line 153, but it won't now |
||
| } catch (AssertionError error) { | ||
| // The code will enter this branch because LocalCache weight eviction does not work | ||
| // when maxSegmentWeight is >= Int.MAX_VALUE. | ||
| // TODO remove cache AssertionError after fix this bug. | ||
| Assert.assertTrue(size > maxCacheCount && size <= totalGetCount); | ||
| Assert.assertTrue(totalWeight > maximumWeight); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void jsonSerializationOfExecutorRegistration() throws IOException { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configure
spark.shuffle.service.index.cache.sizewith 8g and the default concurrencyLevel is 4, so themaxSegmentWeightLocal Cache isInt.MAX_VALUE, these condition will trigger the bug