You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/12 17:02:56 UTC

[doris] 12/33: [Improve](FileCahe) Support the file cache profile in olap scan node and Update the profile (#17710)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch doris-for-zhongjin
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 3ba7ea4c9279f83e521353188c54158d0a568a24
Author: Lightman <31...@users.noreply.github.com>
AuthorDate: Tue Apr 4 10:18:30 2023 +0800

    [Improve](FileCahe) Support the file cache profile in olap scan node and Update the profile (#17710)
    
    We want to use file cache for caching cold data in S3.
    When reading them, we want to know where the data come from and the time taken to read the datas.
    So we support the metrics in olap scan node.
    And for clearing the information, i also update the fields about the metrics.
---
 be/src/io/cache/block/block_file_cache_profile.cpp | 132 ++++++---------------
 be/src/io/cache/block/block_file_cache_profile.h   |  91 +++++++-------
 .../io/cache/block/cached_remote_file_reader.cpp   |  87 ++++++++------
 be/src/io/cache/block/cached_remote_file_reader.h  |  13 +-
 be/src/io/io_common.h                              |  17 +--
 be/src/vec/exec/scan/new_olap_scanner.cpp          |   6 +
 6 files changed, 153 insertions(+), 193 deletions(-)

diff --git a/be/src/io/cache/block/block_file_cache_profile.cpp b/be/src/io/cache/block/block_file_cache_profile.cpp
index d18a0e180e..61b0ef72ce 100644
--- a/be/src/io/cache/block/block_file_cache_profile.cpp
+++ b/be/src/io/cache/block/block_file_cache_profile.cpp
@@ -22,63 +22,30 @@
 namespace doris {
 namespace io {
 
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_total, MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_hit_cache, MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_bytes_read_total, MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_bytes_read_from_file_cache,
-                                     MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_bytes_read_from_write_cache,
-                                     MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_written_in_file_cache,
-                                     MetricUnit::OPERATIONS);
-DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_cache_num_io_bytes_written_in_file_cache,
-                                     MetricUnit::OPERATIONS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_total, MetricUnit::OPERATIONS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_cache, MetricUnit::OPERATIONS);
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_remote, MetricUnit::OPERATIONS);
 
-FileCacheStatistics FileCacheProfile::report(int64_t table_id, int64_t partition_id) {
-    FileCacheStatistics stats;
+std::shared_ptr<AtomicStatistics> FileCacheProfile::report(int64_t table_id, int64_t partition_id) {
+    std::shared_ptr<AtomicStatistics> stats = std::make_shared<AtomicStatistics>();
     if (_profile.count(table_id) == 1 && _profile[table_id].count(partition_id) == 1) {
-        std::shared_ptr<AtomicStatistics> count;
-        {
-            std::lock_guard lock(_mtx);
-            count = _profile[table_id][partition_id];
-        }
-        stats.num_io_total = count->num_io_total.load(std::memory_order_relaxed);
-        stats.num_io_hit_cache = count->num_io_hit_cache.load(std::memory_order_relaxed);
-        stats.num_io_bytes_read_total =
-                count->num_io_bytes_read_total.load(std::memory_order_relaxed);
-        stats.num_io_bytes_read_from_file_cache =
-                count->num_io_bytes_read_from_file_cache.load(std::memory_order_relaxed);
-        stats.num_io_bytes_read_from_write_cache =
-                count->num_io_bytes_read_from_write_cache.load(std::memory_order_relaxed);
-        stats.num_io_written_in_file_cache =
-                count->num_io_written_in_file_cache.load(std::memory_order_relaxed);
-        stats.num_io_bytes_written_in_file_cache =
-                count->num_io_bytes_written_in_file_cache.load(std::memory_order_relaxed);
+        std::lock_guard lock(_mtx);
+        stats->num_io_bytes_read_from_cache +=
+                (_profile[table_id][partition_id])->num_io_bytes_read_from_cache;
+        stats->num_io_bytes_read_from_cache +=
+                _profile[table_id][partition_id]->num_io_bytes_read_from_cache;
     }
     return stats;
 }
 
-FileCacheStatistics FileCacheProfile::report(int64_t table_id) {
-    FileCacheStatistics stats;
+std::shared_ptr<AtomicStatistics> FileCacheProfile::report(int64_t table_id) {
+    std::shared_ptr<AtomicStatistics> stats = std::make_shared<AtomicStatistics>();
     if (_profile.count(table_id) == 1) {
         std::lock_guard lock(_mtx);
         auto& partition_map = _profile[table_id];
-        for (auto& [partition_id, atomic_stats] : partition_map) {
-            stats.num_io_total += atomic_stats->num_io_total.load(std::memory_order_relaxed);
-            stats.num_io_hit_cache +=
-                    atomic_stats->num_io_hit_cache.load(std::memory_order_relaxed);
-            stats.num_io_bytes_read_total +=
-                    atomic_stats->num_io_bytes_read_total.load(std::memory_order_relaxed);
-            stats.num_io_bytes_read_from_file_cache +=
-                    atomic_stats->num_io_bytes_read_from_file_cache.load(std::memory_order_relaxed);
-            stats.num_io_bytes_read_from_write_cache +=
-                    atomic_stats->num_io_bytes_read_from_write_cache.load(
-                            std::memory_order_relaxed);
-            stats.num_io_written_in_file_cache +=
-                    atomic_stats->num_io_written_in_file_cache.load(std::memory_order_relaxed);
-            stats.num_io_bytes_written_in_file_cache +=
-                    atomic_stats->num_io_bytes_written_in_file_cache.load(
-                            std::memory_order_relaxed);
+        for (auto& [_, partition_stats] : partition_map) {
+            stats->num_io_bytes_read_from_cache += partition_stats->num_io_bytes_read_from_cache;
+            stats->num_io_bytes_read_from_remote += partition_stats->num_io_bytes_read_from_remote;
         }
     }
     return stats;
@@ -110,19 +77,8 @@ void FileCacheProfile::update(int64_t table_id, int64_t partition_id, OlapReader
     if (table_metric) {
         table_metric->register_entity();
     }
-    count->num_io_total.fetch_add(stats->file_cache_stats.num_io_total, std::memory_order_relaxed);
-    count->num_io_hit_cache.fetch_add(stats->file_cache_stats.num_io_hit_cache,
-                                      std::memory_order_relaxed);
-    count->num_io_bytes_read_total.fetch_add(stats->file_cache_stats.num_io_bytes_read_total,
-                                             std::memory_order_relaxed);
-    count->num_io_bytes_read_from_file_cache.fetch_add(
-            stats->file_cache_stats.num_io_bytes_read_from_file_cache, std::memory_order_relaxed);
-    count->num_io_bytes_read_from_write_cache.fetch_add(
-            stats->file_cache_stats.num_io_bytes_read_from_write_cache, std::memory_order_relaxed);
-    count->num_io_written_in_file_cache.fetch_add(
-            stats->file_cache_stats.num_io_written_in_file_cache, std::memory_order_relaxed);
-    count->num_io_bytes_written_in_file_cache.fetch_add(
-            stats->file_cache_stats.num_io_bytes_written_in_file_cache, std::memory_order_relaxed);
+    count->num_io_bytes_read_from_cache += stats->file_cache_stats.bytes_read_from_local;
+    count->num_io_bytes_read_from_remote += stats->file_cache_stats.bytes_read_from_remote;
 }
 
 void FileCacheProfile::deregister_metric(int64_t table_id, int64_t partition_id) {
@@ -152,48 +108,32 @@ void FileCacheProfile::deregister_metric(int64_t table_id, int64_t partition_id)
 }
 
 void FileCacheMetric::register_entity() {
-    std::string name = "table_" + std::to_string(table_id);
-    if (partition_id != -1) {
-        name += "_partition_" + std::to_string(partition_id);
-    }
+    std::string table_id_str = std::to_string(table_id);
+    std::string partition_id_str = partition_id != -1 ? std::to_string(partition_id) : "total";
     entity = DorisMetrics::instance()->metric_registry()->register_entity(
-            std::string("cloud_file_cache"), {{"name", name}});
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_total);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_hit_cache);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_bytes_read_total);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_bytes_read_from_file_cache);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_bytes_read_from_write_cache);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_written_in_file_cache);
-    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, file_cache_num_io_bytes_written_in_file_cache);
-    entity->register_hook(name, std::bind(&FileCacheMetric::update_table_metrics, this));
+            std::string("cloud_file_cache"),
+            {{"table_id", table_id_str}, {"partition_id", partition_id_str}});
+    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, num_io_bytes_read_total);
+    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, num_io_bytes_read_from_cache);
+    INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, num_io_bytes_read_from_remote);
+    entity->register_hook("cloud_file_cache",
+                          std::bind(&FileCacheMetric::update_table_metrics, this));
 }
 
 void FileCacheMetric::update_table_metrics() const {
-    FileCacheStatistics stats = profile->report(table_id);
-    file_cache_num_io_total->set_value(stats.num_io_total);
-    file_cache_num_io_hit_cache->set_value(stats.num_io_hit_cache);
-    file_cache_num_io_bytes_read_total->set_value(stats.num_io_bytes_read_total);
-    file_cache_num_io_bytes_read_from_file_cache->set_value(
-            stats.num_io_bytes_read_from_file_cache);
-    file_cache_num_io_bytes_read_from_write_cache->set_value(
-            stats.num_io_bytes_read_from_write_cache);
-    file_cache_num_io_written_in_file_cache->set_value(stats.num_io_written_in_file_cache);
-    file_cache_num_io_bytes_written_in_file_cache->set_value(
-            stats.num_io_bytes_written_in_file_cache);
+    auto stats = profile->report(table_id);
+    num_io_bytes_read_from_cache->set_value(stats->num_io_bytes_read_from_cache);
+    num_io_bytes_read_from_remote->set_value(stats->num_io_bytes_read_from_remote);
+    num_io_bytes_read_total->set_value(stats->num_io_bytes_read_from_cache +
+                                       stats->num_io_bytes_read_from_remote);
 }
 
 void FileCacheMetric::update_partition_metrics() const {
-    FileCacheStatistics stats = profile->report(table_id, partition_id);
-    file_cache_num_io_total->set_value(stats.num_io_total);
-    file_cache_num_io_hit_cache->set_value(stats.num_io_hit_cache);
-    file_cache_num_io_bytes_read_total->set_value(stats.num_io_bytes_read_total);
-    file_cache_num_io_bytes_read_from_file_cache->set_value(
-            stats.num_io_bytes_read_from_file_cache);
-    file_cache_num_io_bytes_read_from_write_cache->set_value(
-            stats.num_io_bytes_read_from_write_cache);
-    file_cache_num_io_written_in_file_cache->set_value(stats.num_io_written_in_file_cache);
-    file_cache_num_io_bytes_written_in_file_cache->set_value(
-            stats.num_io_bytes_written_in_file_cache);
+    auto stats = profile->report(table_id, partition_id);
+    num_io_bytes_read_from_cache->set_value(stats->num_io_bytes_read_from_cache);
+    num_io_bytes_read_from_remote->set_value(stats->num_io_bytes_read_from_remote);
+    num_io_bytes_read_total->set_value(stats->num_io_bytes_read_from_cache +
+                                       stats->num_io_bytes_read_from_remote);
 }
 
 } // namespace io
diff --git a/be/src/io/cache/block/block_file_cache_profile.h b/be/src/io/cache/block/block_file_cache_profile.h
index dfbd026f6c..858a07aed5 100644
--- a/be/src/io/cache/block/block_file_cache_profile.h
+++ b/be/src/io/cache/block/block_file_cache_profile.h
@@ -35,13 +35,8 @@ namespace doris {
 namespace io {
 
 struct AtomicStatistics {
-    std::atomic<int64_t> num_io_total = 0;
-    std::atomic<int64_t> num_io_hit_cache = 0;
-    std::atomic<int64_t> num_io_bytes_read_total = 0;
-    std::atomic<int64_t> num_io_bytes_read_from_file_cache = 0;
-    std::atomic<int64_t> num_io_bytes_read_from_write_cache = 0;
-    std::atomic<int64_t> num_io_written_in_file_cache = 0;
-    std::atomic<int64_t> num_io_bytes_written_in_file_cache = 0;
+    std::atomic<int64_t> num_io_bytes_read_from_cache = 0;
+    std::atomic<int64_t> num_io_bytes_read_from_remote = 0;
 };
 
 struct FileCacheProfile;
@@ -66,13 +61,9 @@ struct FileCacheMetric {
     int64_t table_id = -1;
     int64_t partition_id = -1;
     std::shared_ptr<MetricEntity> entity;
-    IntAtomicCounter* file_cache_num_io_total = nullptr;
-    IntAtomicCounter* file_cache_num_io_hit_cache = nullptr;
-    IntAtomicCounter* file_cache_num_io_bytes_read_total = nullptr;
-    IntAtomicCounter* file_cache_num_io_bytes_read_from_file_cache = nullptr;
-    IntAtomicCounter* file_cache_num_io_bytes_read_from_write_cache = nullptr;
-    IntAtomicCounter* file_cache_num_io_written_in_file_cache = nullptr;
-    IntAtomicCounter* file_cache_num_io_bytes_written_in_file_cache = nullptr;
+    IntAtomicCounter* num_io_bytes_read_total = nullptr;
+    IntAtomicCounter* num_io_bytes_read_from_cache = nullptr;
+    IntAtomicCounter* num_io_bytes_read_from_remote = nullptr;
 };
 
 struct FileCacheProfile {
@@ -108,51 +99,51 @@ struct FileCacheProfile {
     std::unordered_map<int64_t, std::shared_ptr<FileCacheMetric>> _table_metrics;
     std::unordered_map<int64_t, std::unordered_map<int64_t, std::shared_ptr<FileCacheMetric>>>
             _partition_metrics;
-    FileCacheStatistics report(int64_t table_id);
-    FileCacheStatistics report(int64_t table_id, int64_t partition_id);
+    std::shared_ptr<AtomicStatistics> report(int64_t table_id);
+    std::shared_ptr<AtomicStatistics> report(int64_t table_id, int64_t partition_id);
 };
 
 struct FileCacheProfileReporter {
-    RuntimeProfile::Counter* num_io_total;
-    RuntimeProfile::Counter* num_io_hit_cache;
-    RuntimeProfile::Counter* num_io_bytes_read_total;
-    RuntimeProfile::Counter* num_io_bytes_read_from_file_cache;
-    RuntimeProfile::Counter* num_io_bytes_read_from_write_cache;
-    RuntimeProfile::Counter* num_io_written_in_file_cache;
-    RuntimeProfile::Counter* num_io_bytes_written_in_file_cache;
-    RuntimeProfile::Counter* num_io_bytes_skip_cache;
+    RuntimeProfile::Counter* num_local_io_total = nullptr;
+    RuntimeProfile::Counter* num_remote_io_total = nullptr;
+    RuntimeProfile::Counter* local_io_timer = nullptr;
+    RuntimeProfile::Counter* bytes_scanned_from_cache = nullptr;
+    RuntimeProfile::Counter* bytes_scanned_from_remote = nullptr;
+    RuntimeProfile::Counter* remote_io_timer = nullptr;
+    RuntimeProfile::Counter* write_cache_io_timer = nullptr;
+    RuntimeProfile::Counter* bytes_write_into_cache = nullptr;
+    RuntimeProfile::Counter* num_skip_cache_io_total = nullptr;
 
     FileCacheProfileReporter(RuntimeProfile* profile) {
         static const char* cache_profile = "FileCache";
         ADD_TIMER(profile, cache_profile);
-        num_io_total = ADD_CHILD_COUNTER(profile, "IOTotalNum", TUnit::UNIT, cache_profile);
-        num_io_hit_cache = ADD_CHILD_COUNTER(profile, "IOHitCacheNum", TUnit::UNIT, cache_profile);
-        num_io_bytes_read_total =
-                ADD_CHILD_COUNTER(profile, "ReadTotalBytes", TUnit::BYTES, cache_profile);
-        num_io_bytes_read_from_file_cache =
-                ADD_CHILD_COUNTER(profile, "ReadFromFileCacheBytes", TUnit::BYTES, cache_profile);
-        num_io_bytes_read_from_write_cache =
-                ADD_CHILD_COUNTER(profile, "ReadFromWriteCacheBytes", TUnit::BYTES, cache_profile);
-        num_io_written_in_file_cache =
-                ADD_CHILD_COUNTER(profile, "WriteInFileCacheNum", TUnit::UNIT, cache_profile);
-        num_io_bytes_written_in_file_cache =
-                ADD_CHILD_COUNTER(profile, "WriteInFileCacheBytes", TUnit::BYTES, cache_profile);
-        num_io_bytes_skip_cache =
-                ADD_CHILD_COUNTER(profile, "SkipCacheBytes", TUnit::BYTES, cache_profile);
+        num_local_io_total =
+                ADD_CHILD_COUNTER(profile, "NumLocalIOTotal", TUnit::UNIT, cache_profile);
+        num_remote_io_total =
+                ADD_CHILD_COUNTER(profile, "NumRemoteIOTotal", TUnit::UNIT, cache_profile);
+        local_io_timer = ADD_CHILD_TIMER(profile, "LocalIOUseTimer", cache_profile);
+        remote_io_timer = ADD_CHILD_TIMER(profile, "RemoteIOUseTimer", cache_profile);
+        write_cache_io_timer = ADD_CHILD_TIMER(profile, "WriteCacheIOUseTimer", cache_profile);
+        bytes_write_into_cache =
+                ADD_CHILD_COUNTER(profile, "BytesWriteIntoCache", TUnit::BYTES, cache_profile);
+        num_skip_cache_io_total =
+                ADD_CHILD_COUNTER(profile, "NumSkipCacheIOTotal", TUnit::UNIT, cache_profile);
+        bytes_scanned_from_cache =
+                ADD_CHILD_COUNTER(profile, "BytesScannedFromCache", TUnit::BYTES, cache_profile);
+        bytes_scanned_from_remote =
+                ADD_CHILD_COUNTER(profile, "BytesScannedFromRemote", TUnit::BYTES, cache_profile);
     }
 
-    void update(FileCacheStatistics* statistics) {
-        COUNTER_UPDATE(num_io_total, statistics->num_io_total);
-        COUNTER_UPDATE(num_io_hit_cache, statistics->num_io_hit_cache);
-        COUNTER_UPDATE(num_io_bytes_read_total, statistics->num_io_bytes_read_total);
-        COUNTER_UPDATE(num_io_bytes_read_from_file_cache,
-                       statistics->num_io_bytes_read_from_file_cache);
-        COUNTER_UPDATE(num_io_bytes_read_from_write_cache,
-                       statistics->num_io_bytes_read_from_write_cache);
-        COUNTER_UPDATE(num_io_written_in_file_cache, statistics->num_io_written_in_file_cache);
-        COUNTER_UPDATE(num_io_bytes_written_in_file_cache,
-                       statistics->num_io_bytes_written_in_file_cache);
-        COUNTER_UPDATE(num_io_bytes_skip_cache, statistics->num_io_bytes_skip_cache);
+    void update(const FileCacheStatistics* statistics) {
+        COUNTER_UPDATE(num_local_io_total, statistics->num_local_io_total);
+        COUNTER_UPDATE(num_remote_io_total, statistics->num_remote_io_total);
+        COUNTER_UPDATE(local_io_timer, statistics->local_io_timer);
+        COUNTER_UPDATE(remote_io_timer, statistics->remote_io_timer);
+        COUNTER_UPDATE(write_cache_io_timer, statistics->write_cache_io_timer);
+        COUNTER_UPDATE(bytes_write_into_cache, statistics->bytes_write_into_cache);
+        COUNTER_UPDATE(num_skip_cache_io_total, statistics->num_skip_cache_io_total);
+        COUNTER_UPDATE(bytes_scanned_from_cache, statistics->bytes_read_from_local);
+        COUNTER_UPDATE(bytes_scanned_from_remote, statistics->bytes_read_from_remote);
     }
 };
 
diff --git a/be/src/io/cache/block/cached_remote_file_reader.cpp b/be/src/io/cache/block/cached_remote_file_reader.cpp
index c3a3eee9f6..e456811430 100644
--- a/be/src/io/cache/block/cached_remote_file_reader.cpp
+++ b/be/src/io/cache/block/cached_remote_file_reader.cpp
@@ -78,7 +78,6 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
         return _remote_file_reader->read_at(offset, result, bytes_read, io_ctx);
     }
     ReadStatistics stats;
-    stats.bytes_read = bytes_req;
     // if state == nullptr, the method is called for read footer
     // if state->read_segment_index, read all the end of file
     size_t align_left = offset, align_size = size() - offset;
@@ -93,17 +92,27 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
             cache->get_or_set(_cache_key, align_left, align_size, is_persistent, query_id);
     std::vector<FileBlockSPtr> empty_segments;
     for (auto& segment : holder.file_segments) {
-        if (segment->state() == FileBlock::State::EMPTY) {
+        switch (segment->state()) {
+        case FileBlock::State::EMPTY:
             segment->get_or_set_downloader();
             if (segment->is_downloader()) {
                 empty_segments.push_back(segment);
             }
-        } else if (segment->state() == FileBlock::State::SKIP_CACHE) {
+            stats.hit_cache = false;
+            break;
+        case FileBlock::State::SKIP_CACHE:
             empty_segments.push_back(segment);
-            stats.bytes_skip_cache += segment->range().size();
+            stats.hit_cache = false;
+            stats.skip_cache = true;
+            break;
+        case FileBlock::State::DOWNLOADING:
+            stats.hit_cache = false;
+            break;
+        case FileBlock::State::DOWNLOADED:
+            break;
         }
     }
-
+    stats.bytes_read += bytes_req;
     size_t empty_start = 0;
     size_t empty_end = 0;
     if (!empty_segments.empty()) {
@@ -111,18 +120,21 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
         empty_end = empty_segments.back()->range().right;
         size_t size = empty_end - empty_start + 1;
         std::unique_ptr<char[]> buffer(new char[size]);
-        RETURN_IF_ERROR(_remote_file_reader->read_at(empty_start, Slice(buffer.get(), size), &size,
-                                                     io_ctx));
+        {
+            SCOPED_RAW_TIMER(&stats.remote_read_timer);
+            RETURN_IF_ERROR(_remote_file_reader->read_at(empty_start, Slice(buffer.get(), size),
+                                                         &size, io_ctx));
+        }
         for (auto& segment : empty_segments) {
             if (segment->state() == FileBlock::State::SKIP_CACHE) {
                 continue;
             }
+            SCOPED_RAW_TIMER(&stats.local_write_timer);
             char* cur_ptr = buffer.get() + segment->range().left - empty_start;
             size_t segment_size = segment->range().size();
             RETURN_IF_ERROR(segment->append(Slice(cur_ptr, segment_size)));
             RETURN_IF_ERROR(segment->finalize_write());
-            stats.write_in_file_cache++;
-            stats.bytes_write_in_file_cache += segment_size;
+            stats.bytes_write_into_file_cache += segment_size;
         }
         // copy from memory directly
         size_t right_offset = offset + result.size - 1;
@@ -134,8 +146,6 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
             size_t copy_size = copy_right_offset - copy_left_offset + 1;
             memcpy(dst, src, copy_size);
         }
-    } else {
-        stats.hit_cache = true;
     }
 
     size_t current_offset = offset;
@@ -160,25 +170,33 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
         FileBlock::State segment_state;
         int64_t wait_time = 0;
         static int64_t MAX_WAIT_TIME = 10;
-        do {
-            segment_state = segment->wait();
-            if (segment_state == FileBlock::State::DOWNLOADED) {
-                break;
-            }
-            if (segment_state != FileBlock::State::DOWNLOADING) {
-                return Status::IOError(
-                        "File Cache State is {}, the cache downloader encounters an error, please "
-                        "retry it",
-                        segment_state);
-            }
-        } while (++wait_time < MAX_WAIT_TIME);
+        if (segment->state() != FileBlock::State::DOWNLOADED) {
+            do {
+                {
+                    SCOPED_RAW_TIMER(&stats.remote_read_timer);
+                    segment_state = segment->wait();
+                }
+                if (segment_state == FileBlock::State::DOWNLOADED) {
+                    break;
+                }
+                if (segment_state != FileBlock::State::DOWNLOADING) {
+                    return Status::IOError(
+                            "File Cache State is {}, the cache downloader encounters an error, "
+                            "please "
+                            "retry it",
+                            segment_state);
+                }
+            } while (++wait_time < MAX_WAIT_TIME);
+        }
         if (UNLIKELY(wait_time) == MAX_WAIT_TIME) {
             return Status::IOError("Waiting too long for the download to complete");
         }
         size_t file_offset = current_offset - left;
-        RETURN_IF_ERROR(segment->read_at(Slice(result.data + (current_offset - offset), read_size),
-                                         file_offset));
-        stats.bytes_read_from_file_cache += read_size;
+        {
+            SCOPED_RAW_TIMER(&stats.local_read_timer);
+            RETURN_IF_ERROR(segment->read_at(
+                    Slice(result.data + (current_offset - offset), read_size), file_offset));
+        }
         *bytes_read += read_size;
         current_offset = right + 1;
     }
@@ -193,15 +211,18 @@ void CachedRemoteFileReader::_update_state(const ReadStatistics& read_stats,
     if (statis == nullptr) {
         return;
     }
-    statis->num_io_total++;
-    statis->num_io_bytes_read_total += read_stats.bytes_read;
-    statis->num_io_bytes_written_in_file_cache += read_stats.bytes_write_in_file_cache;
     if (read_stats.hit_cache) {
-        statis->num_io_hit_cache++;
+        statis->num_local_io_total++;
+        statis->bytes_read_from_local += read_stats.bytes_read;
+    } else {
+        statis->num_remote_io_total++;
+        statis->bytes_read_from_remote += read_stats.bytes_read;
     }
-    statis->num_io_bytes_read_from_file_cache += read_stats.bytes_read_from_file_cache;
-    statis->num_io_written_in_file_cache += read_stats.write_in_file_cache;
-    statis->num_io_bytes_skip_cache += read_stats.bytes_skip_cache;
+    statis->remote_io_timer += read_stats.remote_read_timer;
+    statis->local_io_timer += read_stats.local_read_timer;
+    statis->num_skip_cache_io_total += read_stats.skip_cache ? 1 : 0;
+    statis->bytes_write_into_cache += read_stats.bytes_write_into_file_cache;
+    statis->write_cache_io_timer += read_stats.local_write_timer;
 }
 
 } // namespace io
diff --git a/be/src/io/cache/block/cached_remote_file_reader.h b/be/src/io/cache/block/cached_remote_file_reader.h
index 179a61a066..95fe00e936 100644
--- a/be/src/io/cache/block/cached_remote_file_reader.h
+++ b/be/src/io/cache/block/cached_remote_file_reader.h
@@ -58,15 +58,16 @@ private:
     CloudFileCachePtr _disposable_cache;
 
     struct ReadStatistics {
-        bool hit_cache = false;
+        bool hit_cache = true;
+        bool skip_cache = false;
         int64_t bytes_read = 0;
-        int64_t bytes_read_from_file_cache = 0;
-        int64_t bytes_write_in_file_cache = 0;
-        int64_t write_in_file_cache = 0;
-        int64_t bytes_skip_cache = 0;
+        int64_t bytes_write_into_file_cache = 0;
+        int64_t remote_read_timer = 0;
+        int64_t local_read_timer = 0;
+        int64_t local_write_timer = 0;
     };
     void _update_state(const ReadStatistics& stats, FileCacheStatistics* state) const;
 };
 
 } // namespace io
-} // namespace doris
+} // namespace doris
\ No newline at end of file
diff --git a/be/src/io/io_common.h b/be/src/io/io_common.h
index 3e5bce3fc0..39a059b7cb 100644
--- a/be/src/io/io_common.h
+++ b/be/src/io/io_common.h
@@ -34,14 +34,15 @@ enum ReaderType {
 namespace io {
 
 struct FileCacheStatistics {
-    int64_t num_io_total = 0;
-    int64_t num_io_hit_cache = 0;
-    int64_t num_io_bytes_read_total = 0;
-    int64_t num_io_bytes_read_from_file_cache = 0;
-    int64_t num_io_bytes_read_from_write_cache = 0;
-    int64_t num_io_written_in_file_cache = 0;
-    int64_t num_io_bytes_written_in_file_cache = 0;
-    int64_t num_io_bytes_skip_cache = 0;
+    int64_t num_local_io_total = 0;
+    int64_t num_remote_io_total = 0;
+    int64_t local_io_timer = 0;
+    int64_t bytes_read_from_local = 0;
+    int64_t bytes_read_from_remote = 0;
+    int64_t remote_io_timer = 0;
+    int64_t write_cache_io_timer = 0;
+    int64_t bytes_write_into_cache = 0;
+    int64_t num_skip_cache_io_total = 0;
 };
 
 class IOContext {
diff --git a/be/src/vec/exec/scan/new_olap_scanner.cpp b/be/src/vec/exec/scan/new_olap_scanner.cpp
index 60e1aa277e..503b416a06 100644
--- a/be/src/vec/exec/scan/new_olap_scanner.cpp
+++ b/be/src/vec/exec/scan/new_olap_scanner.cpp
@@ -17,6 +17,7 @@
 
 #include "vec/exec/scan/new_olap_scanner.h"
 
+#include "io/cache/block/block_file_cache_profile.h"
 #include "olap/storage_engine.h"
 #include "vec/exec/scan/new_olap_scan_node.h"
 #include "vec/olap/block_reader.h"
@@ -541,6 +542,11 @@ void NewOlapScanner::_update_counters_before_close() {
     COUNTER_UPDATE(olap_parent->_inverted_index_searcher_search_timer,
                    stats.inverted_index_searcher_search_timer);
 
+    if (config::enable_file_cache) {
+        io::FileCacheProfileReporter cache_profile(olap_parent->_segment_profile.get());
+        cache_profile.update(&stats.file_cache_stats);
+    }
+
     COUNTER_UPDATE(olap_parent->_output_index_result_column_timer,
                    stats.output_index_result_column_timer);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org