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

Method NextIntervalSleepMs

phxqueue/comm/utils/time_util.cpp:122–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122int PoissonDistribution :: NextIntervalSleepMs()
123{
124 int already_sleep_ms = 0;
125 int need_sleep_ms = GetNextIntervalTimeMs();
126 int all_sleep_ms = 0;
127
128 while(need_sleep_ms > 0) {
129 int need_sleep_ms_this_round = need_sleep_ms > 1000 ? 1000 : need_sleep_ms;
130 need_sleep_ms -= need_sleep_ms_this_round;
131 already_sleep_ms += need_sleep_ms_this_round;
132
133 all_sleep_ms += need_sleep_ms_this_round;
134
135 //分段sleep,在base改变的时候及时做出响应
136 MsSleep(need_sleep_ms_this_round);
137
138 if (impl_->base_interval_time_change)
139 {
140 int new_next_interval_time_ms = GetNextIntervalTimeMs();
141 if (new_next_interval_time_ms == 0)
142 {
143 return all_sleep_ms;
144 }
145
146 need_sleep_ms = new_next_interval_time_ms > already_sleep_ms ?
147 new_next_interval_time_ms - already_sleep_ms : 0;
148
149 if (need_sleep_ms == 0)
150 {
151 //如果最新设置的base太小,会导致集体退出sleep从而导致泄洪效应
152 //这时候立即开始一次新的interval
153 already_sleep_ms = 0;
154 need_sleep_ms = GetNextIntervalTimeMs();
155 }
156 }
157 }
158
159 return all_sleep_ms;
160}
161
162void PoissonDistribution :: SetMaxIntervalTimeMs(const int max_interval_time_ms)
163{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected