Coder Social home page Coder Social logo

Comments (13)

methane avatar methane commented on May 26, 2024 1

Don't use defer in a loop.
Just call cancel() after PingContext returns.

from mysql.

methane avatar methane commented on May 26, 2024 1

It is unlimited by default. So increasing context timeout also increase timeout to get connection from pool.

from mysql.

methane avatar methane commented on May 26, 2024

I can't compile jpeg.
Post a runnable source code.

from mysql.

parsibox avatar parsibox commented on May 26, 2024
func mysql_check_connection() {
	logger.Info("mysql_check_connection call")
	//db.Execute("select 42")
	for {
		var errMy error
		ctx, _ := context.WithTimeout(context.Background(), 40*time.Second)
		errMy = db.PingContext(ctx)
		if errMy != nil {
			stats := db.Stats()
			fields := logrus.Fields{
				"MaxOpenConnections": stats.MaxOpenConnections,
				"OpenConnections":    stats.OpenConnections,
				"InUse":              stats.InUse,
				"Idle":               stats.Idle,
				"WaitCount":          stats.WaitCount,
				"WaitDuration":       stats.WaitDuration.String(),
				"MaxIdleClosed":      stats.MaxIdleClosed,
				"MaxLifetimeClosed":  stats.MaxLifetimeClosed,
				"err":                errMy,
			}
			logger.ErrorWithFields(fields, "ConMysql error on mysql_check_connection Err : ")
			Heartbeat = false
			//fmt.Println(" Heartbeat change to false :", Heartbeat)
			/**/
			mutex.Lock()
			db.Close()
			start()
			mutex.Unlock()

			//go start()
			return

		}
		Heartbeat = true
		time.Sleep(3 * time.Second)
	}
}

from mysql.

parsibox avatar parsibox commented on May 26, 2024

how can increase total time blocked waiting for a new connection?

from mysql.

methane avatar methane commented on May 26, 2024

Oh! You don't call cancel func.
You are leaking many contexts.

from mysql.

parsibox avatar parsibox commented on May 26, 2024

do you mean this change?

		ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
		defer cancel() // Call cancel function to release resources when the function returns

from mysql.

parsibox avatar parsibox commented on May 26, 2024

i change it

		ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
		errMy = db.PingContext(ctx)
		cancel()

how can increase total time blocked waiting for a new connection?

from mysql.

methane avatar methane commented on May 26, 2024

I cannot understand what you mean.
If you want to be blocked long time, set max open connection to 1 and query "SELECT SLEEP(100)" from 100 goroutines.
99 goroutines need to wait 100 sec.
98 goroutines need to wait another 100 sec.
...

from mysql.

parsibox avatar parsibox commented on May 26, 2024

no please see this db stat

{
    "Idle": 0,
    "InUse": 15,
    "MaxIdleClosed": 0,
    "MaxLifetimeClosed": 57,
    "MaxOpenConnections": 15,
    "OpenConnections": 15,
    "WaitCount": 141,
    "WaitDuration": "2m39.604195004s",
}

my MaxOpenConnections was equaled to OpenConnections and WaitDuration is 2m39
how can i increase WaitDuration to 10 m ?

from mysql.

methane avatar methane commented on May 26, 2024

Maybe, you misunderstand it.
Wait duration in db stat is what I said.
Total time for waiting connection from pool.

from mysql.

parsibox avatar parsibox commented on May 26, 2024

ok but is there any time limit for waiting connection from pool?

from mysql.

methane avatar methane commented on May 26, 2024

Anyway, here is issue tracker, not user forum.

from mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.