微服務之間調用超時的設置治理

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微服務是⼀種分佈式架構,系統內各部分(服務)被部署爲單獨的應用程序,並通過某種遠程訪問協議進⾏通訊。分佈式應⽤的挑戰之⼀就是如何管理遠程服務的可用性和它們的響應。本⽂主要探討服務的響應時間對系統的影響和應對。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.infoq.cn\/resource\/image\/5a\/7c\/5a7ed46c5c06abb45b5b25eee704d47c.jpg","alt":null,"title":"","style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上圖是簡化的微服務調用鏈路過程,爲清晰闡述三個相關方,圖中的客戶端被限定爲用戶端(如移動端應用、瀏覽器頁面等),服務端被區分爲服務消費方(網絡調用中客戶端)和服務提供方(網絡調用中服務端)。⼤部分服務既爲服務消費方,⼜爲服務提供方,如處於調⽤鏈路中間的業務服務,大概率需要去整合數據,所以通常會同時作爲服務消費方和服務提供方,兩種資源消耗並存。小部分服務是純粹的服務提供方,如數據庫、緩存、ZooKeeper等。下⽂先來分析服務響應時間過⻓對資源消耗問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"資源消耗分析"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"靜態分析"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"微服務都有⾃身的硬件資源上限,直觀來看,響應時間會對資源消耗產⽣直接影響。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"服務消費方"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"協議消耗,每次發起TCP連接請求時,通常會讓系統選取⼀個空閒的本地端⼝(local port),該端⼝是獨佔的,不能和其他TCP連接共享。TCP端⼝的數據類型是unsigned short,因此可⽤端⼝最多隻有65535,所以在全部作爲client端的情況下,最⼤TCP連接數65535。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"除端⼝消耗外,發起調⽤的業務進程、線程、協程等待過程中,⽆法釋放其所消耗的內存、CPU等,是服務消費⽅發起調⽤的主要消耗。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"服務提供方"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"協議消耗,主要是建⽴連接的消耗,每接收每⼀個tcp連接都要佔⼀個⽂件描述符,理論上是server端單機最⼤tcp連接數約爲2的48次方。"}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"業務邏輯消耗。在複雜的業務邏輯、機器資源和⽹絡帶寬條件下,最⼤併發tcp連接數遠不能達到理論上限,有時候會發現,單機1w併發往往也是⽐較困難。因此,服務提供⽅主要是業務邏輯的⼤量資源消耗,如CPU、⽹絡帶寬、磁盤IO等。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"動態分析"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在調⽤持續發⽣且服務提供⽅不及時返回的情況下,未觸發性能拐點前,可以簡化認爲資源的消耗是線性增⻓。微服務發起⼀個請求,會佔⽤⼀個空閒的本地端⼝,當然,每個連接所對應的業務處理過程,也會對應消耗內存、IO、CPU消耗等資源,"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"簡化爲如下公式:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"RR = RT - QPS * RCPR * Duration- Release * Tinny_T "}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章