青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 60, 文章 - 0, 評論 - 197, 引用 - 0
數據加載中……

淺析遠程過程調用 RPC

一、什么是遠程過程調用

  什么是遠程過程調用 RPC(Remote Procedure Call)? 你可能對這個概念有點陌生, 而你可能非常熟悉 NFS, 是的,
NFS 就是基于 RPC 的. 為了理解遠程過程調用,我們先來看一下過程調用。

  所謂過程調用,就是將控制從一個過程 A 傳遞到另一個過程 B, 返回時過程 B 將控制進程交給過程 A。目前大多數系統
中, 調用者和被調用者都在給定主機系統中的一個進程中, 它們是在生成可執行文件時由鏈接器連接起來的, 這類過程調用稱
為本地過程調用。

  遠程過程調用(RPC)指的是由本地系統上的進程激活遠程系統上的進程, 我們將此稱為過程調用是因為它對程序員來說表現
為常規過程調用。處理遠程過程調用的進程有兩個, 一個是本地客戶進程, 一個是遠程服務器進程。對本地進程來說, 遠程過
程調用表現這對客戶進程的控制, 然后由客戶進程生成一個消息, 通過網絡系統調用發往遠程服務器。網絡信息中包括過程調
用所需要的參數, 遠程服務器接到消息后調用相應過程, 然后將結果通過網絡發回客戶進程, 再由客戶進程將結果返回給調用
進程。因此, 遠程系統調用對調用者表現為本地過程調用, 但實際上是調用了遠程系統上的過程。


二、遠程過程調用模型

  本地過程調用: 一個傳統程序由一個或多個過程組成。它們往往按照一種調用等級來安排。如下圖所示:


  遠程過程調用: 使用了和傳統過程一樣的抽象, 只是它允許一個過程的邊界跨越兩臺計算機。如下圖所示:


三、遠程過程和本地過程的對比

  首先, 網絡延時會使一個遠程過程的開銷遠遠比本地過程要大
  其次, 傳統的過程調用因為被調用過程和調用過程運行在同一塊內存空間上, 可以在過程間傳遞指針。而遠程過程不能夠將
指針作為參數, 因為遠程過程與調用者運行在完全不同的地址空間中。
  再次, 因為一個遠程調用不能共享調用者的環境, 所以它就無法直接訪問調用者的 I/O 描述符或操作系統功能。


四、遠程過程調用的幾種版本 
  (1) Sun RPC (UDP, TCP)
  (2) Xerox Courier (SPP)
  (3) Apollo RPC (UDP, DDS)

  其中 Sun RPC 可用于面向連接或非面向連接的協議; Xerox Courier 僅用于面向連接的協議; Apollo RPC 僅用于非連接的協議
 

五、如何編寫遠程過程調用程序
 
  為了將一個傳統的程序改寫成 RPC 程序, 我們要在程序里加入另外一些代碼, 這個過程稱作 stub 過程。我們可以想象一
個傳統程序, 它的一個過程被轉移到一個遠程機器中。在遠程過程一端, stub 過程取代了調用者。這樣 stub 實現了遠程過
程調用所需要的所有通信。因為 stub 與原來的調用使用了一樣的接口, 因此增加這些 stub 過程既不需要更改原來的調用過
程, 也不要求更改原來的被調用過程。如下圖所示:

 


六、示例
    此示例在 Ubuntu 8.04 + gcc 4.2.3 下編譯運行通過。

    遠程過程調用示例(點擊下載)

posted on 2008-08-15 17:02 Normandy 閱讀(15179) 評論(12)  編輯 收藏 引用 所屬分類: Networking

評論

# re: 淺析遠程過程調用 RPC[未登錄]  回復  更多評論   

RPC的優勢在哪里?
2008-08-15 17:56 | achilles

# re: 淺析遠程過程調用 RPC  回復  更多評論   

@achilles
優點是可直接訪問遠程過程,避免煩瑣的打包和解包過程,且不依賴于某種特定的協議
2008-08-15 18:40 | Normandy

# re: 淺析遠程過程調用 RPC[未登錄]  回復  更多評論   

@Normandy
可是這些過程為什么非要放到不同的機器呢,與普通的網絡通信相比RPC有什么優勢?
2008-08-15 20:38 | achilles

# re: 淺析遠程過程調用 RPC  回復  更多評論   

@achilles
優點是可直接訪問遠程過程,避免煩瑣的打包和解包過程,且不依賴于某種特定的協議
===================
顯然你就是看的皮毛
底層仍然通過打包解包實現
你沒聽說過marshall這個詞?
這只不過是打包的另一種說法罷了。。。
2008-08-15 21:05 | 訪客

# re: 淺析遠程過程調用 RPC  回復  更多評論   

遠程過程調用的使用領域太廣泛了,以后要是能不聯機就能定時生成或采集數據就更好了。
2008-08-17 17:46 | dell筆記本

# re: 淺析遠程過程調用 RPC  回復  更多評論   

@achilles
將一些過程放在遠程是分布式程序的要求,如客戶機/服務器模式。相比常規的網絡通信程序而言,在用 RPC 時我們只需要關心程序本身的邏輯,就像建本地程序一樣,因為 RPC 已經幫你做了網絡通信的工作!

如果你還是不能理解, 請下載我上面的遠程過程調用示例,將客戶程序和服務程序放在兩個不同的機器上運行看看。

如果你想了解更多的細節,請看一下 <<Linux 網絡編程>> 第十二章,上面的內容更精彩!
2008-08-18 10:13 | Normandy

# re: 淺析遠程過程調用 RPC  回復  更多評論   

[薦]RPC is bad?
偶像 Steve Vinoski 在 maillist 的回帖中一不留神就泄漏了他為 ErlangeXchange 準備的 session ,我們可以先一睹為快。Steve 大拿是 CORBA 界的牛人,對 RPC 是 bad 很有發言權地。這篇文章也寫得很漂亮,水分相當少,我就不干“損失味道”的事情了。
為方便閱讀,將 mail 內容盜版如下:
Well, if you had time you could dig through my various IEEE Internet Computing columns from the past 6 years and find many reasons listed there. For example, “RPC Under Fire“(note that it’s PDF) from the Sep/Oct 2005 lists a number of problems:
Also, pretty much any of my columns that cover REST to any degree would also contain mentions of RPC’s shortcomings. All the columns can be found here:
But if you don’t have the time or energy, the fundamental problem is that RPC tries to make a distributed invocation look like a local one. This can’t work because the failure modes in distributed systems are
quite different from those in local systems, so you find yourself having to introduce more and more infrastructure that tries to hide all the hard details and problems that lurk beneath. That’s how we got
Apollo NCS and Sun RPC and DCE and CORBA and DSOM and DCOM and EJB and SOAP and JAX-RPC, to name a few off the top of my head, each better than what came before in some ways but worse in other ways, especially footprint and complexity. But it’s all for naught because no amount of infrastructure can ever hide those problems of distribution. Network partitions are real, timeouts are real, remote host and service
crashes are real, the need for piecemeal system upgrade and handling version differences between systems is real, etc. The distributed systems programmer *must* deal with these and other issues because
they affect different applications very differently; no amount of hiding or abstraction can make these problems disappear. As I said about such systems in a recent column:
“The layers of complexity required to maintain the resulting leaky illusion of local/remote transparency are reminiscent of the convoluted equations that pre-Copernican astronomers used to explain how the Sun and other planets revolved around the Earth.” (from “Serendipitous Reuse“)
RPC systems in C++, Java, etc. also tend to introduce higher degrees of coupling than one would like in a distributed system. Typically you have some sort of IDL that’s used to generate stubs/proxies/skeletons
2008-08-21 00:56 | 訪客

# re: 淺析遠程過程調用 RPC  回復  更多評論   

code that turns the local calls into remote ones, which nobody wants to write or maintain by hand. The IDL is often simple, but the generated code is usually not. That code is normally compiled into each app in the system. Change the IDL and you have to regenerate the code, recompile it, and then retest and redeploy your apps, and you typically have to do that atomically, either all apps or none, because versioning is not accounted for. In an already-deployed production system, it can be pretty hard to do atomic upgrades across the entire system. Overall, this approach makes for brittle, tightly-coupled systems.
Such systems also have problems with impedance mismatch between the IDL and whatever languages you’re translating it to. If the IDL is minimal so that it can be used with a wide variety of programming
languages, it means advanced features of well-stocked languages like Java and C++ can’t be used. OTOH if you make the IDL more powerful so that it’s closer to such languages, then translating it to C or other
more basic languages becomes quite difficult. On top of all that, no matter how you design the IDL type system, all the types won’t — indeed, can’t — map cleanly into every desired programming language. This turns into the need for non-idiomatic programming in one or more of the supported languages, and developers using those languages tend to complain about that. If you turn the whole process around by using a programming language like Java for your RPC IDL in an attempt to avoid the mismatch problems, you find it works only for that language, and that translating that language into other languages is quite difficult.
There’s also the need with these systems to have the same or similar infrastructure on both ends of the wire. Earlier posters to this thread complained about this, for example, when they mentioned having to have CORBA ORBs underneath all their participating applications. If you can’t get the exact same infrastructure under all endpoints, then you need to use interoperable infrastructure, which obviously relies on interoperability standards. These, unfortunately, are often problematic as well. CORBA interoperability, for example, eventually became pretty good, but it took about a decade. CORBA started out with
no interoperability protocol at all (in fact, it originally specified no network protocol at all), and then we suffered with interop problems for a few years once IIOP came along and both the protocol itself and implementations of it matured.
Ultimately, RPC is a leaky abstraction. It can’t hide what it tries to hide, and because of that, it can easily make the overall problem more difficult to deal with by adding a lot of accidental complexity.
In my previous message I specifically mentioned Erlang as having gotten it right. I believe that to be true not only because the handling of distribution is effectively built in and dealt with directly, but also because Erlang makes no attempt to hide those hard problems from the developer. Rather, it makes them known to the
developer by providing facilities for dealing with timeouts, failures, versioning, etc. I think what Erlang gives us goes a very long way and is well beyond anything I’ve experienced before. Erlang really doesn’t provide RPC according to the strict definition of the term, BTW, because remote calls don’t actually look like local ones.
(BTW, this is the kind of stuff I’ll be talking about at Erlang eXchange next month.)
2008-08-21 00:57 | 訪客

# re: 淺析遠程過程調用 RPC  回復  更多評論   

可不可以這樣理解:
通常的C/S程序,Server端的程序必須已經在運行,Client端的程序才能和它通訊。

而使用RPC,Client可以遠程啟動Server端的程序。
2008-09-07 10:41 | 訪客

# re: 淺析遠程過程調用 RPC  回復  更多評論   

你講得非常棒,看了你的文章,讓我知道了什么RPC。
2009-03-15 15:12 | bob.shao

# re: 淺析遠程過程調用 RPC  回復  更多評論   

雖然RPC有好有不好,不過很贊你的文章看了就懂,而且跟著做就可以簡單理解一下rpc的例子。

RPC雖然對網絡依賴,但是對于中間件技術來說還是蠻贊的技術。
2009-12-03 21:06 | kaholi

# re: 淺析遠程過程調用 RPC  回復  更多評論   

你將得非常的好.謝謝你
2014-12-01 19:06 | 被JAVA淹沒的庫比程序員
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            麻豆av一区二区三区| 亚洲精品影院| 亚洲精品视频一区| 亚洲激情在线激情| 激情综合色综合久久| 国内久久精品| 91久久精品国产91久久性色tv| 亚洲国产精品嫩草影院| 最新国产精品拍自在线播放| 99视频一区二区三区| 中日韩午夜理伦电影免费| 欧美亚洲在线| 女人香蕉久久**毛片精品| 亚洲国产高清aⅴ视频| 亚洲国产欧美一区二区三区丁香婷| 亚洲国产精品成人一区二区| 99视频+国产日韩欧美| 亚洲欧美一区二区三区在线| 玖玖精品视频| 欧美三区美女| 禁断一区二区三区在线| 亚洲美女福利视频网站| 欧美在线观看一区二区三区| 美腿丝袜亚洲色图| 99re66热这里只有精品3直播| 欧美一级大片在线免费观看| 欧美成人dvd在线视频| 国产精品日韩精品| 亚洲精品乱码久久久久久蜜桃91| 亚洲欧美日本日韩| 香蕉久久夜色精品| 国一区二区在线观看| 亚洲人体一区| 久久av一区二区三区| 亚洲国产精品福利| 性色av一区二区三区在线观看| 欧美大片国产精品| 国内精品视频久久| 午夜亚洲激情| 91久久国产综合久久蜜月精品| 亚洲一区二区精品| 欧美国产精品日韩| 1769国产精品| 久久久精品国产免大香伊| 一本色道久久综合亚洲精品高清 | 国产精品激情电影| 亚洲高清网站| 久久久噜噜噜久久中文字幕色伊伊 | 亚洲精品一区二区三区四区高清| 性久久久久久久| 欧美日韩在线一区二区三区| 亚洲精品永久免费| 免费人成精品欧美精品| 欧美一区精品| 国产日韩欧美一区在线| 亚洲欧美国产制服动漫| 日韩亚洲一区二区| 欧美日韩午夜视频在线观看| 亚洲日韩欧美视频一区| 亚洲国产高清高潮精品美女| 久久免费视频网站| 亚洲二区精品| 亚洲国内自拍| 欧美日韩国产成人高清视频| 亚洲少妇中出一区| 亚洲性夜色噜噜噜7777| 国产伦精品一区二区三区照片91| 午夜久久久久久久久久一区二区| 亚洲综合日韩中文字幕v在线| 国产精品爽黄69| 久久精品视频播放| 久久久国产精品亚洲一区| 在线成人性视频| 亚洲国产一区二区三区a毛片 | 欧美激情一二三区| 一区二区动漫| 亚洲综合不卡| 精品成人一区二区三区| 欧美激情视频网站| 欧美日韩国产大片| 亚洲欧美日韩精品在线| 91久久精品日日躁夜夜躁欧美| 亚洲大胆人体视频| 欧美经典一区二区三区| 亚洲欧美久久久| 久久精品中文| 一本色道久久综合亚洲精品小说 | 亚洲国产美女久久久久| 亚洲欧洲精品天堂一级 | 1024欧美极品| 99re热这里只有精品视频| 国产欧美不卡| 亚洲激情第一页| 国产欧美大片| 欧美激情偷拍| 国产精品三级视频| 男女av一区三区二区色多| 欧美日韩在线一二三| 久久一综合视频| 欧美午夜欧美| 欧美激情va永久在线播放| 国产精品jvid在线观看蜜臀| 久久这里有精品视频| 欧美性猛交99久久久久99按摩| 久久精品视频在线| 欧美午夜www高清视频| 欧美国产日韩精品| 国产日韩成人精品| 亚洲人成网站精品片在线观看| 国产区日韩欧美| 亚洲伦理中文字幕| 亚洲国产精品va| 欧美专区一区二区三区| 亚洲欧美日韩视频一区| 欧美精品久久99久久在免费线| 久久亚洲一区二区| 国产亚洲欧美一区二区三区| 中文一区二区| 一区二区欧美在线| 欧美激情乱人伦| 亚洲第一成人在线| 一区二区三区亚洲| 午夜日韩视频| 欧美一级黄色录像| 国产精品久久久久久福利一牛影视| 欧美大片在线看免费观看| 国产日韩欧美综合一区| 一区二区三区回区在观看免费视频 | 免费看av成人| 久久婷婷国产麻豆91天堂| 国产精品美女久久久久久免费| 夜色激情一区二区| 中国成人在线视频| 国产精品igao视频网网址不卡日韩| 亚洲欧洲日韩女同| 一本到高清视频免费精品| 欧美巨乳在线| 一区二区日韩伦理片| 午夜精品一区二区三区在线视| 国产手机视频一区二区| 亚洲破处大片| 欧美 亚欧 日韩视频在线| 久久精品女人| 国产一区二区三区在线播放免费观看| 一区二区黄色| 午夜精品偷拍| 国产一区激情| 老巨人导航500精品| 亚洲国产女人aaa毛片在线| 一区二区高清视频| 国产女精品视频网站免费| 久久精品理论片| 欧美激情亚洲国产| 制服丝袜激情欧洲亚洲| 国产精品theporn| 亚洲一区二区三| 久久久久久久久久久成人| 亚洲国产精品激情在线观看| 欧美日韩国产一中文字不卡| 亚洲一区二区三区成人在线视频精品| 久久精品一本| 亚洲精品视频免费在线观看| 国产精品高清在线| 久久久精品国产免大香伊| 亚洲精品黄网在线观看| 亚洲欧美在线一区二区| 黄色日韩网站| 欧美午夜国产| 久久久久久婷| 亚洲开发第一视频在线播放| 欧美一区二区三区日韩| 亚洲人成人一区二区三区| 国产精品高潮视频| 麻豆成人综合网| 亚洲主播在线观看| 亚洲激情一区二区| 久久精品国产精品| 一区二区久久| 在线播放亚洲| 国产精品一区二区男女羞羞无遮挡 | 欧美视频一区二区三区四区| 久久精品国内一区二区三区| 99视频一区| 欧美国产国产综合| 欧美一区二区三区在线| 亚洲人成网站777色婷婷| 国产精品影音先锋| 欧美国产第一页| 久久精品国产一区二区三区免费看 | 久久久噜噜噜久久中文字幕色伊伊| 亚洲国产视频a| 蘑菇福利视频一区播放| 久久狠狠一本精品综合网| 亚洲少妇自拍| 一本大道av伊人久久综合| 亚洲国产婷婷综合在线精品| 国产欧美日韩在线播放| 国产精品v欧美精品v日本精品动漫 | 欧美成人久久| 一区二区日本视频|