lets try sonnet
This commit is contained in:
@@ -318,9 +318,14 @@ func (sp *SecondaryProbe) runProbe() {
|
|||||||
backendMin := time.Hour // Start with large value
|
backendMin := time.Hour // Start with large value
|
||||||
|
|
||||||
for _, method := range sp.probeMethods {
|
for _, method := range sp.probeMethods {
|
||||||
|
methodMin := time.Hour // Track minimum for this method on this backend
|
||||||
|
methodSuccesses := 0
|
||||||
|
|
||||||
|
// Perform 10 probes for this method and take the minimum
|
||||||
|
for probe := 0; probe < 10; probe++ {
|
||||||
reqBody := []byte(fmt.Sprintf(
|
reqBody := []byte(fmt.Sprintf(
|
||||||
`{"jsonrpc":"2.0","method":"%s","params":[],"id":"probe-%d"}`,
|
`{"jsonrpc":"2.0","method":"%s","params":[],"id":"probe-%d-%d"}`,
|
||||||
method, time.Now().UnixNano(),
|
method, time.Now().UnixNano(), probe,
|
||||||
))
|
))
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", backend.URL, bytes.NewReader(reqBody))
|
req, err := http.NewRequest("POST", backend.URL, bytes.NewReader(reqBody))
|
||||||
@@ -329,6 +334,8 @@ func (sp *SecondaryProbe) runProbe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
// Ensure connection reuse by setting Connection: keep-alive
|
||||||
|
req.Header.Set("Connection", "keep-alive")
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
resp, err := sp.client.Do(req)
|
resp, err := sp.client.Do(req)
|
||||||
@@ -338,24 +345,44 @@ func (sp *SecondaryProbe) runProbe() {
|
|||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
if resp.StatusCode == 200 {
|
||||||
|
methodSuccesses++
|
||||||
successfulProbes++
|
successfulProbes++
|
||||||
|
|
||||||
// Update method timing (use minimum across all backends)
|
// Track minimum for this method on this backend
|
||||||
if currentMin, exists := newMethodTimings[method]; !exists || duration < currentMin {
|
if duration < methodMin {
|
||||||
newMethodTimings[method] = duration
|
methodMin = duration
|
||||||
}
|
|
||||||
|
|
||||||
// Track backend minimum
|
|
||||||
if duration < backendMin {
|
|
||||||
backendMin = duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if sp.enableDetailedLogs {
|
if sp.enableDetailedLogs {
|
||||||
log.Printf("Probe: backend=%s method=%s duration=%s status=%d",
|
log.Printf("Probe %d/10: backend=%s method=%s duration=%s status=%d (min so far: %s)",
|
||||||
backend.Name, method, duration, resp.StatusCode)
|
probe+1, backend.Name, method, duration, resp.StatusCode, methodMin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Small delay between probes to avoid overwhelming the backend
|
||||||
|
if probe < 9 { // Don't delay after the last probe
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only use this method's timing if we had successful probes
|
||||||
|
if methodSuccesses > 0 && methodMin < time.Hour {
|
||||||
|
// Update method timing (use minimum across all backends)
|
||||||
|
if currentMin, exists := newMethodTimings[method]; !exists || methodMin < currentMin {
|
||||||
|
newMethodTimings[method] = methodMin
|
||||||
|
}
|
||||||
|
|
||||||
|
// Track backend minimum
|
||||||
|
if methodMin < backendMin {
|
||||||
|
backendMin = methodMin
|
||||||
|
}
|
||||||
|
|
||||||
|
if sp.enableDetailedLogs {
|
||||||
|
log.Printf("Method %s on backend %s: %d/10 successful probes, min duration: %s",
|
||||||
|
method, backend.Name, methodSuccesses, methodMin)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store backend minimum if we got any successful probes
|
// Store backend minimum if we got any successful probes
|
||||||
@@ -1647,10 +1674,12 @@ func main() {
|
|||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: 30 * time.Second,
|
Timeout: 30 * time.Second,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
MaxIdleConns: 100,
|
MaxIdleConns: 200, // Increased for better connection pooling
|
||||||
MaxIdleConnsPerHost: 100,
|
MaxIdleConnsPerHost: 50, // Increased per-host limit for probing
|
||||||
IdleConnTimeout: 90 * time.Second,
|
IdleConnTimeout: 120 * time.Second, // Longer idle timeout for connection reuse
|
||||||
DisableCompression: true, // Typically JSON-RPC doesn't benefit from compression
|
DisableCompression: true, // Typically JSON-RPC doesn't benefit from compression
|
||||||
|
DisableKeepAlives: false, // Ensure keep-alives are enabled
|
||||||
|
MaxConnsPerHost: 50, // Limit concurrent connections per host
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user