Kết nối nhóm trong nodejs là gì?
Nút. js có thể kết nối với các sản phẩm cơ sở dữ liệu MariaDB bằng Trình kết nối/Nút MariaDB. js để sử dụng nhóm kết nối với API gọi lại. Nhóm kết nối cho phép sử dụng lại các kết nối cơ sở dữ liệu để giảm thiểu chi phí hoạt động của việc kết nối với cơ sở dữ liệu và thời gian mở và đóng kết nối Show Nhóm kết nối giữ các kết nối mở trong một nhóm. Khi quá trình hoàn tất với kết nối, nó được trả về nhóm thay vì đóng lại, cho phép Trình kết nối/Nút MariaDB. js để có được kết nối khi cần Nhóm kết nối với API gọi lạiVới API gọi lại, nhóm kết nối có thể được sử dụng. API gọi lại cung cấp các chức năng sau trong đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]7 để tạo nhóm kết nối Chức năng Loại trả lại Sự miêu tả Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]8 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]9 Chức năng cơ bản để tạo nhóm kết nối Đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]9 hỗ trợ chức năng gọi lại trong các chức năng sau Chức năng Sự miêu tả Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]1 Lấy kết nối dưới dạng đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]7. Hàm gọi lại được xác định với hai đối số là Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]0. Đối số đầu tiên dành cho đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]1 nếu xảy ra lỗi và đối số thứ hai dành cho đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]7 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]3 Được sử dụng để chạy một câu lệnh SQL hoặc câu lệnh đã chuẩn bị. Các tham số chức năng có ý nghĩa tương tự như đối với chức năng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]4 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]5 Được sử dụng để chạy một loạt các câu lệnh SQL. Các tham số chức năng có cùng ý nghĩa như đối với chức năng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]6 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]7 Đóng nhóm và các kết nối cơ bản sau khi tất cả các truy vấn đang chạy đã hoàn thành. Hàm gọi lại được xác định với một đối số duy nhất cho đối tượng Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]1 nếu xảy ra lỗi khi đóng nhóm Tùy chọnHàm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]9 hỗ trợ các tùy chọn dành riêng cho nhóm sau Tùy chọn Sự miêu tả Loại Giá trị mặc định pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)0 Thời gian chờ để nhận kết nối mới từ nhóm tính bằng mili giây. Để có thông tin lỗi kết nối, pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)0 phải cao hơn pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)2 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)4 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)5 Số lượng kết nối tối đa trong nhóm pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)7 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)8 Đặt thời gian nhàn rỗi sau đó kết nối nhóm được giải phóng. Giá trị phải thấp hơn wait_timeout. Trong vài giây (0 có nghĩa là không bao giờ phát hành) pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]90 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]91 Cho phép đặt số lượng kết nối tối thiểu trong nhóm. Chúng tôi khuyên bạn nên sử dụng nhóm cố định và do đó không đặt giá trị này. pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)5. pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)7 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]95 Khi yêu cầu kết nối với nhóm, nhóm sẽ xác thực trạng thái kết nối. Để tránh xác minh không cần thiết trong trường hợp sử dụng lại các kết nối thường xuyên, "minDelayValidation" cho phép vô hiệu hóa xác thực này nếu kết nối đã được mượn gần đây. 0 có nghĩa là xác thực được thực hiện mỗi khi yêu cầu kết nối. (tính bằng mili giây) pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]97 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]98 Sau khi đưa kết nối trở lại nhóm ( Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]99) trình kết nối sẽ đặt lại hoặc khôi phục kết nối để đảm bảo trạng thái hợp lệ. Tùy chọn này cho phép vô hiệu hóa các điều khiển đó Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]70 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]71 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]72 Khi kết nối được đưa trở lại nhóm, tùy chọn này cho phép đặt lại kết nối nếu máy chủ cho phép (chỉ dành cho phiên bản MariaDB >= 10. 2. 22/10. 3. 13). Nếu bị vô hiệu hóa hoặc phiên bản máy chủ không cho phép đặt lại, nhóm sẽ chỉ khôi phục giao dịch mở nếu có Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]70 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]74 trước 3. 0, Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]71 kể từ Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]76 Đặt thời gian chờ để đăng nhập kết nối mượn từ nhóm. Khi một kết nối được mượn từ nhóm và hết thời gian chờ này, một thông báo sẽ được ghi vào bảng điều khiển cho biết có thể xảy ra rò rỉ kết nối. Một thông báo khác sẽ cho biết rò rỉ được ghi lại có thể đã được phát hành hay chưa. Giá trị 0 vô hiệu hóa phát hiện rò rỉ pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]78 Cân bằng tảiNgoài các nhóm kết nối, Trình kết nối/Nút MariaDB. js cũng hỗ trợ pool cluster. Điều kiện tiên quyết là một cụm các nút đang chạy MariaDB. Trong trường hợp nhóm kết nối là một tập hợp các kết nối được duy trì đến một máy chủ riêng lẻ, trong một cụm nhóm, Trình kết nối duy trì một tập hợp các nhóm kết nối đến các máy chủ khác nhau Cụm nhóm hữu ích trong trường hợp triển khai lớn trong đó ứng dụng của bạn cần kết nối với các máy chủ khác nhau cho các mục đích khác nhau hoặc khi bạn muốn thực hiện cân bằng tải ở cấp độ ứng dụng. Lợi ích của cụm nhóm là tính sẵn sàng cao và phân phối tải Cụm nhóm cung cấp tổng hợp kết nối trên các máy chủ khác nhau trong cụm. Cụm nhóm không cung cấp bản sao dữ liệu cho máy chủ MariaDB trong cụm. Để sao chép, hãy sử dụng MariaDB ReplicationTriển khai MariaDB Replication Cụm nhóm có thể được sử dụng với API gọi lại. API gọi lại cung cấp chức năng sau để tạo cụm nhóm Chức năng Loại trả lại Sự miêu tả Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]79 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]80 Chức năng cơ sở để tạo một cụm nhóm Hàm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]81 hỗ trợ tất cả các tùy chọn được hỗ trợ bởi Pool API. Hơn nữa, các tùy chọn API nhóm bao gồm các tùy chọn từ hàm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]82, được thảo luận trong Hàm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]81 hỗ trợ các tùy chọn bổ sung sau Tùy chọn Sự miêu tả Loại Giá trị mặc định Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]84 Liệu cụm nhóm có thể cố gắng nhận kết nối từ nhóm khác hay không nếu nhận được kết nối từ một nhóm không thành công Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]70 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]74 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]87 Số lỗi cho một nhóm duy nhất trong việc nhận kết nối sau đó nhóm được xóa khỏi cụm nhóm. Đặt thành Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]88 nếu nhóm không bao giờ bị xóa pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]90 trước 3. 0, Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]91 kể từ Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]92 Thời gian chờ tính bằng mili giây sau đó một nhóm được thử lại cho kết nối sau khi kết nối không thành công. Giá trị mặc định là 1000 pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections)3 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]94 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]95 Chỉ định bộ chọn nhóm mặc định. Chiến lược bộ chọn nhóm được sử dụng để chọn nhóm nào trong cụm để thử kết nối. 'RR' dành cho bộ chọn vòng tròn. 'RANDOM' là chọn ngẫu nhiên. 'ĐẶT HÀNG' là chọn theo trình tự hoặc thứ tự được thêm vào cụm nhóm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]96 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]97 Trình kết nối/Nút MariaDB. js Callback API hỗ trợ các bộ chọn cân bằng tải sau Cân bằng tải Bộ chọn Sự miêu tả Trật tự Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]98 Máy chủ được chọn theo thứ tự liệt kê Ngẫu nhiên Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]99 Máy chủ được chọn ngẫu nhiên thi đấu vòng tròn Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]90 Máy chủ được chọn bằng tính năng vòng tròn Mã ví dụ. Tạo nhóm kết nốiVí dụ mã sau khởi tạo nhóm kết nối Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]2
Đầu ra từ tập lệnh liệt kê tập kết quả truy vấn dưới dạng đối tượng JSON. Ngoài ra đầu ra là siêu dữ liệu Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ] Các kết nối mới có thể không được tạo với thông báo sau nếu nhóm kết nối không thể tạo bất kỳ kết nối nào do máy chủ đạt đến giới hạn pool fail to create connection ((conn=241, no: 1040, SQLState: 08004) Too many connections) Tăng giá trị trên biến hệ thống max_connections để tăng giới hạn này nhằm cho phép nhiều kết nối hơn đến máy chủ Mã ví dụ. Đóng kết nốiKhi bạn hoàn tất kết nối được truy xuất từ nhóm, hãy đóng kết nối đó bằng hàm Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]99 Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]9 Các kết nối được lấy từ nhóm kết nối được trả về nhóm khi đóng. Nhóm giữ một số lượng kết nối nhất định được định cấu hình sẵn để sử dụng. Khi ứng dụng gọi lại phương thức Connected. Connection id is 132 [ { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'Johnny', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' }, { first_name: 'John', last_name: 'Smith', email: '[email protected]' } ] [ //metadata //... ]10, kết nối sẽ được trả lại cho ứng dụng Nhóm kết nối được sử dụng để làm gì?Sử dụng nhóm kết nối giúp giảm bớt chi phí quản lý kết nối và giảm các nhiệm vụ phát triển để truy cập dữ liệu . Mỗi khi một ứng dụng cố gắng truy cập vào kho lưu trữ phụ trợ (chẳng hạn như cơ sở dữ liệu), nó sẽ yêu cầu tài nguyên để tạo, duy trì và giải phóng kết nối đến kho dữ liệu đó.
pool trong chuỗi kết nối là gì?Một nhóm kết nối được tạo cho mỗi chuỗi kết nối duy nhất . Khi một nhóm được tạo, nhiều đối tượng kết nối sẽ được tạo và thêm vào nhóm để đáp ứng yêu cầu về kích thước nhóm tối thiểu. Các kết nối được thêm vào nhóm khi cần, lên đến kích thước nhóm tối đa được chỉ định (100 là mặc định).
Nhóm trong HTTP là gì?Dịch vụ nhóm kết nối HTTP cho phép quản lý và sử dụng lại các kết nối http một cách tập trung để liên lạc ra bên ngoài . Dịch vụ nhóm kết nối sử dụng khái niệm nhóm được đặt tên. Nhóm được đặt tên có một số tùy chọn cấu hình trên đó mô tả cách kết nối từ nhóm đó sẽ hoạt động.
Hồ bơi kết nối vào mùa xuân là gì?Nhóm kết nối mặc định trong Spring Boot 2 là HikariCP . Nó cung cấp các tính năng sẵn sàng cho doanh nghiệp và hiệu suất tốt hơn. HikariCP là một triển khai JDBC DataSource cung cấp cơ chế tổng hợp kết nối. Nếu HikariCP xuất hiện trên đường dẫn lớp, Spring Boot sẽ tự động định cấu hình nó. |