diff options
author | Nathan Harmata <nharmata@google.com> | 2015-11-04 18:45:30 +0000 |
---|---|---|
committer | John Field <jfield@google.com> | 2015-11-05 16:49:31 +0000 |
commit | 70b5130a854abba9a2fb1f503e1dfdb5ddfeca84 (patch) | |
tree | 8824ef2d27157d7aeceecc50661a06646f870c44 /src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java | |
parent | 53856cb4ae007ac347a3587e90d4c106e49777bc (diff) |
Increase the concurrency level of the filesystem call caches used in legacy package loading from the LoadingCache default of 4 to value of --legacy_globbing_threads.
--
MOS_MIGRATED_REVID=107056166
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java | 118 |
1 files changed, 74 insertions, 44 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java index 51df3671a4..ebb0618ae9 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PerBuildSyscallCache.java @@ -37,19 +37,60 @@ public class PerBuildSyscallCache implements UnixGlob.FilesystemCalls { private static final FileStatus NO_STATUS = new FakeFileStatus(); - /** - * Create a new per-build filesystem cache. - * - * @param maxStats Max stat results to keep in cache, or -1 for unbounded. - * @param maxReaddirs Max readdir results to keep in cache, or -1 for unbounded. - */ - public PerBuildSyscallCache(int maxStats, int maxReaddirs) { - statCache = newStatMap(maxStats); - readdirCache = newReaddirMap(maxReaddirs); + private PerBuildSyscallCache(LoadingCache<Pair<Path, Symlinks>, FileStatus> statCache, + LoadingCache<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>> readdirCache) { + this.statCache = statCache; + this.readdirCache = readdirCache; } - public static PerBuildSyscallCache newUnboundedCache() { - return new PerBuildSyscallCache(-1, -1); + public static Builder newBuilder() { + return new Builder(); + } + + /** Builder for a per-build filesystem cache. */ + public static class Builder { + private static final int UNSET = -1; + private int maxStats = UNSET; + private int maxReaddirs = UNSET; + private int concurrencyLevel = UNSET; + + private Builder() { + } + + /** Sets the upper bound of the 'stat' cache. This cache is unbounded by default. */ + public Builder setMaxStats(int maxStats) { + this.maxStats = maxStats; + return this; + } + + /** Sets the upper bound of the 'readdir' cache. This cache is unbounded by default. */ + public Builder setMaxReaddirs(int maxReaddirs) { + this.maxReaddirs = maxReaddirs; + return this; + } + + /** Sets the concurrency level of the caches. */ + public Builder setConcurrencyLevel(int concurrencyLevel) { + this.concurrencyLevel = concurrencyLevel; + return this; + } + + public PerBuildSyscallCache build() { + CacheBuilder<Object, Object> statCacheBuilder = CacheBuilder.newBuilder(); + if (maxStats != UNSET) { + statCacheBuilder = statCacheBuilder.maximumSize(maxStats); + } + CacheBuilder<Object, Object> readdirCacheBuilder = CacheBuilder.newBuilder(); + if (maxReaddirs != UNSET) { + readdirCacheBuilder = readdirCacheBuilder.maximumSize(maxStats); + } + if (concurrencyLevel != UNSET) { + statCacheBuilder = statCacheBuilder.concurrencyLevel(concurrencyLevel); + readdirCacheBuilder = readdirCacheBuilder.concurrencyLevel(concurrencyLevel); + } + return new PerBuildSyscallCache(statCacheBuilder.build(newStatLoader()), + readdirCacheBuilder.build(newReaddirLoader())); + } } @Override @@ -113,49 +154,38 @@ public class PerBuildSyscallCache implements UnixGlob.FilesystemCalls { } /** - * A cache of stat calls. + * A {@link CacheLoader} for a cache of stat calls. * Input: (path, following_symlinks) * Output: FileStatus */ - private static LoadingCache<Pair<Path, Symlinks>, FileStatus> newStatMap(int maxStats) { - return builderWithOptionalMax(maxStats).build( - new CacheLoader<Pair<Path, Symlinks>, FileStatus>() { - @Override - public FileStatus load(Pair<Path, Symlinks> p) { - FileStatus f = p.first.statNullable(p.second); - return (f == null) ? NO_STATUS : f; - } - }); + private static CacheLoader<Pair<Path, Symlinks>, FileStatus> newStatLoader() { + return new CacheLoader<Pair<Path, Symlinks>, FileStatus>() { + @Override + public FileStatus load(Pair<Path, Symlinks> p) { + FileStatus f = p.first.statNullable(p.second); + return (f == null) ? NO_STATUS : f; + } + }; } /** - * A cache of readdir calls. + * A {@link CacheLoader} for a cache of readdir calls. * Input: (path, following_symlinks) * Output: A union of (Dirents, IOException). */ private static - LoadingCache<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>> newReaddirMap( - int maxReaddirs) { - return builderWithOptionalMax(maxReaddirs).build( - new CacheLoader<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>>() { - @Override - public Pair<Collection<Dirent>, IOException> load(Pair<Path, Symlinks> p) { - try { - // TODO(bazel-team): Consider storing the Collection of Dirent values more compactly - // by reusing DirectoryEntryListingStateValue#CompactSortedDirents. - return Pair.of(p.first.readdir(p.second), null); - } catch (IOException e) { - return Pair.of(null, e); - } + CacheLoader<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>> newReaddirLoader() { + return new CacheLoader<Pair<Path, Symlinks>, Pair<Collection<Dirent>, IOException>>() { + @Override + public Pair<Collection<Dirent>, IOException> load(Pair<Path, Symlinks> p) { + try { + // TODO(bazel-team): Consider storing the Collection of Dirent values more compactly + // by reusing DirectoryEntryListingStateValue#CompactSortedDirents. + return Pair.of(p.first.readdir(p.second), null); + } catch (IOException e) { + return Pair.of(null, e); } - }); - } - - private static CacheBuilder<Object, Object> builderWithOptionalMax(int maxEntries) { - CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); - if (maxEntries >= 0) { - builder = builder.maximumSize(maxEntries); - } - return builder; + } + }; } } |