diff --git a/zatomic/uint64.go b/zatomic/uint64.go new file mode 100644 index 0000000000000000000000000000000000000000..dbfe811f70eb2fd62dfe0d37b653a1ab51f7e52e --- /dev/null +++ b/zatomic/uint64.go @@ -0,0 +1,31 @@ +package zatomic + +import "sync/atomic" + +type UInt64 struct { + v *atomic.Uint64 +} + +func NewUInt64() *UInt64 { + return &UInt64{v: &atomic.Uint64{}} +} + +func (i *UInt64) Store(v int) { + i.v.Store(uint64(v)) +} + +func (i *UInt64) Add(delta int) uint64 { + return i.v.Add(uint64(delta)) +} + +func (i *UInt64) Inc() uint64 { + return i.Add(1) +} + +func (i *UInt64) Dec() uint64 { + return i.Add(-1) +} + +func (i *UInt64) Load() uint64 { + return i.v.Load() +} diff --git a/zdb/pool.go b/zdb/pool.go index 5b3b65db499d332bfbf33ad7fba5d6520f87d789..596c9a42e832213719e09aaec9a2563de6f005a6 100644 --- a/zdb/pool.go +++ b/zdb/pool.go @@ -6,6 +6,7 @@ import ( "github.com/jackc/pgx/v5/pgxpool" "log" "reflect" + "runtime" "strconv" "strings" "sync" @@ -154,6 +155,10 @@ func (d *Pool) newConn(mode connMode, pgConnString string) (q *Conn, err error) pgConnString += " sslmode=disable" } + if !strings.Contains(pgConnString, "pool_max_conns=") { + pgConnString += fmt.Sprintf(" pool_max_conns=%d", runtime.NumCPU()*2) + } + if pgxConfig, err = pgxpool.ParseConfig(pgConnString); err != nil { return nil, err }