Skip to content

Commit 0990487

Browse files
authored
fix: Implement periodic logging of task queue size (#1978)
* fix: Implement periodic logging of task queue size
1 parent 21ea890 commit 0990487

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

include/pika_client_processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class PikaClientProcessor {
2121
void SchedulePool(net::TaskFunc func, void* arg);
2222
void ScheduleBgThreads(net::TaskFunc func, void* arg, const std::string& hash_str);
2323
size_t ThreadPoolCurQueueSize();
24+
size_t ThreadPoolMaxQueueSize();
2425

2526
private:
2627
std::unique_ptr<net::ThreadPool> pool_;

include/pika_server.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class PikaServer : public pstd::noncopyable {
240240
void ScheduleClientBgThreads(net::TaskFunc func, void* arg, const std::string& hash_str);
241241
// for info debug
242242
size_t ClientProcessorThreadPoolCurQueueSize();
243+
size_t ClientProcessorThreadPoolMaxQueueSize();
243244

244245
/*
245246
* BGSave used
@@ -518,7 +519,8 @@ class PikaServer : public pstd::noncopyable {
518519
void AutoDeleteExpiredDump();
519520
void AutoKeepAliveRSync();
520521
void AutoUpdateNetworkMetric();
521-
522+
void PrintThreadPoolQueueStatus();
523+
522524
std::string host_;
523525
int port_ = 0;
524526
time_t start_time_s_ = 0;

src/pika_client_processor.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ size_t PikaClientProcessor::ThreadPoolCurQueueSize() {
5454
}
5555
return cur_size;
5656
}
57+
58+
size_t PikaClientProcessor::ThreadPoolMaxQueueSize() {
59+
size_t cur_size = 0;
60+
if (pool_) {
61+
cur_size = pool_->max_queue_size();
62+
}
63+
return cur_size;
64+
}

src/pika_server.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern PikaServer* g_pika_server;
3434
extern std::unique_ptr<PikaReplicaManager> g_pika_rm;
3535
extern std::unique_ptr<PikaCmdTableManager> g_pika_cmd_table_manager;
3636
extern std::unique_ptr<net::NetworkStatistic> g_network_statistic;
37+
// QUEUE_SIZE_THRESHOLD_PERCENTAGE is used to represent a percentage value and should be within the range of 0 to 100.
38+
const size_t QUEUE_SIZE_THRESHOLD_PERCENTAGE = 75;
3739

3840
void DoPurgeDir(void* arg) {
3941
std::unique_ptr<std::string> path(static_cast<std::string*>(arg));
@@ -854,6 +856,13 @@ size_t PikaServer::ClientProcessorThreadPoolCurQueueSize() {
854856
return pika_client_processor_->ThreadPoolCurQueueSize();
855857
}
856858

859+
size_t PikaServer::ClientProcessorThreadPoolMaxQueueSize() {
860+
if (!pika_client_processor_) {
861+
return 0;
862+
}
863+
return pika_client_processor_->ThreadPoolMaxQueueSize();
864+
}
865+
857866
void PikaServer::BGSaveTaskSchedule(net::TaskFunc func, void* arg) {
858867
bgsave_thread_.StartThread();
859868
bgsave_thread_.Schedule(func, arg);
@@ -1298,6 +1307,8 @@ void PikaServer::DoTimingTask() {
12981307
ResetLastSecQuerynum();
12991308
// Auto update network instantaneous metric
13001309
AutoUpdateNetworkMetric();
1310+
// Print the queue status periodically
1311+
PrintThreadPoolQueueStatus();
13011312
}
13021313

13031314
void PikaServer::AutoCompactRange() {
@@ -1491,6 +1502,16 @@ void PikaServer::AutoUpdateNetworkMetric() {
14911502
current_time, factor);
14921503
}
14931504

1505+
void PikaServer::PrintThreadPoolQueueStatus() {
1506+
// Print the current queue size if it exceeds QUEUE_SIZE_THRESHOLD_PERCENTAGE/100 of the maximum queue size.
1507+
size_t cur_size = ClientProcessorThreadPoolCurQueueSize();
1508+
size_t max_size = ClientProcessorThreadPoolMaxQueueSize();
1509+
size_t thread_hold = (max_size / 100) * QUEUE_SIZE_THRESHOLD_PERCENTAGE;
1510+
if (cur_size > thread_hold) {
1511+
LOG(INFO) << "The current queue size of the Pika Server's client thread processor thread pool: " << cur_size;
1512+
}
1513+
}
1514+
14941515
void PikaServer::InitStorageOptions() {
14951516
std::lock_guard rwl(storage_options_rw_);
14961517

0 commit comments

Comments
 (0)