使用haproxy作為sql server 的負載均衡器。
使用了文檔中的示例配置項:
timeout client 50s
timeout server 50s
采用這個配置項,有時會出現“遠程主機強迫關閉了一個現有的連接”的錯誤。
出現這個錯誤的原因是:一旦sql client超過50s沒有給haproxy發送數據,則haproxy會關閉這個連接,此時sql client中的以為連接還是通的,此時發送數據就會出現異常。
在查看了HAProxy的官方文檔,以及mysql和sql server的文檔之后,將配置改為:
timeout client 8h
timeout server 8h
之后正常了。為什么設置為8小時呢?sql server沒有查到類似wait timeout的資料,於是借鑒了mysql的配置項,mysql有一個名為wait timeout的配置項,它的默認時間為8小時,這個配置項的意思是當mysql發現與客戶端的tcp連接如果超過8個小時不活動的話(收發數據),那么mysql就關閉這個連接。這個配置項跟http1.1中的keep alive timeout是類似的。
參考:
Apache: Keep-alive timeout
Amount of time the server will wait for subsequent requests on a persistent connection
Mysql: wait_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
HAProxy: timeout client
The inactivity timeout applies when the client is expected to acknowledge or send data.
