Add lab 3 scaling research and database bottleneck evidence
This commit is contained in:
@@ -45,6 +45,11 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
defer pool.Close()
|
||||
if os.Getenv("PG_POOL_DIAGNOSTICS") == "1" {
|
||||
diagnosticsCtx, stopDiagnostics := context.WithCancel(context.Background())
|
||||
defer stopDiagnostics()
|
||||
go logPoolStats(diagnosticsCtx, pool)
|
||||
}
|
||||
|
||||
queries := sqlc.New(pool)
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// logPoolStats is opt-in diagnostics for the isolated scaling experiment.
|
||||
// It contains only aggregate counters, never connection strings or SQL values.
|
||||
func logPoolStats(ctx context.Context, pool *pgxpool.Pool) {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
s := pool.Stat()
|
||||
slog.Info("pg_pool_stats", "max_conns", s.MaxConns(),
|
||||
"acquired", s.AcquiredConns(), "idle", s.IdleConns(),
|
||||
"acquire_count", s.AcquireCount(), "empty_count", s.EmptyAcquireCount(),
|
||||
"empty_wait_ns", s.EmptyAcquireWaitTime().Nanoseconds(),
|
||||
"canceled_count", s.CanceledAcquireCount())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user