Copilot commented on code in PR #3526:
URL: https://github.com/apache/brpc/pull/3526#discussion_r3952290721
##########
docs/cn/client.md:
##########
@@ -290,6 +290,14 @@ locality-aware,优先选择延时低的下游,直到其延时高于其他机
channel.Init("http://...", "random:min_working_instances=6 hold_seconds=10",
&options);
```
+### 慢启动(预热)
+
+新加入集群或刚重启的server往往是“冷”的(缓存未命中、JIT未编译、连接池未建立),立即承担全量流量会推高其延时甚至过载。设置-lb_warmup_ms大于0(默认为0,即关闭)后,新加入负载均衡器的server先获得一小部分正常流量份额(-lb_warmup_min_weight,默认0.1),并在该时间窗口内线性爬升到100%。该机制对rr、wrr、random、la、p2c和一致性哈希均生效:la和p2c把爬升系数乘入权重,与延时评分自然叠加而不会互相干扰;其余算法按该系数概率性地把请求转给其他server(一致性哈希转给环上的下一个节点,预热期间会有部分请求偏离原有的哈希亲和性)。
Review Comment:
这里写“线性爬升到100%”与下一段 -lb_warmup_curve 可配置曲线的描述不一致(曲线 != 1
时并非线性)。建议去掉“线性”或改成更泛化的表述。
##########
src/brpc/load_balancer.h:
##########
@@ -113,6 +113,31 @@ class LoadBalancer : public NonConstDescribable, public
Destroyable {
DECLARE_bool(show_lb_in_vars);
DECLARE_int32(default_weight_of_wlb);
+DECLARE_int64(lb_warmup_ms);
+
+double WarmupMultiplierImpl(int64_t join_time_us, int64_t now_us);
+bool WarmupAcceptImpl(int64_t join_time_us, int64_t now_us);
+
+// Slow start: while -lb_warmup_ms is positive, a server newly added to a
+// LoadBalancer serves a ramping fraction of its normal traffic share, from
+// about 10% right after joining to 100% at the end of the window. The ramp
+// restarts when a removed server is added back(naming service flap); a
+// transiently disconnected server does not change LB membership and keeps
+// its ramp. Servers added together(e.g. at channel init) ramp together and
+// keep their relative shares.
+// Returns the weight multiplier in (0, 1] for a server that joined the
+// LoadBalancer at `join_time_us'(gettimeofday_us). `now_us' <= 0 makes the
+// function read the clock itself.
+inline double WarmupMultiplier(int64_t join_time_us, int64_t now_us) {
+ return FLAGS_lb_warmup_ms <= 0 ?
+ 1.0 : WarmupMultiplierImpl(join_time_us, now_us);
+}
+
+// Probabilistic form of WarmupMultiplier for policies without changable
+// weights: returns true with probability WarmupMultiplier(...).
Review Comment:
Typo in the comment: “changable” should be “changeable”.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]