feat: batch connection logs to avoid DB lock contention (#23727)

- Running 30k connections was generating a ton of lock contention in the
DB
This commit is contained in:
Jon Ayers
2026-04-03 15:47:26 -05:00
committed by GitHub
parent 333503f74e
commit a1d51f0dab
21 changed files with 2168 additions and 426 deletions
+10 -2
View File
@@ -5,6 +5,7 @@ import (
"crypto/ed25519"
"crypto/tls"
"fmt"
"io"
"math"
"net/http"
"net/url"
@@ -144,10 +145,11 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
}
if options.ConnectionLogger == nil {
options.ConnectionLogger = connectionlog.NewConnectionLogger(
connectionlog.NewDBBackend(options.Database),
connLogger := connectionlog.New(
connectionlog.NewDBBatcher(ctx, options.Database, options.Logger),
connectionlog.NewSlogBackend(options.Logger),
)
options.ConnectionLogger = connLogger
}
meshTLSConfig, err := replicasync.CreateDERPMeshTLSConfig(options.AccessURL.Hostname(), options.TLSCertificates)
@@ -822,6 +824,12 @@ func (api *API) Close() error {
api.Options.CheckInactiveUsersCancelFunc()
}
// Close the connection logger to flush any remaining batched
// entries before shutting down the database connection.
if cl, ok := api.Options.ConnectionLogger.(io.Closer); ok {
_ = cl.Close()
}
return api.AGPL.Close()
}