B
B
bodrich2019-09-12 19:49:31
go
bodrich, 2019-09-12 19:49:31

Does it make sense to use multiple connections to the same database to increase performance?

Will there be an option

db, err := sql.Open("mysql", "root:[email protected]/productdb")

// много потоков дергающие запросы db.Query

similar in performance to this option:
db, err := sql.Open("mysql", "root:[email protected]/productdb")
db1, err := sql.Open("mysql", "root:[email protected]/productdb")

// много потоков, половина которых дергают запросы db, вторая половина db1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Mamonov, 2019-09-12
@bodrich

No, there is already a connection pool in use.
You can specify the number of idle (IDLE) connections db.SetMaxIdleConns and the maximum number of concurrently open connections via db.SetMaxOpenConns

S
Stanislav Bodrov, 2019-09-18
@jenki

Does it make sense to use multiple connections to the same database to increase performance?
Usually the DBMS is the slowest link. Even so, in the vast majority of architectural solutions, the DBMS is the slowest link.
The second case will be not only not the most productive, but also not the safest. It goes to two different databases db and db1 . Therefore, the problem of synchronizing data between databases arises, otherwise one may begin to give some data, and the other others for the same request. Synchronizing data is not always a fast process. And until the data is synchronized, you have to wait for a response. Otherwise split brain will come out.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question