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

隨筆 - 60, 文章 - 0, 評(píng)論 - 197, 引用 - 0
數(shù)據(jù)加載中……

淺析遠(yuǎn)程過(guò)程調(diào)用 RPC

一、什么是遠(yuǎn)程過(guò)程調(diào)用

  什么是遠(yuǎn)程過(guò)程調(diào)用 RPC(Remote Procedure Call)? 你可能對(duì)這個(gè)概念有點(diǎn)陌生, 而你可能非常熟悉 NFS, 是的,
NFS 就是基于 RPC 的. 為了理解遠(yuǎn)程過(guò)程調(diào)用,我們先來(lái)看一下過(guò)程調(diào)用。

  所謂過(guò)程調(diào)用,就是將控制從一個(gè)過(guò)程 A 傳遞到另一個(gè)過(guò)程 B, 返回時(shí)過(guò)程 B 將控制進(jìn)程交給過(guò)程 A。目前大多數(shù)系統(tǒng)
中, 調(diào)用者和被調(diào)用者都在給定主機(jī)系統(tǒng)中的一個(gè)進(jìn)程中, 它們是在生成可執(zhí)行文件時(shí)由鏈接器連接起來(lái)的, 這類(lèi)過(guò)程調(diào)用稱(chēng)
為本地過(guò)程調(diào)用。

  遠(yuǎn)程過(guò)程調(diào)用(RPC)指的是由本地系統(tǒng)上的進(jìn)程激活遠(yuǎn)程系統(tǒng)上的進(jìn)程, 我們將此稱(chēng)為過(guò)程調(diào)用是因?yàn)樗鼘?duì)程序員來(lái)說(shuō)表現(xiàn)
為常規(guī)過(guò)程調(diào)用。處理遠(yuǎn)程過(guò)程調(diào)用的進(jìn)程有兩個(gè), 一個(gè)是本地客戶(hù)進(jìn)程, 一個(gè)是遠(yuǎn)程服務(wù)器進(jìn)程。對(duì)本地進(jìn)程來(lái)說(shuō), 遠(yuǎn)程過(guò)
程調(diào)用表現(xiàn)這對(duì)客戶(hù)進(jìn)程的控制, 然后由客戶(hù)進(jìn)程生成一個(gè)消息, 通過(guò)網(wǎng)絡(luò)系統(tǒng)調(diào)用發(fā)往遠(yuǎn)程服務(wù)器。網(wǎng)絡(luò)信息中包括過(guò)程調(diào)
用所需要的參數(shù), 遠(yuǎn)程服務(wù)器接到消息后調(diào)用相應(yīng)過(guò)程, 然后將結(jié)果通過(guò)網(wǎng)絡(luò)發(fā)回客戶(hù)進(jìn)程, 再由客戶(hù)進(jìn)程將結(jié)果返回給調(diào)用
進(jìn)程。因此, 遠(yuǎn)程系統(tǒng)調(diào)用對(duì)調(diào)用者表現(xiàn)為本地過(guò)程調(diào)用, 但實(shí)際上是調(diào)用了遠(yuǎn)程系統(tǒng)上的過(guò)程。


二、遠(yuǎn)程過(guò)程調(diào)用模型

  本地過(guò)程調(diào)用: 一個(gè)傳統(tǒng)程序由一個(gè)或多個(gè)過(guò)程組成。它們往往按照一種調(diào)用等級(jí)來(lái)安排。如下圖所示:


  遠(yuǎn)程過(guò)程調(diào)用: 使用了和傳統(tǒng)過(guò)程一樣的抽象, 只是它允許一個(gè)過(guò)程的邊界跨越兩臺(tái)計(jì)算機(jī)。如下圖所示:


三、遠(yuǎn)程過(guò)程和本地過(guò)程的對(duì)比

  首先, 網(wǎng)絡(luò)延時(shí)會(huì)使一個(gè)遠(yuǎn)程過(guò)程的開(kāi)銷(xiāo)遠(yuǎn)遠(yuǎn)比本地過(guò)程要大
  其次, 傳統(tǒng)的過(guò)程調(diào)用因?yàn)楸徽{(diào)用過(guò)程和調(diào)用過(guò)程運(yùn)行在同一塊內(nèi)存空間上, 可以在過(guò)程間傳遞指針。而遠(yuǎn)程過(guò)程不能夠?qū)?br>指針作為參數(shù), 因?yàn)檫h(yuǎn)程過(guò)程與調(diào)用者運(yùn)行在完全不同的地址空間中。
  再次, 因?yàn)橐粋€(gè)遠(yuǎn)程調(diào)用不能共享調(diào)用者的環(huán)境, 所以它就無(wú)法直接訪問(wèn)調(diào)用者的 I/O 描述符或操作系統(tǒng)功能。


四、遠(yuǎn)程過(guò)程調(diào)用的幾種版本 
  (1) Sun RPC (UDP, TCP)
  (2) Xerox Courier (SPP)
  (3) Apollo RPC (UDP, DDS)

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

五、如何編寫(xiě)遠(yuǎn)程過(guò)程調(diào)用程序
 
  為了將一個(gè)傳統(tǒng)的程序改寫(xiě)成 RPC 程序, 我們要在程序里加入另外一些代碼, 這個(gè)過(guò)程稱(chēng)作 stub 過(guò)程。我們可以想象一
個(gè)傳統(tǒng)程序, 它的一個(gè)過(guò)程被轉(zhuǎn)移到一個(gè)遠(yuǎn)程機(jī)器中。在遠(yuǎn)程過(guò)程一端, stub 過(guò)程取代了調(diào)用者。這樣 stub 實(shí)現(xiàn)了遠(yuǎn)程過(guò)
程調(diào)用所需要的所有通信。因?yàn)?stub 與原來(lái)的調(diào)用使用了一樣的接口, 因此增加這些 stub 過(guò)程既不需要更改原來(lái)的調(diào)用過(guò)
程, 也不要求更改原來(lái)的被調(diào)用過(guò)程。如下圖所示:

 


六、示例
    此示例在 Ubuntu 8.04 + gcc 4.2.3 下編譯運(yùn)行通過(guò)。

    遠(yuǎn)程過(guò)程調(diào)用示例(點(diǎn)擊下載)

posted on 2008-08-15 17:02 Normandy 閱讀(15187) 評(píng)論(12)  編輯 收藏 引用 所屬分類(lèi): Networking

評(píng)論

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC[未登錄](méi)  回復(fù)  更多評(píng)論   

RPC的優(yōu)勢(shì)在哪里?
2008-08-15 17:56 | achilles

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

@achilles
優(yōu)點(diǎn)是可直接訪問(wèn)遠(yuǎn)程過(guò)程,避免煩瑣的打包和解包過(guò)程,且不依賴(lài)于某種特定的協(xié)議
2008-08-15 18:40 | Normandy

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC[未登錄](méi)  回復(fù)  更多評(píng)論   

@Normandy
可是這些過(guò)程為什么非要放到不同的機(jī)器呢,與普通的網(wǎng)絡(luò)通信相比RPC有什么優(yōu)勢(shì)?
2008-08-15 20:38 | achilles

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

@achilles
優(yōu)點(diǎn)是可直接訪問(wèn)遠(yuǎn)程過(guò)程,避免煩瑣的打包和解包過(guò)程,且不依賴(lài)于某種特定的協(xié)議
===================
顯然你就是看的皮毛
底層仍然通過(guò)打包解包實(shí)現(xiàn)
你沒(méi)聽(tīng)說(shuō)過(guò)marshall這個(gè)詞?
這只不過(guò)是打包的另一種說(shuō)法罷了。。。
2008-08-15 21:05 | 訪客

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

遠(yuǎn)程過(guò)程調(diào)用的使用領(lǐng)域太廣泛了,以后要是能不聯(lián)機(jī)就能定時(shí)生成或采集數(shù)據(jù)就更好了。
2008-08-17 17:46 | dell筆記本

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

@achilles
將一些過(guò)程放在遠(yuǎn)程是分布式程序的要求,如客戶(hù)機(jī)/服務(wù)器模式。相比常規(guī)的網(wǎng)絡(luò)通信程序而言,在用 RPC 時(shí)我們只需要關(guān)心程序本身的邏輯,就像建本地程序一樣,因?yàn)?RPC 已經(jīng)幫你做了網(wǎng)絡(luò)通信的工作!

如果你還是不能理解, 請(qǐng)下載我上面的遠(yuǎn)程過(guò)程調(diào)用示例,將客戶(hù)程序和服務(wù)程序放在兩個(gè)不同的機(jī)器上運(yùn)行看看。

如果你想了解更多的細(xì)節(jié),請(qǐng)看一下 <<Linux 網(wǎng)絡(luò)編程>> 第十二章,上面的內(nèi)容更精彩!
2008-08-18 10:13 | Normandy

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

[薦]RPC is bad?
偶像 Steve Vinoski 在 maillist 的回帖中一不留神就泄漏了他為 ErlangeXchange 準(zhǔn)備的 session ,我們可以先一睹為快。Steve 大拿是 CORBA 界的牛人,對(duì) RPC 是 bad 很有發(fā)言權(quán)地。這篇文章也寫(xiě)得很漂亮,水分相當(dāng)少,我就不干“損失味道”的事情了。
為方便閱讀,將 mail 內(nèi)容盜版如下:
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: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

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: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

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

而使用RPC,Client可以遠(yuǎn)程啟動(dòng)Server端的程序。
2008-09-07 10:41 | 訪客

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

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

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

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

RPC雖然對(duì)網(wǎng)絡(luò)依賴(lài),但是對(duì)于中間件技術(shù)來(lái)說(shuō)還是蠻贊的技術(shù)。
2009-12-03 21:06 | kaholi

# re: 淺析遠(yuǎn)程過(guò)程調(diào)用 RPC  回復(fù)  更多評(píng)論   

你將得非常的好.謝謝你
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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久久久久久麻豆网| 免费成人黄色片| 亚洲经典三级| 欧美日韩亚洲成人| 亚洲视频在线观看三级| 亚洲欧美视频一区二区三区| 国产日韩亚洲欧美| 老巨人导航500精品| 亚洲精选在线观看| 欧美伊人久久大香线蕉综合69| 狠狠色综合日日| 欧美岛国激情| 亚洲欧美日韩在线一区| 免费成年人欧美视频| 一区二区日韩| 国产综合欧美| 欧美日韩大陆在线| 羞羞色国产精品| 亚洲国产免费看| 亚洲欧美一区二区在线观看| 樱桃视频在线观看一区| 欧美日韩视频免费播放| 欧美专区日韩视频| 亚洲麻豆视频| 女同一区二区| 欧美一级电影久久| 亚洲精选一区二区| 国产在线麻豆精品观看| 欧美日韩视频在线第一区| 久久精品水蜜桃av综合天堂| 亚洲精品一区二区三区樱花 | 亚洲精品乱码| 欧美午夜视频网站| 久久综合福利| 国产三级欧美三级日产三级99| 欧美一区成人| 国产精品私人影院| 欧美电影在线播放| 久久精品欧美日韩| 亚洲一区三区视频在线观看| 亚洲激情第一页| 久久影院午夜片一区| 亚洲在线视频| 中文av字幕一区| 亚洲精品美女在线观看| 韩曰欧美视频免费观看| 国产精品一区二区三区乱码| 欧美日韩免费一区二区三区| 欧美成人免费一级人片100| 久久不射电影网| 亚洲综合视频网| 宅男精品视频| 999亚洲国产精| 亚洲日本欧美日韩高观看| 欧美激情久久久| 牛夜精品久久久久久久99黑人 | 欧美激情精品久久久久久免费印度| 欧美一区二区日韩| 亚洲欧美经典视频| 亚洲女爱视频在线| 亚洲一区二区三区三| 一区二区三区欧美视频| 99re成人精品视频| 亚洲人成免费| 99re6这里只有精品视频在线观看| 91久久久一线二线三线品牌| 最新日韩欧美| 亚洲精品视频在线| 亚洲免费精品| 一本色道久久88亚洲综合88| 夜夜爽99久久国产综合精品女不卡 | 久热精品视频在线观看一区| 久久久久久久网| 久久精品视频va| 午夜精品久久久久久久蜜桃app | 欧美成人精品一区二区| 亚洲精品乱码视频| 日韩亚洲不卡在线| 一区二区三区久久精品| 亚洲小视频在线| 亚洲欧美成人| 久久国产精品一区二区三区四区| 久久久久国产一区二区三区| 麻豆久久久9性大片| 欧美v日韩v国产v| 亚洲日本中文字幕| 亚洲视频一区二区在线观看| 午夜精品久久久久久99热软件| 欧美一区日本一区韩国一区| 久久久精品日韩| 欧美激情一区二区三区蜜桃视频 | 国产伦精品一区二区三区免费 | 亚洲尤物在线| 午夜视频在线观看一区| 久久精品综合网| 欧美激情日韩| 一区二区三区四区五区视频| 午夜精品久久久久久久99黑人| 久久大综合网| 欧美裸体一区二区三区| 国产精品亚洲综合| 1000精品久久久久久久久| 一本色道婷婷久久欧美| 欧美一区=区| 欧美成人激情视频免费观看| 亚洲精品综合在线| 久久大香伊蕉在人线观看热2| 欧美二区乱c少妇| 国产精品一区在线观看| 亚洲高清视频的网址| 亚洲一区欧美二区| 免费欧美在线视频| 一区二区三区日韩欧美| 久久综合999| 国产精品一区二区三区乱码 | 欧美日韩中文字幕在线视频| 国产伦精品一区二区三区视频黑人| 伊人精品久久久久7777| 亚洲少妇在线| 欧美va天堂| 亚洲综合清纯丝袜自拍| 欧美激情精品久久久久久蜜臀 | 一区二区三区免费网站| 久久免费高清| 中国日韩欧美久久久久久久久| 久久亚洲春色中文字幕| 国产精品一区久久久久| 亚洲另类自拍| 欧美大片18| 久久国产精品一区二区| 国产精品99一区| 亚洲精品日韩精品| 六月丁香综合| 午夜精品福利在线观看| 欧美视频一区二区三区四区| 亚洲三级视频在线观看| 久久久中精品2020中文| 亚洲欧美成人| 国产精品久久| 亚洲夜间福利| 亚洲精品自在在线观看| 欧美成人免费网站| 亚洲高清不卡在线| 老鸭窝亚洲一区二区三区| 亚洲欧美日韩国产| 国产精品久久久一区二区三区| 一区二区av在线| 亚洲国产日韩欧美在线图片 | 99精品视频一区| 亚洲国产日韩一区| 男人的天堂亚洲在线| 亚洲韩国一区二区三区| 蜜桃久久av一区| 久久久一区二区三区| 合欧美一区二区三区| 久久久久久穴| 久久精品一区二区三区不卡牛牛| 国产伦精品一区二区三区四区免费| 亚洲欧美久久久| 亚洲永久精品大片| 国产精品日日做人人爱| 性亚洲最疯狂xxxx高清| 亚洲女同性videos| 国产视频一区在线观看| 久久激情一区| 久久久久欧美精品| 亚洲国产天堂久久综合| 亚洲国产经典视频| 欧美精品一区二区三区蜜臀 | 午夜精品一区二区三区电影天堂| 国产精品亚发布| 久久国产精品99精品国产| 午夜亚洲视频| 在线看国产日韩| 亚洲第一视频| 欧美视频1区| 欧美一区二区三区在线播放| 欧美在线影院| 亚洲国产成人精品视频| 亚洲激情视频在线| 欧美日韩在线看| 欧美一区二区免费视频| 久久精品国产综合精品| 亚洲人成人99网站| 99精品欧美一区| 国产三区二区一区久久| 免费观看30秒视频久久| 欧美人在线观看| 欧美影院在线| 免费日韩成人| 亚洲欧美另类在线| 久久久久久久欧美精品| 一区二区三区免费看| 亚洲欧美久久| 亚洲黄色三级| 亚洲欧美久久| 亚洲人人精品| 欧美一区二区三区免费大片| 亚洲国产一二三|