簡體   English   中英

強調 spring 引導服務時消耗的 GCP Postgres 連接數(使用 SQL 雲代理)

[英]GCP Postgres connections consumed when stressing spring boot service (using SQL Cloud proxy)

我正在使用 Spring 引導服務來發布數據並將其保存在GCP SQL Postgres數據庫中。 問題是當我用請求強調服務時,我得到一個關於消耗所有可用連接的 SQL 異常

"FATAL: remaining connection slots are reserved for non-replication superuser connections"

我想通了這個問題,我添加了一個適當的 hikari 配置來限制使用的連接並設置何時關閉空閑連接的限制,這是我的 properties.yml 配置:

 type: com.zaxxer.hikari.HikariDataSource
 hikari:
   initializationFailTimeout: 30000
   idle-timeout: 30000
   minimum-idle: 5
   maximum-pool-size: 15
   connection-timeout: 20000
   max-lifetime: 1000 

當我使用同一數據庫在本地運行該服務時,該服務在該設置下運行良好,但當我從我的雲設置運行它時,它會消耗所有可用連接,然后出現相同的異常

重要的! 我正在使用 SQL 雲代理連接到數據庫。

以下是數據庫可用連接的屏幕截圖:

1- 在運行服務之前

在此處輸入圖像描述

2- 在本地運行服務后

在此處輸入圖像描述

3- 從雲端運行服務后在此處輸入圖像描述

經過幾天對這個問題的排查,我們找到了一個緩解問題但沒有徹底解決問題的解決方案(最后提到了理想的解決方案)。

如果您想繼續使用 SQL 雲代理,那么您需要接受這樣一個事實,即您無法完全控制您的數據庫連接配置,因為 SQL 雲代理可能使這些連接保持活動狀態的時間超過您配置的時間( 來源).

為了緩解這個問題,我們使用了docker 注冊表中的 SQL Cloud proxy 1.19.2,我們使用了這個 hikari 配置:

hikari:
  idle-timeout: 30000 # maximum amount of time (in milliseconds) that a connection is allowed to sit idle in the pool
  minimum-idle: 1 # minimum number of idle connections that HikariCP tries to maintain in the pool, including both idle and in-use connections. If the idle connections dip below this value, HikariCP will make a best effort to restore them quickly and efficiently
  maximum-pool-size: 15 # maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend
  connection-timeout: 20000 #maximum number of milliseconds that a client will wait for a connection
  max-lifetime: 20000 # maximum lifetime in milliseconds of a connection in the pool after it is closed.

在這種情況下,正確的解決方案是使用共享 VPC與您的數據庫建立專用連接,您將依靠數據庫驅動程序建立這些連接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM