Nâng bao nhiêu pool connect database là phù hợp

1. Max_connection database hiện tại là bao nhiêu?

Giả sử ta sử dụng Database MySQL AWS thuộc dòng db.t2.large (2CPU – 8GB RAM). Để biết số lượng max_connection có 2 cách:

  • Cách 1: Thực hiện truy vấn SHOW GLOBAL VARIABLES LIKE 'max_connections';
  • Cách 2: Dùng công thức max_connections = DBInstanceClassMemory/12582880
    • Ram 8G ⇒ 8000000000 bytes / 12582880 = 635 pools

2. Nâng bao nhiêu pool là hợp lý?

Giả sử ta có 3 con servers. Mỗi server chạy 4 workers. Mỗi worker chạy 16 threads.

Mỗi thread là 1 connection đến database.

Suy ra ta có tổng số threads trên 1 server ⇒ 16 threads * 4 workers = 64 pools/server

Ta có 3 servers ⇒ 64 pools * 3 servers = 192 pools ⇒ Số pool tổng cộng là 192 pools

Cho nên chỉ số max_connection > tổng số pools

Với database ở trên thì sẽ đáp ứng được. Nếu DB của bạn yếu thì các bạn cần phải điều chỉnh lại số lượng threads cho phù hợp. Miễn sao khi tổng các server lại nó phải bé hơn số max_connection

Lưu ý: Đó là ta mới tính cho những server đang golive, ngoài ra còn có những server khác như background chẳng hạn, hoặc khi ứng dụng được Scale-up server thì củng phải được tính vào. Tốt nhất là ta nên chừa số lượng còn lại ít nhất phải được 25 pools (Còn tuỳ vào thực tế server của bạn như thế nào mà tính cho hợp lý)

Nếu server bạn mạnh, bạn dùng nhiều threads thì đồng nghĩa với việc bạn phải nâng Database lên cho phù hợp. Chứ không thể server mạnh mà Database yếu thì không thể đáp ứng được.

0 Shares:
1 comment
  1. Hi there,
    I apologize for reaching out via your contact form, but I wasn’t sure who the best point of contact is within your company. I wanted to introduce you to a valuable solution for dealerships looking to enhance their lot security—mobile security trailers. Our security trailers are equipped with cutting-edge technology to provide 24/7 surveillance for all of your inventory. https://mrsecuritycameratrailers.com/ These trailers offer high-definition cameras, motion detection, and real-time alerts, all managed remotely for maximum convenience. They are designed to safeguard your property, prevent theft, and ensure the safety of your assets 24/7. I’d love to share a testimonial from one of our dealership clients so you know we are the real thing and a trusted vendor in your industry. You can reach me at mailto:[email protected] or 916-672-2660. If this isn’t something your company is looking for right now, please feel free to let me know, and I’ll ensure we don’t contact you again.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

SOLID Principles

Table of Contents Hide Single-responsibility PrincipleOpen/Closed Principle (OCP)Liskov Substitution Principle (LSP)Interface Segregation Principle (ISP)Dependency Inversion Principle (DIP)Advantages of…