mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-22 12:42:25 +00:00
* feat(db): background_state table and the (hop_count, iata) route index * perf(db): one /routes statement per filter shape, hop pair on custom plans * feat(db): keyset route retention and grace slices at exact cutoffs * feat(background): hourly route retention with a bounded grace walk and watermark * fix(background): bound the grace walk at microsecond cutoffs * feat(db): stamp-free reconfirm sweep over the route primary key * feat(background): pace route reconfirm at routes.reconfirm_rows_per_hour, no stamps * test(routes): drive route retention end to end and tidy comments * fix(profiling): sample during the hourly route retention run
32 lines
957 B
Go
32 lines
957 B
Go
// Copyright 2026 Beacon Contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
"os"
|
|
|
|
"github.com/MeshCore-Beacon/beacon-server/internal/profiling"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
func configureProfiling(ctx context.Context, pool *pgxpool.Pool) *profiling.Recorder {
|
|
r, err := profiling.Start(ctx, os.Getenv("BEACON_CPU_PROFILE_DIR"), os.Getenv("BEACON_CPU_PROFILE_UNTIL"), []string{"route_retention"}, func() any {
|
|
s := pool.Stat()
|
|
return struct {
|
|
Acquired, Idle, Total, Max int32
|
|
Acquires, EmptyAcquires, CanceledAcquires int64
|
|
AcquireDurationNS int64
|
|
}{
|
|
s.AcquiredConns(), s.IdleConns(), s.TotalConns(), s.MaxConns(),
|
|
s.AcquireCount(), s.EmptyAcquireCount(), s.CanceledAcquireCount(), int64(s.AcquireDuration()),
|
|
}
|
|
})
|
|
if err != nil {
|
|
slog.Warn("CPU profiling unavailable", "component", "profiling", "error", err)
|
|
}
|
|
return r
|
|
}
|