Commit f1b4a007 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

pool_max_conns

parent 6d4bbe0a
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()
}
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
"log" "log"
"reflect" "reflect"
"runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
...@@ -154,6 +155,10 @@ func (d *Pool) newConn(mode connMode, pgConnString string) (q *Conn, err error) ...@@ -154,6 +155,10 @@ func (d *Pool) newConn(mode connMode, pgConnString string) (q *Conn, err error)
pgConnString += " sslmode=disable" 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 { if pgxConfig, err = pgxpool.ParseConfig(pgConnString); err != nil {
return nil, err return nil, err
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment