MCPcopy Create free account
hub / github.com/Tencent/phxqueue / CheckMem

Method CheckMem

phxqueue/consumer/consumer.cpp:950–992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

948}
949
950void Consumer::CheckMem(const int vpid) {
951 comm::RetCode ret;
952
953 shared_ptr<const config::TopicConfig> topic_config;
954 if (comm::RetCode::RET_OK != (ret = config::GlobalConfig::GetThreadInstance()->GetTopicConfigByTopicID(impl_->topic_id, topic_config))) {
955 QLErr("GetTopicConfigByTopicID ret %d topic_id %d", comm::as_integer(ret), impl_->topic_id);
956 return;
957 }
958
959 auto mem_size_limit = topic_config->GetProto().topic().consumer_max_mem_size_mb_per_proc();
960 if (!mem_size_limit) return;
961
962 static time_t last_check_time = 0;
963 auto now = time(NULL);
964 if (last_check_time + 60 < now) {
965 last_check_time = now;
966
967 comm::ConsumerBP::GetThreadInstance()->OnMemCheck(impl_->topic_id);
968
969 comm::utils::MemStat mem_stat;
970 if (!mem_stat.Stat()) return;
971
972 if (mem_stat.resident > mem_stat.share) {
973 auto mem_size = (mem_stat.resident - mem_stat.share) / 256;
974 QLInfo("mem_size %d mem_size_limit %d", mem_size, mem_size_limit);
975 uint32_t fixed_limit = mem_size_limit + mem_size_limit / 100.0 * (vpid % 20);
976 if (mem_size > fixed_limit) {
977 comm::ConsumerBP::GetThreadInstance()->OnMemCheckUnpass(impl_->topic_id);
978
979 QLErr("ERR: memory size %u > %u MB, kill it, res %lu, share %lu, size %lu, mem_size_limit %u",
980 mem_size,
981 fixed_limit,
982 mem_stat.resident,
983 mem_stat.share,
984 mem_stat.size,
985 mem_size_limit);
986 exit(-1);
987 }
988 }
989
990 comm::ConsumerBP::GetThreadInstance()->OnMemCheckPass(impl_->topic_id);
991 }
992}
993
994void Consumer::CustomGetRequest(const comm::proto::ConsumerContext &cc,
995 const comm::proto::GetRequest &req,

Callers

nothing calls this directly

Calls 6

as_integerFunction · 0.85
OnMemCheckMethod · 0.80
OnMemCheckUnpassMethod · 0.80
OnMemCheckPassMethod · 0.80
StatMethod · 0.45

Tested by

no test coverage detected