diff --git a/include/pika_client_conn.h b/include/pika_client_conn.h index 4d7a1382b6..d804a113c0 100644 --- a/include/pika_client_conn.h +++ b/include/pika_client_conn.h @@ -19,6 +19,7 @@ struct TimeStat { void Reset() { enqueue_ts_ = dequeue_ts_ = 0; process_done_ts_ = 0; + before_queue_ts_ = 0; } uint64_t start_ts() const { @@ -37,8 +38,13 @@ struct TimeStat { return process_done_ts_ > dequeue_ts_ ? process_done_ts_ - dequeue_ts_ : 0; } + uint64_t before_queue_time() const { + return process_done_ts_ > dequeue_ts_ ? before_queue_ts_ - enqueue_ts_ : 0; + } + uint64_t enqueue_ts_; uint64_t dequeue_ts_; + uint64_t before_queue_ts_; uint64_t process_done_ts_; }; diff --git a/include/pika_command.h b/include/pika_command.h index 0ad4a4f5a2..92e314a745 100644 --- a/include/pika_command.h +++ b/include/pika_command.h @@ -247,6 +247,8 @@ const std::string kCmdNameXInfo = "xinfo"; const std::string kClusterPrefix = "pkcluster"; +const std::unordered_set interceptCmds = {kCmdNameGet, kCmdNameHGet, kCmdNameHGetall}; + /* * If a type holds a key, a new data structure * that uses the key will use this error diff --git a/src/pika_client_conn.cc b/src/pika_client_conn.cc index 2ec8e1388b..27271abb85 100644 --- a/src/pika_client_conn.cc +++ b/src/pika_client_conn.cc @@ -238,6 +238,7 @@ void PikaClientConn::ProcessSlowlog(const PikaCmdArgsType& argv, uint64_t do_dur LOG(ERROR) << "ip_port: " << ip_port() << ", db: " << current_db_ << ", command:" << slow_log << ", command_size: " << cmd_size - 1 << ", arguments: " << argv.size() << ", total_time(ms): " << time_stat_->total_time() / 1000 + << ", before_queue_time(ms): " << time_stat_->before_queue_time() / 1000 << ", queue_time(ms): " << time_stat_->queue_time() / 1000 << ", process_time(ms): " << time_stat_->process_time() / 1000 << ", cmd_time(ms): " << do_duration / 1000; @@ -262,7 +263,7 @@ void PikaClientConn::ProcessRedisCmds(const std::vector& if (async) { auto arg = new BgTaskArg(); arg->redis_cmds = argvs; - time_stat_->enqueue_ts_ = pstd::NowMicros(); + time_stat_->enqueue_ts_ = time_stat_->before_queue_ts_ = pstd::NowMicros(); arg->conn_ptr = std::dynamic_pointer_cast(shared_from_this()); /** * If using the pipeline method to transmit batch commands to Pika, it is unable to @@ -277,14 +278,15 @@ void PikaClientConn::ProcessRedisCmds(const std::vector& bool read_status = false; std::shared_ptr c_ptr = g_pika_cmd_table_manager->GetCmd(opt); - if (PIKA_CACHE_NONE != g_pika_conf->cache_mode() && c_ptr && c_ptr->isCacheRead()){ - // read in cache - if (BatchReadCmdInCache(argvs)){ - delete arg; - arg = nullptr; - return; - } - } + if (PIKA_CACHE_NONE != g_pika_conf->cache_mode() && !IsInTxn() && interceptCmds.find(opt) != interceptCmds.end()){ + // read in cache + if (BatchReadCmdInCache(argvs)){ + delete arg; + arg = nullptr; + return; + } + time_stat_->before_queue_ts_ = pstd::NowMicros(); + } g_pika_server->ScheduleClientPool(&DoBackgroundTask, arg, is_slow_cmd, is_admin_cmd); return; diff --git a/src/pika_command.cc b/src/pika_command.cc index 34cea023ac..09dce5c423 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -282,7 +282,7 @@ void InitCmdTable(CmdTable* cmd_table) { cmd_table->insert(std::pair>(kCmdNameAppend, std::move(appendptr))); ////MgetCmd std::unique_ptr mgetptr = - std::make_unique(kCmdNameMget, -2, kCmdFlagsRead | kCmdFlagsKv | kCmdFlagsDoThroughDB | kCmdFlagsUpdateCache | kCmdFlagsReadCache | kCmdReadBeforeQueue | kCmdFlagsFast); + std::make_unique(kCmdNameMget, -2, kCmdFlagsRead | kCmdFlagsKv | kCmdFlagsDoThroughDB | kCmdFlagsUpdateCache | kCmdFlagsReadCache | kCmdFlagsFast); cmd_table->insert(std::pair>(kCmdNameMget, std::move(mgetptr))); ////KeysCmd std::unique_ptr keysptr = @@ -420,7 +420,7 @@ void InitCmdTable(CmdTable* cmd_table) { cmd_table->insert(std::pair>(kCmdNameHLen, std::move(hlenptr))); ////HMgetCmd std::unique_ptr hmgetptr = - std::make_unique(kCmdNameHMget, -3, kCmdFlagsRead | kCmdFlagsHash | kCmdFlagsUpdateCache | kCmdFlagsDoThroughDB | kCmdFlagsReadCache | kCmdReadBeforeQueue |kCmdFlagsFast); + std::make_unique(kCmdNameHMget, -3, kCmdFlagsRead | kCmdFlagsHash | kCmdFlagsUpdateCache | kCmdFlagsDoThroughDB | kCmdFlagsReadCache |kCmdFlagsFast); cmd_table->insert(std::pair>(kCmdNameHMget, std::move(hmgetptr))); ////HMsetCmd std::unique_ptr hmsetptr =