some tweaks to cart
Build and Publish / BuildAndDeployArm64 (push) Failing after 5s
Build and Publish / BuildAndDeployAmd64 (push) Failing after 4s

This commit is contained in:
2026-06-29 20:08:21 +02:00
parent de47ef4f14
commit 98e2fd8d41
7 changed files with 932 additions and 56 deletions
+24 -13
View File
@@ -9,6 +9,7 @@ import (
"io"
"log"
"net/http"
"sync"
"time"
"git.k6n.net/mats/go-cart-actor/pkg/actor"
@@ -27,7 +28,6 @@ type RemoteHost[V any] struct {
host string
httpBase string
conn *grpc.ClientConn
transport *http.Transport
client *http.Client
controlClient messages.ControlPlaneClient
missedPings int
@@ -38,8 +38,27 @@ const name = "proxy"
var (
tracer = otel.Tracer(name)
meter = otel.Meter(name)
// One process-wide HTTP transport pools idle connections to every peer.
// Per-host RemoteHost instances previously each owned a transport with
// MaxIdleConnsPerHost=100, multiplying file handles by replica count.
sharedTransport *http.Transport
sharedTransportOnce sync.Once
)
func sharedHTTPTransport() *http.Transport {
sharedTransportOnce.Do(func() {
sharedTransport = &http.Transport{
MaxIdleConns: 64,
MaxIdleConnsPerHost: 8,
MaxConnsPerHost: 32,
DisableKeepAlives: false,
IdleConnTimeout: 90 * time.Second,
}
})
return sharedTransport
}
// MockResponseWriter implements http.ResponseWriter to capture responses for proxy calls.
type MockResponseWriter struct {
StatusCode int
@@ -88,23 +107,13 @@ func NewRemoteHost[V any](host string, httpPort ...string) (*RemoteHost[V], erro
controlClient := messages.NewControlPlaneClient(conn)
transport := &http.Transport{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 100,
// Bound concurrently-open connections to this peer so a load spike
// can't exhaust file handles. Excess requests wait for a free conn
// rather than opening unbounded sockets.
MaxConnsPerHost: 256,
DisableKeepAlives: false,
IdleConnTimeout: 120 * time.Second,
}
transport := sharedHTTPTransport()
client := &http.Client{Transport: transport, Timeout: 10 * time.Second}
return &RemoteHost[V]{
host: host,
httpBase: fmt.Sprintf("http://%s:%s", host, port),
conn: conn,
transport: transport,
client: client,
controlClient: controlClient,
missedPings: 0,
@@ -136,7 +145,9 @@ func (h *RemoteHost[V]) Name() string {
func (h *RemoteHost[V]) Close() error {
if h.conn != nil {
h.conn.Close()
err := h.conn.Close()
h.conn = nil
return err
}
return nil
}