In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Golang is performing database operations. Generally speaking, we use the Open function to create a database (operation) handle: func Open (driverName, dataSourceName string) (* DB, error) We know that the returned * DB is a connection pool with zero to multiple underlying connections, which can be safely used by multiple goos and maintains its own idle connections. So generally speaking, we only call the open function once, and we rarely need to turn off DB. Connection pooling allows better control of connections, so you can use it with simple configuration or even nothing to configure. This seems to be the case, even connecting to the database is ok. But! You are likely to encounter the following errors: [mysql] 12:23:43 on 2017-01-15 packets.go:124: write tcp 127.0.0.1 write tcp 45697-> 127.0.0.1:3306:write: broken pipe is probably because your connection pool is not configured properly, or the setting value is incorrect, so the reasons for timeout are probably as follows: 1. The maximum number of connections is greater than the maximum number of connections configured on the database server side, and the excess connections have a connection timeout of 2. 5% when used. Network jitter: submit or maintain a large amount of data each time you connect, when the network is unstable and the connection times out by 3. 5%. The occupied resources are not released. We usually only open once and get a * DB, but it is not turned off when using stmt,rows or tx, and running out of resources may also lead to connection timeout. For the three problems that arise, you can try the following solution: 1. For the problem of maximum number of connections, call the function Db.SetMaxOpenConns () to set the value (less than the maximum number of connections configured by the database) 2. For maintaining a large amount of data, you can try a transactional operation and, if it fails, roll back. And try again. 3. Using the defer keyword, the relevant shutdown function is executed when the defer * .close () function return is added directly to the next line when the operation is enabled. If you try the above solutions and still find that there is an occasional connection timeout error, it is probably because the database itself has a timeout setting for the connection. If the timeout is over, the database will unilaterally break the connection. At this point, it will make an error to access the connection with the connection pool, and each connection in the connection pool maintains a creation time. It will be checked automatically when getting a connection. You can try calling the SetConnMaxLifetime () method of db to set a timeout for db, which is less than the timeout of the database.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.