-
Notifications
You must be signed in to change notification settings - Fork 136
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
[ISSUE-186][Feature] Use I/O cost time to select storage paths #192
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eee3726
[ISSUE-186][Feature] Use I/O cost time to select storage paths
1acc0cc
fix ut
38413f0
fix checkstyle
7c0d063
pass ut
d143614
pass ut
b939802
pass ut
02e5a1a
pass ut
80225fc
fix sth
afc108a
fix sth
27106ff
add access times
09d051e
Update HealthSelectStorageStrategy.java
smallzhongfeng 306acbb
change name
00f6892
add config to doc
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 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
144 changes: 144 additions & 0 deletions
144
...dinator/src/main/java/org/apache/uniffle/coordinator/AppBalanceSelectStorageStrategy.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* 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.uniffle.coordinator; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Maps; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.uniffle.common.RemoteStorageInfo; | ||
import org.apache.uniffle.coordinator.LowestIOSampleCostSelectStorageStrategy.RankValue; | ||
|
||
/** | ||
* AppBalanceSelectStorageStrategy will consider the number of apps allocated on each remote path is balanced. | ||
*/ | ||
public class AppBalanceSelectStorageStrategy implements SelectStorageStrategy { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AppBalanceSelectStorageStrategy.class); | ||
/** | ||
* store appId -> remote path to make sure all shuffle data of the same application | ||
* will be written to the same remote storage | ||
*/ | ||
private final Map<String, RemoteStorageInfo> appIdToRemoteStorageInfo; | ||
/** | ||
* store remote path -> application count for assignment strategy | ||
*/ | ||
private final Map<String, RankValue> remoteStoragePathCounter; | ||
private final Map<String, RemoteStorageInfo> availableRemoteStorageInfo; | ||
|
||
public AppBalanceSelectStorageStrategy() { | ||
this.appIdToRemoteStorageInfo = Maps.newConcurrentMap(); | ||
this.remoteStoragePathCounter = Maps.newConcurrentMap(); | ||
this.availableRemoteStorageInfo = Maps.newHashMap(); | ||
} | ||
|
||
/** | ||
* the strategy of pick remote storage is according to assignment count | ||
*/ | ||
@Override | ||
public RemoteStorageInfo pickRemoteStorage(String appId) { | ||
if (appIdToRemoteStorageInfo.containsKey(appId)) { | ||
return appIdToRemoteStorageInfo.get(appId); | ||
} | ||
|
||
// create list for sort | ||
List<Map.Entry<String, RankValue>> sizeList = | ||
Lists.newArrayList(remoteStoragePathCounter.entrySet()).stream().filter(Objects::nonNull) | ||
.sorted(Comparator.comparingInt(entry -> entry.getValue().getAppNum().get())).collect(Collectors.toList()); | ||
|
||
for (Map.Entry<String, RankValue> entry : sizeList) { | ||
String storagePath = entry.getKey(); | ||
if (availableRemoteStorageInfo.containsKey(storagePath)) { | ||
appIdToRemoteStorageInfo.putIfAbsent(appId, availableRemoteStorageInfo.get(storagePath)); | ||
incRemoteStorageCounter(storagePath); | ||
break; | ||
} | ||
} | ||
return appIdToRemoteStorageInfo.get(appId); | ||
} | ||
|
||
@Override | ||
@VisibleForTesting | ||
public synchronized void incRemoteStorageCounter(String remoteStoragePath) { | ||
RankValue counter = remoteStoragePathCounter.get(remoteStoragePath); | ||
if (counter != null) { | ||
counter.getAppNum().incrementAndGet(); | ||
} else { | ||
// it may be happened when assignment remote storage | ||
// and refresh remote storage at the same time | ||
LOG.warn("Remote storage path lost during assignment: %s doesn't exist, reset it to 1", | ||
remoteStoragePath); | ||
remoteStoragePathCounter.put(remoteStoragePath, new RankValue(1)); | ||
} | ||
} | ||
|
||
@Override | ||
@VisibleForTesting | ||
public synchronized void decRemoteStorageCounter(String storagePath) { | ||
if (!StringUtils.isEmpty(storagePath)) { | ||
RankValue atomic = remoteStoragePathCounter.get(storagePath); | ||
if (atomic != null) { | ||
double count = atomic.getAppNum().decrementAndGet(); | ||
if (count < 0) { | ||
LOG.warn("Unexpected counter for remote storage: %s, which is %i, reset to 0", | ||
storagePath, count); | ||
atomic.getAppNum().set(0); | ||
} | ||
} else { | ||
LOG.warn("Can't find counter for remote storage: {}", storagePath); | ||
remoteStoragePathCounter.putIfAbsent(storagePath, new RankValue(0)); | ||
} | ||
if (remoteStoragePathCounter.get(storagePath).getAppNum().get() == 0 | ||
&& !availableRemoteStorageInfo.containsKey(storagePath)) { | ||
remoteStoragePathCounter.remove(storagePath); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void removePathFromCounter(String storagePath) { | ||
RankValue atomic = remoteStoragePathCounter.get(storagePath); | ||
if (atomic != null && atomic.getAppNum().get() == 0) { | ||
remoteStoragePathCounter.remove(storagePath); | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, RemoteStorageInfo> getAppIdToRemoteStorageInfo() { | ||
return appIdToRemoteStorageInfo; | ||
} | ||
|
||
@Override | ||
public Map<String, RankValue> getRemoteStoragePathRankValue() { | ||
return remoteStoragePathCounter; | ||
} | ||
|
||
@Override | ||
public Map<String, RemoteStorageInfo> getAvailableRemoteStorageInfo() { | ||
return availableRemoteStorageInfo; | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.
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.
Could we add the new configuration option to the documents?
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.
OK.