Cache and maximum number of connections for database access

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Check out the error log I wrote today and report the Too many connections error. Have not seen ah, decisive to ask my eldest brother, he said is the problem of the number of connections. I went to see my code before it was online, only to remember that the database connection needs to set the maximum number of connections. This error is reported when the number of connections exceeds the range.

I'm using Xorm as an ORM tool, engine.SetMaxConns(dbMaxConns) you can set the maximum number of connections directly.

Later, the cache was optimized. The general ORM also supports caching mechanisms. If the cache hits, it will not go to the database to find the data, but will return directly. Adding a cache requires increasing the cache time and the maximum number of caches.

cacher := xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Duration(interval)*time.Second, max)engine.SetDefaultCacher(cacher)

Very simple question, but always forget to add. Today, with a wrk simple stress test on the project, this is the problem. I've always felt that stress tests are used to measure performance, and today we have a new understanding.

Original link: Database access to the cache and the maximum number of connections, reproduced please indicate the source!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.