1. 程式人生 > >《高併發下的.NET》第2季 - 故障公告:高併發下全線崩潰

《高併發下的.NET》第2季 - 故障公告:高併發下全線崩潰

大家好,非常抱歉,在昨天下午(12月3日)的訪問高峰,園子迎來更高的併發,在這樣的高併發下,突發的資料庫連線故障造成部落格站點全線崩潰,由此給您帶來很大的麻煩,請您諒解。 最近,我們一邊在忙於[AWS合作專案](https://www.cnblogs.com/cmt/p/14003277.html),一邊在加快產品的改進速度,一邊在統一全園UI,一邊在忙於解決高併發下出現的各種問題。園子正處於發展的關鍵時期,我們正全力應對挑戰,迎接園子的新階段。感謝大家的支援,也請大家諒解這段時間給大家帶來的麻煩。 今天下午的故障開始於 14:09 左右,最開始出現的故障是訪問部落格後臺502。 發生故障時部落格後臺第1條錯誤日誌是 SqlClient 連線 SQL Server 資料庫失敗(我們用的是阿里雲 RDS SQL Server 例項) > 2020-12-03T14:09:48 ERR [Path:/healthz]/[Action:]/[Version:] Health check "blogdb" completed after 0.3522ms with status Unhealthy and description 'null' Microsoft.Data.SqlClient.SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. This failure occurred while attempting to connect to the Principle server. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=20025; handshake=3; ---> System.ComponentModel.Win32Exception (258): Unknown error 258 at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) 3分鐘後,部落格站點也開始出現故障,表現為訪問有時出現500錯誤。 發生故障時部落格站點第1個錯誤日誌是 SqlClient 解析資料庫伺服器名稱失敗 > 2020-12-03 14:12:46.729 [Error] An exception occurred while iterating over the results of a query for context type '"BlogServer.Infrastructure.Data.EfUnitOfWork"'." ""Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name or service not known at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses) at System.Net.Dns.GetHostAddresses(String hostNameOrAddress) at Microsoft.Data.SqlClient.SNI.SNITCPHandle.Connect(String serverName, Int32 port, TimeSpan timeout, Boolean isInfiniteTimeout, String cachedFQDN, SQLDNSInfo& pendingDNSInfo) 之後就是部落格後臺一直 502,部落格站點訪問速度慢,頻繁出現500錯誤。 在之後的故障處理過程中,我們進行了資料庫伺服器的主備切換,切換後部落格後臺恢復了正常。但高併發壓力下的部落格站點怎麼也無法恢復正常,資料庫主備切換後,資料庫連線數飆升
之後我們使勁渾身解數,也無法讓部落格站點完全恢復正常,恢復到一定程度後發現,訪問有時飛快有時非常緩慢,這與請求落在哪個 pod 有關,後來我們向 k8s 叢集添加了更多伺服器,scale 更多 pod ,然後強制一個一個停用執行時間最早的一批 pod ,這才有所緩解,但真正恢復是在過了訪問高峰之後。 先發布這篇博文向大家彙報一下故障的大致情況,對於故障的原因,我們需要進一步排查與分析,再次請大家諒解這次故障給您帶來的麻煩。