What is connection pool and why do we need it?

When your application needs to access your database several times.
It is easy to open a connection for each request


But it is not a performance application, to enhance the performance we need to care for POOL definition. I mean connection pool in database

//Golang code

psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
   "password=%s dbname=%s sslmode=disable",
   host, port, user, password, dbname)

db, err := sqlx.Open("postgres", psqlInfo)

if err != nil {
   panic(err)
}

//set connection pool with maximum is 30
db.SetMaxOpenConns(30)
//always available at least 5 connections for using 
db.SetMaxIdleConns(5)
//
db.SetConnMaxLifetime(time.Minute)



















Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch