You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by li...@apache.org on 2026/04/24 07:51:28 UTC

(doris) branch master updated: [improve](profile) Skip _init_profile in load_v1 when enable_profile is false (#61131)

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

liaoxin01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new f3a591ba003 [improve](profile) Skip _init_profile in load_v1 when enable_profile is false (#61131)
f3a591ba003 is described below

commit f3a591ba00361beecb92208799a4044302017208
Author: 黄瑞鑫 <11...@users.noreply.github.com>
AuthorDate: Fri Apr 24 15:51:20 2026 +0800

    [improve](profile) Skip _init_profile in load_v1 when enable_profile is false (#61131)
    
    Skip _init_profile() in the load v1 path when enable_profile is false to
    reduce overhead.
---
 be/src/cloud/cloud_tablets_channel.cpp    |  4 +++-
 be/src/load/channel/load_channel.cpp      | 19 ++++++++++++++-----
 be/src/load/channel/tablets_channel.cpp   | 10 ++++++++--
 be/src/load/delta_writer/delta_writer.cpp |  6 +++++-
 be/src/load/memtable/memtable_writer.cpp  |  3 +++
 be/src/storage/rowset_builder.cpp         |  6 +++++-
 6 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/be/src/cloud/cloud_tablets_channel.cpp b/be/src/cloud/cloud_tablets_channel.cpp
index 4d114b677c2..590677a38d7 100644
--- a/be/src/cloud/cloud_tablets_channel.cpp
+++ b/be/src/cloud/cloud_tablets_channel.cpp
@@ -45,7 +45,9 @@ Status CloudTabletsChannel::add_batch(const PTabletWriterAddBlockRequest& reques
     // FIXME(plat1ko): Too many duplicate code with `TabletsChannel`
     SCOPED_TIMER(_add_batch_timer);
     int64_t cur_seq = 0;
-    _add_batch_number_counter->update(1);
+    if (_add_batch_number_counter != nullptr) {
+        _add_batch_number_counter->update(1);
+    }
 
     auto status = _get_current_seq(cur_seq, request);
     if (UNLIKELY(!status.ok())) {
diff --git a/be/src/load/channel/load_channel.cpp b/be/src/load/channel/load_channel.cpp
index a0d63d3ba86..9ec0de1943e 100644
--- a/be/src/load/channel/load_channel.cpp
+++ b/be/src/load/channel/load_channel.cpp
@@ -72,7 +72,9 @@ LoadChannel::LoadChannel(const UniqueId& load_id, int64_t timeout_s, bool is_hig
     // _load_channels in load_channel_mgr, or it may be erased
     // immediately by gc thread.
     _last_updated_time.store(time(nullptr));
-    _init_profile();
+    if (enable_profile) {
+        _init_profile();
+    }
 }
 
 LoadChannel::~LoadChannel() {
@@ -88,6 +90,7 @@ LoadChannel::~LoadChannel() {
 }
 
 void LoadChannel::_init_profile() {
+    DCHECK(_enable_profile);
     _profile = std::make_unique<RuntimeProfile>("LoadChannels");
     _mgr_add_batch_timer = ADD_TIMER(_profile, "LoadChannelMgrAddBatchTime");
     _handle_mem_limit_timer = ADD_TIMER(_profile, "HandleMemLimitTime");
@@ -179,7 +182,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
     DBUG_EXECUTE_IF("LoadChannel.add_batch.failed",
                     { return Status::InternalError("fault injection"); });
     SCOPED_TIMER(_add_batch_timer);
-    COUNTER_UPDATE(_add_batch_times, 1);
+    if (_enable_profile) {
+        COUNTER_UPDATE(_add_batch_times, 1);
+    }
     SCOPED_ATTACH_TASK(_resource_ctx);
     int64_t index_id = request.index_id();
     // 1. get tablets channel
@@ -193,7 +198,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
     // 2. add block to tablets channel
     if (request.has_block()) {
         RETURN_IF_ERROR(channel->add_batch(request, response));
-        _add_batch_number_counter->update(1);
+        if (_enable_profile) {
+            _add_batch_number_counter->update(1);
+        }
     }
 
     // 3. handle eos
@@ -204,7 +211,7 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
         if (!st.ok()) {
             return st;
         }
-    } else if (_add_batch_number_counter->value() % 100 == 1) {
+    } else if (_enable_profile && _add_batch_number_counter->value() % 100 == 1) {
         _report_profile(response);
     }
     _last_updated_time.store(time(nullptr));
@@ -214,7 +221,9 @@ Status LoadChannel::add_batch(const PTabletWriterAddBlockRequest& request,
 Status LoadChannel::_handle_eos(BaseTabletsChannel* channel,
                                 const PTabletWriterAddBlockRequest& request,
                                 PTabletWriterAddBlockResult* response) {
-    _self_profile->add_info_string("EosHost", fmt::format("{}", request.backend_id()));
+    if (_enable_profile) {
+        _self_profile->add_info_string("EosHost", fmt::format("{}", request.backend_id()));
+    }
     bool finished = false;
     auto index_id = request.index_id();
 
diff --git a/be/src/load/channel/tablets_channel.cpp b/be/src/load/channel/tablets_channel.cpp
index b372828b951..12d535e9e08 100644
--- a/be/src/load/channel/tablets_channel.cpp
+++ b/be/src/load/channel/tablets_channel.cpp
@@ -66,7 +66,9 @@ BaseTabletsChannel::BaseTabletsChannel(const TabletsChannelKey& key, const Uniqu
           _closed_senders(64),
           _is_high_priority(is_high_priority) {
     static std::once_flag once_flag;
-    _init_profile(profile);
+    if (profile != nullptr) {
+        _init_profile(profile);
+    }
     std::call_once(once_flag, [] {
         REGISTER_HOOK_METRIC(tablet_writer_count, [&]() { return _s_tablet_writer_count.load(); });
     });
@@ -102,6 +104,7 @@ Status BaseTabletsChannel::_get_current_seq(int64_t& cur_seq,
 }
 
 void BaseTabletsChannel::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     _profile =
             profile->create_child(fmt::format("TabletsChannel {}", _key.to_string()), true, true);
     _add_batch_number_counter = ADD_COUNTER(_profile, "NumberBatchAdded", TUnit::UNIT);
@@ -122,6 +125,7 @@ void BaseTabletsChannel::_init_profile(RuntimeProfile* profile) {
 }
 
 void TabletsChannel::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     BaseTabletsChannel::_init_profile(profile);
     _slave_replica_timer = ADD_TIMER(_profile, "SlaveReplicaTime");
 }
@@ -637,7 +641,9 @@ Status TabletsChannel::add_batch(const PTabletWriterAddBlockRequest& request,
                                  PTabletWriterAddBlockResult* response) {
     SCOPED_TIMER(_add_batch_timer);
     int64_t cur_seq = 0;
-    _add_batch_number_counter->update(1);
+    if (_add_batch_number_counter) {
+        _add_batch_number_counter->update(1);
+    }
 
     auto status = _get_current_seq(cur_seq, request);
     if (UNLIKELY(!status.ok())) {
diff --git a/be/src/load/delta_writer/delta_writer.cpp b/be/src/load/delta_writer/delta_writer.cpp
index a2ccbe7745b..33d3c3065ff 100644
--- a/be/src/load/delta_writer/delta_writer.cpp
+++ b/be/src/load/delta_writer/delta_writer.cpp
@@ -62,7 +62,9 @@ using namespace ErrorCode;
 BaseDeltaWriter::BaseDeltaWriter(const WriteRequest& req, RuntimeProfile* profile,
                                  const UniqueId& load_id)
         : _req(req), _memtable_writer(new MemTableWriter(req)) {
-    _init_profile(profile);
+    if (profile != nullptr) {
+        _init_profile(profile);
+    }
 }
 
 DeltaWriter::DeltaWriter(StorageEngine& engine, const WriteRequest& req, RuntimeProfile* profile,
@@ -72,12 +74,14 @@ DeltaWriter::DeltaWriter(StorageEngine& engine, const WriteRequest& req, Runtime
 }
 
 void BaseDeltaWriter::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     _profile = profile->create_child(fmt::format("DeltaWriter {}", _req.tablet_id), true, true);
     _close_wait_timer = ADD_TIMER(_profile, "CloseWaitTime");
     _wait_flush_limit_timer = ADD_TIMER(_profile, "WaitFlushLimitTime");
 }
 
 void DeltaWriter::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     BaseDeltaWriter::_init_profile(profile);
     _commit_txn_timer = ADD_TIMER(_profile, "CommitTxnTime");
 }
diff --git a/be/src/load/memtable/memtable_writer.cpp b/be/src/load/memtable/memtable_writer.cpp
index 5812a016a51..3179939a1d6 100644
--- a/be/src/load/memtable/memtable_writer.cpp
+++ b/be/src/load/memtable/memtable_writer.cpp
@@ -289,6 +289,9 @@ Status MemTableWriter::_do_close_wait() {
 }
 
 void MemTableWriter::_update_profile(RuntimeProfile* profile) {
+    if (!profile) {
+        return;
+    }
     // NOTE: MemTableWriter may be accessed when profile is out of scope, in MemTableMemoryLimiter.
     // To avoid accessing dangling pointers, we cannot make profile as a member of MemTableWriter.
     auto child =
diff --git a/be/src/storage/rowset_builder.cpp b/be/src/storage/rowset_builder.cpp
index aafdb426f98..91a888e4cbb 100644
--- a/be/src/storage/rowset_builder.cpp
+++ b/be/src/storage/rowset_builder.cpp
@@ -64,7 +64,9 @@ using namespace ErrorCode;
 
 BaseRowsetBuilder::BaseRowsetBuilder(const WriteRequest& req, RuntimeProfile* profile)
         : _req(req), _tablet_schema(std::make_shared<TabletSchema>()) {
-    _init_profile(profile);
+    if (profile != nullptr) {
+        _init_profile(profile);
+    }
 }
 
 RowsetBuilder::RowsetBuilder(StorageEngine& engine, const WriteRequest& req,
@@ -72,6 +74,7 @@ RowsetBuilder::RowsetBuilder(StorageEngine& engine, const WriteRequest& req,
         : BaseRowsetBuilder(req, profile), _engine(engine) {}
 
 void BaseRowsetBuilder::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     _profile = profile->create_child(fmt::format("RowsetBuilder {}", _req.tablet_id), true, true);
     _build_rowset_timer = ADD_TIMER(_profile, "BuildRowsetTime");
     _submit_delete_bitmap_timer = ADD_TIMER(_profile, "DeleteBitmapSubmitTime");
@@ -79,6 +82,7 @@ void BaseRowsetBuilder::_init_profile(RuntimeProfile* profile) {
 }
 
 void RowsetBuilder::_init_profile(RuntimeProfile* profile) {
+    DCHECK(profile != nullptr);
     BaseRowsetBuilder::_init_profile(profile);
     _commit_txn_timer = ADD_TIMER(_profile, "CommitTxnTime");
 }


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