|
139 | 139 | import com.google.common.cache.CacheLoader; |
140 | 140 | import com.google.common.cache.LoadingCache; |
141 | 141 | import com.google.common.cache.RemovalListener; |
142 | | -import com.google.common.cache.RemovalNotification; |
143 | | -import com.google.common.cache.Weigher; |
144 | 142 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
145 | 143 | import org.apache.hadoop.thirdparty.protobuf.ByteString; |
146 | 144 |
|
@@ -836,63 +834,58 @@ public ChannelPipeline getPipeline() throws Exception { |
836 | 834 | // TODO factor out encode/decode to permit binary shuffle |
837 | 835 | // TODO factor out decode of index to permit alt. models |
838 | 836 | } |
839 | | - |
840 | 837 | } |
841 | 838 |
|
842 | 839 | class Shuffle extends SimpleChannelUpstreamHandler { |
843 | | - private static final int MAX_WEIGHT = 10 * 1024 * 1024; |
844 | | - private static final int EXPIRE_AFTER_ACCESS_MINUTES = 5; |
845 | | - private static final int ALLOWED_CONCURRENCY = 16; |
846 | | - private final Configuration conf; |
| 840 | + private static final String MAX_WEIGHT = |
| 841 | + "mapreduce.shuffle.pathcache.max-weight"; |
| 842 | + private static final int DEFAULT_MAX_WEIGHT = 10 * 1024 * 1024; |
| 843 | + |
| 844 | + private static final String EXPIRE_AFTER_ACCESS_MINUTES = |
| 845 | + "mapreduce.shuffle.pathcache.expire-after-access-minutes"; |
| 846 | + private static final int DEFAULT_EXPIRE_AFTER_ACCESS_MINUTES = 5; |
| 847 | + |
| 848 | + private static final String CONCURRENCY_LEVEL = |
| 849 | + "mapreduce.shuffle.pathcache.concurrency-level"; |
| 850 | + private static final int DEFAULT_CONCURRENCY_LEVEL = 16; |
| 851 | + |
847 | 852 | private final IndexCache indexCache; |
| 853 | + private final |
| 854 | + LoadingCache<AttemptPathIdentifier, AttemptPathInfo> pathCache; |
| 855 | + |
848 | 856 | private int port; |
849 | | - private final LoadingCache<AttemptPathIdentifier, AttemptPathInfo> pathCache = |
850 | | - CacheBuilder.newBuilder().expireAfterAccess(EXPIRE_AFTER_ACCESS_MINUTES, |
851 | | - TimeUnit.MINUTES).softValues().concurrencyLevel(ALLOWED_CONCURRENCY). |
852 | | - removalListener( |
853 | | - new RemovalListener<AttemptPathIdentifier, AttemptPathInfo>() { |
854 | | - @Override |
855 | | - public void onRemoval(RemovalNotification<AttemptPathIdentifier, |
856 | | - AttemptPathInfo> notification) { |
857 | | - if (LOG.isDebugEnabled()) { |
858 | | - LOG.debug("PathCache Eviction: " + notification.getKey() + |
859 | | - ", Reason=" + notification.getCause()); |
860 | | - } |
861 | | - } |
862 | | - } |
863 | | - ).maximumWeight(MAX_WEIGHT).weigher( |
864 | | - new Weigher<AttemptPathIdentifier, AttemptPathInfo>() { |
865 | | - @Override |
866 | | - public int weigh(AttemptPathIdentifier key, |
867 | | - AttemptPathInfo value) { |
868 | | - return key.jobId.length() + key.user.length() + |
869 | | - key.attemptId.length()+ |
870 | | - value.indexPath.toString().length() + |
871 | | - value.dataPath.toString().length(); |
872 | | - } |
873 | | - } |
874 | | - ).build(new CacheLoader<AttemptPathIdentifier, AttemptPathInfo>() { |
875 | | - @Override |
876 | | - public AttemptPathInfo load(AttemptPathIdentifier key) throws |
877 | | - Exception { |
878 | | - String base = getBaseLocation(key.jobId, key.user); |
879 | | - String attemptBase = base + key.attemptId; |
880 | | - Path indexFileName = getAuxiliaryLocalPathHandler() |
881 | | - .getLocalPathForRead(attemptBase + "/" + INDEX_FILE_NAME); |
882 | | - Path mapOutputFileName = getAuxiliaryLocalPathHandler() |
883 | | - .getLocalPathForRead(attemptBase + "/" + DATA_FILE_NAME); |
884 | | - |
885 | | - if (LOG.isDebugEnabled()) { |
886 | | - LOG.debug("Loaded : " + key + " via loader"); |
887 | | - } |
888 | | - return new AttemptPathInfo(indexFileName, mapOutputFileName); |
889 | | - } |
890 | | - }); |
891 | 857 |
|
892 | | - public Shuffle(Configuration conf) { |
893 | | - this.conf = conf; |
894 | | - indexCache = new IndexCache(new JobConf(conf)); |
| 858 | + Shuffle(Configuration conf) { |
895 | 859 | this.port = conf.getInt(SHUFFLE_PORT_CONFIG_KEY, DEFAULT_SHUFFLE_PORT); |
| 860 | + this.indexCache = new IndexCache(new JobConf(conf)); |
| 861 | + this.pathCache = CacheBuilder.newBuilder() |
| 862 | + .expireAfterAccess(conf.getInt(EXPIRE_AFTER_ACCESS_MINUTES, |
| 863 | + DEFAULT_EXPIRE_AFTER_ACCESS_MINUTES), TimeUnit.MINUTES) |
| 864 | + .softValues() |
| 865 | + .concurrencyLevel(conf.getInt(CONCURRENCY_LEVEL, |
| 866 | + DEFAULT_CONCURRENCY_LEVEL)) |
| 867 | + .removalListener((RemovalListener<AttemptPathIdentifier, |
| 868 | + AttemptPathInfo>) notification -> |
| 869 | + LOG.debug("PathCache Eviction: {}, Reason={}", |
| 870 | + notification.getKey(), notification.getCause())) |
| 871 | + .maximumWeight(conf.getInt(MAX_WEIGHT, DEFAULT_MAX_WEIGHT)) |
| 872 | + .weigher((key, value) -> key.jobId.length() + key.user.length() + |
| 873 | + key.attemptId.length()+ value.indexPath.toString().length() + |
| 874 | + value.dataPath.toString().length()) |
| 875 | + .build(new CacheLoader<AttemptPathIdentifier, AttemptPathInfo>() { |
| 876 | + @Override |
| 877 | + public AttemptPathInfo load(AttemptPathIdentifier key) throws |
| 878 | + Exception { |
| 879 | + String base = getBaseLocation(key.jobId, key.user); |
| 880 | + String attemptBase = base + key.attemptId; |
| 881 | + Path indexFileName = getAuxiliaryLocalPathHandler() |
| 882 | + .getLocalPathForRead(attemptBase + "/" + INDEX_FILE_NAME); |
| 883 | + Path mapOutputFileName = getAuxiliaryLocalPathHandler() |
| 884 | + .getLocalPathForRead(attemptBase + "/" + DATA_FILE_NAME); |
| 885 | + LOG.debug("Loaded : {} via loader", key); |
| 886 | + return new AttemptPathInfo(indexFileName, mapOutputFileName); |
| 887 | + } |
| 888 | + }); |
896 | 889 | } |
897 | 890 |
|
898 | 891 | public void setPort(int port) { |
|
0 commit comments