Principles of Reactive Programming 之Actors are Distributed (1)
week7中的前兩節課的標題是”Actors are Distributed",講了很多Akka Cluster的內容,同時也很難理解。
Roland Kuhn并沒有講太多Akka Cluster自身如何工作的細節,而是更關注于如何利用Akka Cluster來把Actor分布到不同的節點上,或許這么安排是因為Akka Cluster能講的東西太多,而Coursera的課時不夠。但是,從聽眾的角度來說,這節課只是初步明白了下Akka Cluster能干啥,但是想要自己用起來,特別是想了解其工作的機制,還需要自己再去看很多東西。在我看了下Akka的文檔里關于Cluster的一章之后,發現不懂的地方更多了……好吧,不能再搞魔獸世界了!
鑒于不懂的地方太多,還是按照課程講的順序先過一遍,整理一下不懂的地方,以后分開研究。下面是課程的內容, 包括:課程PPT的內容,作者在講課過程中一些重要的觀點和我的一些理解。
Roland Kuhn在視頻開頭的時候,介紹了一下本周要講的內容:
In this last week of the reactive programming course, we will focus first on something which was implicitly there already. Namely, that actors as independent agents of computation are by default distributed. Normally you run them just on different CPU's in the same system. But, there is nothing stopping you from running them on different network hosts, and we will do this in practice. This means, if you picture for example, people who are living on different continents that it takes some effort for them to agree on a common truth or a common decision. The same thing is true for actors and we call this eventual consistency. After that, we will talk about scalability and responsiveness and how you achieve these in an actor-based system. Rounding up all the four tenets of reactive programming, which were event-driven Scalable, resilient, and responsive.
在這reactive programming課程的最后一周,我們將會重點看一下已經暗自存在著的內容。也就是說,actor作為相互獨立的計算單元,默認是分布式的。通常,你會在一個系統的不同CPU上運行他們,但是,沒有什么能阻止你把它們運行在網絡中的不同主機上,我們接下來將實際這么做一次。這(actor是分布式的)意味著,舉個栗子,拿生活在不同的大陸上的人們來說,他們需要花費一些努力才能夠就某個事實或者某個決定達成一致。這種情況對actor也一樣,我們把它叫做“最終一致性”。在那(介紹完最終一致性)之后,我們將介紹scalability和responsiveness以及如何在基于actor的系統中實現他們。圍紹著reactive programming的四個原則: event-driven, scalable, resilent, responsive
這里發現得再理解下這四個tenets,于是找了篇文章翻譯了一下。
?
The Impact of Network Communication
Compared to in-process communication:
- data sharing only by value
- lower bandwith
- higher latency
- partial failure
- data corruption
Multiple processes on the same machine are quantitatively less impacted, but qualitatively the issues are the same.
?比較網絡通信和進程內通信,是用來了解actor在分布式的方面能帶領我們走多遠。
- 在網絡通信時,數據以值的方式被傳遞。對象需要被序列化,通過網絡傳輸,反序列化,經過這些步驟,被傳輸后的對象和原始的對象就不是完全相同了(畢竟現在在不同的JVM里)。之前講過,一個有狀態的對象,它的行為跟它的歷史有關系。但是一個有狀態的對象在經過網絡傳輸以后,經過一段時間,網絡兩邊的這兩個對象的狀態就可能會不同了。因此,只有共享不可變對象,才是有意義的。(意思應該是通過網絡傳輸一個可變狀態的對象,然后想在網絡兩端共享這個對象,是沒有意義的)。
- 網絡帶寬比一個機器內部數據的帶寬要小很多。
- 所有通信的延遲要高很多。你可以在一納秒內調用一個方法,但是不能在一納秒傳遞一個網絡數據包。并且在網絡通信時,對象需要被序列化和反序列化,這比在進程內部傳遞引用要帶來更高的時延。
- 除了這些量上的區別,還有新的情況發生。就是,當進行網絡通信時,有partial failure的風險, 或者你的一些消息只有一部分到達了,并且在收到回復之前你不知道哪些到達了。
- 另一類failure是data corruption。從個人的經驗業看,通過TCP發送數據時,大約每TB會有一個損壞事件。
Multiple processes on the same machine are quantitatively less impacted, but qualitatively the issues are the same.
Distributed computing breaks assumptions made by the synchronous programming model.
在同一個機器上運行多個進程,讓他們通過,比如localhost interface通信,可以緩解上邊的一些問題。但是本質上的問題仍然存在。
The overarching description of the problem is that distributed computing breaks the core assumptions made by a synchronous programming model.
對于這個問題總的描述是分布式計算打破了同步編程模型的核心假設。
Actors are Distributed
Actor communication is asynchronous, one-way and not guaranteed.
Actor encapsulation makes them look the same, regardless where they live.
Actors are "Location Transparent", hidden behind ActorRef.
迄今,我們已經講了很多關于actor的知識,你們也知道了actor的所有通信都是異步的和單向的,并且不會保證可靠傳遞。 因此,actor實際上建模的東西就是網絡給我們的東西. They model precisely what the network gives us. 可以認為,actor采取了與“把本地模型擴展到網絡”相反的方式。actor模型審視了網絡模型,然后把它用在本地機器上。
Actor的另一個特征是他們如此獨立地運行,以至于從外部來看,他們都一樣。他們都是,ActorRef. 不管actor實際在哪,給他們發消息都是一樣的,我們稱之為位置透明。
當前的Akka的actor模型所提供的特性集里的所有語法都是嚴格地設定為所有東西都是遠程的。所以不能在這個環境中建模的特性都被移除。結果就是,使用actor來編寫一個分布式的程序就跟寫一個本地的同樣的程序有基本相同的工作量。代碼本身沒有什么大的區別喝,我們接下來將看到這點。
?
轉載于:https://www.cnblogs.com/devos/p/4167258.html
總結
以上是生活随笔為你收集整理的Principles of Reactive Programming 之Actors are Distributed (1)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NYOJ541 最强DE 战斗力(第五届
- 下一篇: Java Script基础(九) 下拉列