You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(hedging): support hedging in order to reduce latency when quering endpoints (#1081)
* feat(hedging): support hedging in order to reduce latency when quering endpoints
Signed-off-by: Ahmet DEMIR <me@ahmet2mir.eu>
* fix(hedging): move fields to struct, remove ratelimit, fail on sethedging func if not enabled, restore retry, allow unsafe funcs
Signed-off-by: Ahmet DEMIR <me@ahmet2mir.eu>
* fix(hedging): adapt suggestions
Signed-off-by: Ahmet DEMIR <me@ahmet2mir.eu>
---------
Signed-off-by: Ahmet DEMIR <me@ahmet2mir.eu>
// Disable retry by default when hedging is enabled.
1611
+
// Users can re-enable retry if they want it as a fallback mechanism.
1612
+
ifc.retryCount>0 {
1613
+
c.log.Warnf("Disabling retry (count: %d) as hedging is now enabled. You can re-enable retry with SetRetryCount() if you want it as a fallback.", c.retryCount)
1614
+
c.retryCount=0
1615
+
}
1616
+
1617
+
c.wrapTransportWithHedging()
1618
+
1619
+
returnc
1620
+
}
1621
+
1622
+
// DisableHedging method disables hedging.
1623
+
func (c*Client) DisableHedging() *Client {
1624
+
c.lock.Lock()
1625
+
deferc.lock.Unlock()
1626
+
1627
+
ifc.isHedgingEnabled() {
1628
+
c.hedging.enabled=false
1629
+
}
1630
+
1631
+
c.unwrapHedgingTransport()
1632
+
1633
+
returnc
1634
+
}
1635
+
1636
+
func (c*Client) wrapTransportWithHedging() {
1637
+
ifc.hedging==nil||!c.hedging.enabled {
1638
+
return
1639
+
}
1640
+
1641
+
currentTransport:=c.httpClient.Transport
1642
+
ifcurrentTransport==nil {
1643
+
currentTransport=createTransport(nil, nil)
1644
+
}
1645
+
1646
+
// Already set
1647
+
if_, ok:=currentTransport.(*hedgingTransport); ok {
1648
+
return
1649
+
}
1650
+
1651
+
// Calculate rate delay: if maxPerSecond is 10, delay is 100ms (1s / 10)
0 commit comments