爲什麼要雲原生?

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"1.寫在前面"}]},{"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","text":"本文希望探討雲原生的誕生場景。以及解決的問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"2.服務的發展之路"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"簡單總結下過去十多年服務的演變之路,總體可以分爲如下3個階段"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"【單體架構階段】->【RPC架構階段】->【微服務架構階段】"}]},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"2.1 單體架構階段"}]},{"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},"content":[{"type":"text","text":"當網站流量很小時,只需一個應用,將所有功能都部署在一起,以減少部署節點和成本。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/35/3536940937aaf8858d5bb4fdf15d6690.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"2.2 RPC架構階段"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"隨之互聯網的發展,流量激增,單體應用面臨着許許多多的問題,例如:"}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"單體應用增加機器以及無法帶來性能上的提升"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"代碼量巨大,啓動服務都要幾分鐘"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":3,"align":null,"origin":null},"content":[{"type":"text","text":"不方便系統維護,經常合併代碼衝突。"}]}]}]},{"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},"content":[{"type":"text","text":"例如 用戶服務,交易服務,庫存服務等等,分別由不同團隊維護,並且可以獨自增加機器,方便支持更大的業務量。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/a1/a1c6deb5c54a5b57e811422f3ba71ee8.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"heading","attrs":{"align":null,"level":5},"content":[{"type":"text","text":"2.3 微服務架構階段"}]},{"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},"content":[{"type":"text","text":"單個服務的如果出現問題,可能引起服務雪崩,拖垮調用方服務"}]},{"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},"content":[{"type":"text","text":"服務的狀態監控?"}]},{"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},"content":[{"type":"text","text":"所以這塊提出服務治理的概念,去解決上述提出的一系列問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果沒有一系列的服務治理基礎設施,所謂的微服務架構階段與RPC架構階段沒有很大區別"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"3. 當下矛盾點"}]},{"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},"content":[{"type":"text","text":"目前,互聯網微服務架構大行其道,那麼我們需要認識到當前服務的主要矛盾的點所在"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"過去3-5年時期,互聯網處於流量紅利期,那個階段業務野蠻生長,每日的業務量都是一個新的高峯,在那個時期,往往都是不在意成本搶佔市場,機器資源利用率普遍不高。"}]},{"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},"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},"content":[{"type":"text","text":"假設你的代碼處於一種完美狀態,最大程度的壓榨的機器性能,但是業務是有高峯低谷時期之分的,例如貓眼電影,重要檔期是業務的最高峯,但是週一到週五業務量其實沒有很大;或者一天中,凌晨1點到凌晨5點基本沒有人購票,晚上8點纔是購票高峯。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"那麼這個時候如何提高資源利用率呢?難道我每天晚上1點縮容,早上6點起來擴容?這不得累死人"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/97/97dc3de7e3c75ca1c1c19b31bd8af2d6.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"4. 解決之道"}]},{"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},"content":[{"type":"text","text":"啥叫【彈性擴容】【按需計費】"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/ad/ad9366f2f0c8d59a60d20d48c3c29683.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"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},"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},"content":[{"type":"text","text":"貓眼電影,一個服務機器假設有100臺機器。在晚上8點前,發現流量在逐步增加,集羣機器的負載也在逐步增加,資源利用率已經超過60%【彈性擴容】根據這個指標判斷未來是業務上漲階段,就提前擴容了10臺機器,如果過一段時間發現還是集羣機器負載逐步增高,那說明擴容不夠,還要再擴容10臺。等到了凌晨1點,大家都睡覺了,沒有看電影了。發現集羣機器負載降低了好多,流量也降低了好多,資源利用率不到3%【彈性擴容】判斷未來是業務下降階段,那麼就縮容80臺機器。"}]},{"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},"content":[{"type":"text","text":"原來沒有【彈性擴容】一天我服務器費用是100 "},{"type":"text","marks":[{"type":"italic"}],"text":" 24 "},{"type":"text","text":" 60 * 60 * M M=每秒鐘的服務使用費。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"現在有【彈性擴容】因爲我業務不同時間段的機器數量不同,業務低峯期的服務器費用基本可以節省80%,那麼服務器的費用將大大降低 。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/84/847a0949aac8b9ecf0c5079273800735.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"5. 問題就解決了?"}]},{"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},"content":[{"type":"text","text":"但是通過【彈性擴容】【按需計費】就把當前問題的矛盾點解決了?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可以說是,也可以說不是!"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/47/4755576ea4534bb3daf9dc53eff66cbb.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"key":"bordertype","value":"none"}],"href":"","fromPaste":false,"pastePass":false}},{"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},"content":[{"type":"text","text":"說沒有解決,說因爲它引出了一個新的問題。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"什麼問題?"},{"type":"text","marks":[{"type":"strong"}],"text":"如何快速拉起一個高性能服務進程"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"什麼是"},{"type":"text","marks":[{"type":"strong"}],"text":"高性能服務進程"},{"type":"text","text":"?"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/13/13199725066ae2bc783fb3aa7a7c038d.png","alt":null,"title":"","style":[{"key":"width","value":"50%"},{"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},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"舉個例子"}]},{"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","text":"好吧,就算上面這些你都是十分迅速的完成了,假設你服務是一個Java程序,你發佈的服務還未經過JIT即使編譯器的優化,虛擬機解釋執行的效率十分感人,你的服務性能TP99線急劇升高,接口的超時嚴重,引起服務雪崩拖垮調用方服務。"}]},{"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}},{"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},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"如何快速拉起一個高性能服務進程"},{"type":"text","text":"?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這個問題分爲兩個部分解決:"},{"type":"text","marks":[{"type":"strong"}],"text":"服務器快速生成,高性能應用快速啓動"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"服務器快速生成"},{"type":"text","text":"的目前解決方案是容器化部署,傳統應用都部署在虛擬機或者物理機器上,相較於前兩者,容器化啓動速度往往遠超前兩者"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/84/841f1ae92e2260e1455f43721df85d06.png","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},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"高性能應用快速啓動"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"高性能應用快速啓動也有兩個部分解決"}]},{"type":"numberedlist","attrs":{"start":1,"normalizeStart":1},"content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":1,"align":null,"origin":null},"content":[{"type":"text","text":"編譯後做成鏡像包,二次部署無需從服務代碼開始執行編譯,打包等耗時過程"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":1,"number":2,"align":null,"origin":null},"content":[{"type":"text","text":"使用更加輕量級的框架,減少程序包中的代碼數量,並且使用AOT技術,將Java實現編譯成二進制碼,跳過部署完成後,解釋執行的階段"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"第一點還好理解,傳統發佈服務,需要在倉庫中拉Master分支代碼,然後編譯,打包,運行才能啓動起來,如果實現就將打包好程序包做成鏡像,自然可以跳過上述那些十分耗時的時間。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"第二點怎麼理解 "},{"type":"text","marks":[{"type":"strong"}],"text":"輕量級框架"},{"type":"text","text":"和"},{"type":"text","marks":[{"type":"strong"}],"text":"AOT技術"},{"type":"text","text":"呢?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"傳統的基於 Java 和 J2EE 的編程模型和框架開發的程序,存在高內存需求和啓動速度(Class文件需要類加載)緩慢等限制"}]},{"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},"content":[{"type":"text","text":"目前業界"},{"type":"text","marks":[{"type":"strong"}],"text":"Quarkus"},{"type":"text","text":"開始嶄露頭角,本質上就是一款輕量級框架,並且可以AOT結合直接編譯成二進制碼。可以迅速拉起一個服務,經過測試啓動一個HelloWorld只需要"},{"type":"text","marks":[{"type":"strong"}],"text":"12ms"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":4},"content":[{"type":"text","text":"6. 總結"}]},{"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},"content":[{"type":"text","text":"當然雲原生要解決的問題絕不是單純上面描述的資源利用率的問題,還有"},{"type":"text","marks":[{"type":"strong"}],"text":"支持業務務快速迭代、業務組合複雜、海量用戶、流量突增、7*24小時高可用,故障轉移,自動恢復"},{"type":"text","text":"等等"}]},{"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},"content":[{"type":"text","text":"至於雲原生的【微服務】【DevOps】【持續交付】【容器化】只是基礎門檻,使用這些並不代表雲原生了,基本上大廠這些基礎設施都是標配。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所以我們應該清晰認識到雲原生的"},{"type":"text","marks":[{"type":"strong"}],"text":"核心"},{"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}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章