From f33d551ea6ed6a46c70cafd3a567933fe1159ddf Mon Sep 17 00:00:00 2001 From: Nick Felt Date: Wed, 30 May 2018 19:27:26 -0700 Subject: [PATCH] Add GCS_READ_CACHE_DISABLED explicit env var to GcsFileSystem PiperOrigin-RevId: 198658074 --- tensorflow/core/platform/cloud/gcs_file_system.cc | 8 ++++++++ tensorflow/core/platform/cloud/ram_file_block_cache.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tensorflow/core/platform/cloud/gcs_file_system.cc b/tensorflow/core/platform/cloud/gcs_file_system.cc index d3a1489..22ae612 100644 --- a/tensorflow/core/platform/cloud/gcs_file_system.cc +++ b/tensorflow/core/platform/cloud/gcs_file_system.cc @@ -64,6 +64,10 @@ constexpr uint64 HTTP_CODE_RESUME_INCOMPLETE = 308; // The environment variable that overrides the size of the readahead buffer. // DEPRECATED. Use GCS_BLOCK_SIZE_MB instead. constexpr char kReadaheadBufferSize[] = "GCS_READAHEAD_BUFFER_SIZE_BYTES"; +// The environment variable that disables the GCS block cache for reads. +// This is the explicit alternative to setting BLOCK_SIZE or MAX_SIZE to 0, and +// takes precedence over either of those environment variables. +constexpr char kReadCacheDisabled[] = "GCS_READ_CACHE_DISABLED"; // The environment variable that overrides the block size for aligned reads from // GCS. Specified in MB (e.g. "16" = 16 x 1024 x 1024 = 16777216 bytes). constexpr char kBlockSize[] = "GCS_READ_CACHE_BLOCK_SIZE_MB"; @@ -623,6 +627,10 @@ GcsFileSystem::GcsFileSystem() if (GetEnvVar(kMaxStaleness, strings::safe_strtou64, &value)) { max_staleness = value; } + if (std::getenv(kReadCacheDisabled)) { + // Setting either to 0 disables the cache; set both for good measure. + block_size = max_bytes = 0; + } file_block_cache_ = MakeFileBlockCache(block_size, max_bytes, max_staleness); // Apply overrides for the stat cache max age and max entries, if provided. uint64 stat_cache_max_age = kStatCacheDefaultMaxAge; diff --git a/tensorflow/core/platform/cloud/ram_file_block_cache.h b/tensorflow/core/platform/cloud/ram_file_block_cache.h index 2303f9c..46fb9a3 100644 --- a/tensorflow/core/platform/cloud/ram_file_block_cache.h +++ b/tensorflow/core/platform/cloud/ram_file_block_cache.h @@ -60,6 +60,8 @@ class RamFileBlockCache : public FileBlockCache { pruning_thread_.reset(env_->StartThread(ThreadOptions(), "TF_prune_FBC", [this] { Prune(); })); } + VLOG(1) << "GCS file block cache is " + << (IsCacheEnabled() ? "enabled" : "disabled"); } ~RamFileBlockCache() override { -- 2.7.4