T
T
twintwin10032016-01-15 14:47:50
MySQL
twintwin1003, 2016-01-15 14:47:50

Golang mysql: Invalid Connection?

There is a web application that works with the database through this driver https://github.com/go-sql-driver/mysql
Everything works OK, but as soon as I submit load testing to several threads (10+) with more than 2 open database connections (DB.SetMaxOpenConns https://golang.org/pkg/database/sql/#DB.SetMaxOpen... , then errors start to fall

statement.go:24: Invalid Connection

Has anyone experienced this and what are the options? Really application cannot sustain more than 2 connections with a DB - I do not trust.
mysql> show variables like "max_connections";
Issues 151

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Shevelev, 2016-01-16
@twintwin1003

Tracing the chain through the documentation
1. https://github.com/go-sql-driver/mysql is used in conjunction with the standard https://golang.org/pkg/database/sql/
2. found in https://golang.org /pkg/database/sql/ function
3. we see that the result is *Rows, we find this structure and by studying we find the function
4. we see exactly the same function in Stmt
5. we conclude that it is necessary to close connections, in certain cases, forcibly
A similar question was on toster.ru already twice.
Here you can read a discussion about the features of working with MySQL in Golang: https://toster.ru/answer?answer_id=685014#comments...
Useful links for those who want to understand the issue:
4gophers.ru/article/go- i-sql-bazy-dannyh
go-database-sql.org/surprises.html

W
wol_fi, 2016-01-15
@wol_fi

Has anyone experienced this and what are the options?

Look at the server configs for the number of maximum active connections\streams\etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question