組通信之jgroups篇----jgroups綜述

 

Group communication uses the terms group and member. Members are part of a group. In the more common terminology,a member is a node and a groups is a cluster. We use these words interchangeably.

我們在組通信中使用術語組和成員.成員是組的一部分.成員是節點而組是集羣.

 

A node is a process, residing on some host. A cluster can have one or more nodes belonging to it. There can be multiple nodes on the same host, and all may or may not be part of the same cluster.

節點是一個主機上的一個進程,一個集羣可以有一個或多個節點.在一臺機器上可以有多個節點,這些節點可以全部屬於一個集羣,也可以部分屬於一個集羣.

 

JGroups is toolkit for reliable group communication. Processes can join a group, send messages to all members or single members and receive messages from members in the group. The system keeps track of the members in every group, and notifies group members when a new member joins, or an existing member leaves or crashes. A group is identified by its name. Groups do not have to be created explicitly; when a process joins a non-existing group, that group will be created automatically. Member processes of a group can be located on the same host, within the same LAN, or across a WAN. A member can be part of multiple groups.

Jgroups是一個組通信組件.進程可以加入一個組,發送消息到所有成員或單個成員,並接受來自組內成員的消息.程序追蹤每個組內的每個成員,但有成員加入,退出或毀壞時組內各個成員都會得到通知.組以其組名爲標記,組的創建不必顯示,當進程加入一個不存在的組時,組即可自動被創建.組內成員所在進程可以位於同一臺機器上,也可位於局域網或廣域網.一個成員同時可以屬於多個組.

 

 

The architecture of JGroups is shown in Figure 1.1.

 

It consists of 3 parts: (1) the Channel API used by application programmers to build reliable group communication applications, (2) the building blocks, which are layered on top of the channel and provide a higher abstraction level and (3) the protocol stack, which implements the properties specified for a given channel.

jgroups體系結構如圖1.1.

它包含3部分.1)channel API,用於程序員實現可靠的組通信應用程序.2)building blocks,位於通道的上層,提供更抽象的服務.3)協議棧,實現了通道的一些屬性.

 

 

 

This document describes how to install and use JGroups, ie. the Channel API and the building blocks. The targeted audience is application programmers who want to use JGroups to build reliable distributed programs that need group communication. Programmers who want to implement their own protocols to be used with JGroups should consult the Programmer's Guide for more details about the architecture and implementation of JGroups.

這篇文檔主要描述如何安裝和使用jgroups.最終的閱讀者是程序員,他們需要使用jgroups去實現基於組通信的分佈式應用程序.如果用戶要實現自己的協議棧,請參考用戶手冊去獲取更細節的有關jgruops體系結構和實現的內容.

 

A channel is connected to a protocol stack. Whenever the application sends a message, the channel passes it on to the protocol stack, which passes it to the topmost protocol. The protocol processes the message and the passes it on to the protocol below it. Thus the message is handed from protocol to protocol until the bottom protocol puts it on the network. The same happens in the reverse direction: the bottom (transport) protocol listens for messages on the network. When a message is received it will be handed up the protocol stack until it reaches the channel. The channel stores the message in a queue until the application consumes it.

channel連接到協議棧,用戶發送消息經過channel傳到協議棧,然後傳到最上層協議,該協議繼續將消息傳到下一協議,一直到該消息傳到最底層協議,通過網絡傳輸出去.同理,在最底層有協議監聽來自網絡上的消息,然後接受到消息並將他傳送到協議棧直到channel,channel保存消息到隊列直到應用程序來使用它.

 

When an application connects to the channel, the protocol stack will be started, and when it disconnects the stack will be stopped. When the channel is closed, the stack will be destroyed, releasing its resources.

The following three sections give an overview of channels, building blocks and the protocol stack.

當應用程序連接channel時,協議棧被啓動,當斷開連接時,協議棧被停止.當關閉連接時,協議棧被銷燬,並釋放相關資源.

下面三節分別給出了channel,building blocks和協議棧的綜述.

 

 

 

1.1. Channel

To join a group and send messages, a process has to create a channel and connect to it using the group name (all channels with the same name form a group). The channel is the handle to the group. While connected, a member may send and receive messages to/from all other group members. The client leaves a group by disconnecting from the channel. A channel can be reused: clients can connect to it again after having disconnected. However, a channel allows only 1 client to be connected at a time. If multiple groups are to be joined, multiple channels can be created and connected to. A client signals that it no longer wants to use a channel by closing it. After this operation, the channel cannot be used any longer.

加入一個組併發送消息,進程必須創建一個channel並用組名進行連接(所有有相同組名的channel組成一個組).channel相當於組的句柄.當已連接,成員可以發送和接收消息.成員通過斷開channel連接退出組.channel可以被重用.在斷開channel後可以再次連接.但是,1個channel只允許一個客戶端連接.當需要加入多個組,則必須創建多個channel並進行連接.當關閉一個channel時,一般以爲着我們不再想使用它.

 

Each channel has a unique address. Channels always know who the other members are in the same group: a list of member addresses can be retrieved from any channel. This list is called a view. A process can select an address from this list and send a unicast message to it (also to itself), or it may send a multicast message to all members of the current view. Whenever a process joins or leaves a group, or when a crashed process has been detected, a new view is sent to all remaining group members. When a member process is suspected of having crashed, a suspicion message is received by all non-faulty members. Thus, channels receive regular messages, view messages and suspicion messages. A client may choose to turn reception of views and suspicions on/off on a channel basis.

每個channel有一個地址.channel總是知道組內其他成員有哪些.我們可以從任何一個channel獲得成員地址列表,該列表稱爲view.進程可以選擇表中某個地址發送單播消息(也可以發給自己),同樣可以發送組播消息到該view的所有成員.但某個進程加入或離開組,或進程異常被檢測出,一個新的view會發送到組內所有剩餘的成員.當某個成員所在進程被懷疑有異常,一個猜疑消息亦會被其他沒失敗的成員接收到.所以,channel會接收到規則消息,視圖消息和懷疑消息.客戶端可以基於channel的設置關閉和開啓接收視圖消息和懷疑消息.

 

Channels are similar to BSD sockets: messages are stored in a channel until a client removes the next one (pull-principle). When no message is currently available, a client is blocked until the next available message has been received.

channel類似於BSD套接字.消息被存儲在channel中直到被客戶端移走.噹噹前沒消息可用時,客戶端會被阻塞知道下一個可用消息被接收到.

 

There is currently only one implementation of Channel: JChannel.

The properties of a channel are typically defined in an XML file, but JGroups also allows for configuration through simple strings, URIs, DOM trees or even programming.

The Channel API and its related classes is described in Chapter 3.

當前只有一種channel實現:JChannel.

channel的屬性一般定義在一個XML文件中.當然,jgroups也支持其他的配置.

channel API和它相關的類我們將在第三章細說.

 

 

 

1.2. Building Blocks

Channels are simple and primitive. They offer the bare functionality of group communication, and have on purpose been designed after the simple model of BSD sockets, which are widely used and well understood. The reason is that an application can make use of just this small subset of JGroups, without having to include a whole set of sophisticated classes, that it may not even need. Also, a somewhat minimalistic interface is simple to understand: a client needs to know about 12 methods to be able to create and use a channel (and oftentimes will only use 3-4 methods frequently).

channels是簡單的,原始的實現,它提供組通信的最基本功能,其設計的目標就是基於BSD套接字的簡單模型,能被很好的理解並可廣泛使用.因爲許多應用程序只需要使用JGroups的這些小的子集功能,而不需要包含一整套的複雜的類,而且,簡單的接口也易於被理解:一個客戶端只需要知道12個創建和使用channel的方法(更多的時候只需要常用的3-4個).

 

Channels provide asynchronous message sending/reception, somewhat similar to UDP. A message sent is essentially put on the network and the send() method will return immediately. Conceptual requests, or responses to previous requests, are received in undefined order, and the application has to take care of matching responses with requests.

channel提供異步的消息發送/接收,類似於UDP.消息的發送本質上是傳輸到網絡,發送函數即返回.迴應消息被接收的順序不確定,應用程序得自己區分響應消息和發送消息的對應關係.

 

Also, an application has to actively retrieve messages from a channel (pull-style); it is not notified when a message has been received. Note that pull-style message reception often needs another thread of execution, or some form of event-loop, in which a channel is periodically polled for messages.

另外,應用程序必須主動從channel中取數據,而不是當有消息被接收時主動通知應用程序.這種消息接收方式必須啓動另一個線程來處理,或者事件輪循機制,週期性的從channel取數據.

 

JGroups offers building blocks that provide more sophisticated APIs on top of a Channel. Building blocks either create and use channels internally, or require an existing channel to be specified when creating a building block. Applications communicate directly with the building block, rather than the channel. Building blocks are intended to save the application programmer from having to write tedious and recurring code, e.g. request-response correlation.

Building blocks are described in Chapter 4.

 

JGroups的building blocks方式在基於channel之上提供了更復雜的API.building blocks在內部創建使用channel,或者需要一個已經存在的channel去創建building blocks.應用程序直接與building blocks通信而不再是和channel通信.building blocks可以將應用程序員從編寫單調重複的代碼中解放出來,如請求-迴應關係代碼.

building blocks將在第四章中詳細介紹.

 

 

1.3. The Protocol Stack

The protocol stack containins a number of protocol layers in a bidirectional list. All messages sent and received over the channel have to pass through the protocol stack. Every layer may modify, reorder, pass or drop a message, or add a header to a message. A fragmentation layer might break up a message into several smaller messages, adding a header with an id to each fragment, and re-assemble the fragments on the receiver's side.

協議棧在雙向列表中有一系列的協議層.所有通過channel發送和接收的消息都必須經過協議棧.每個協議層都可以修改,記錄,傳遞或丟棄某個消息,或增加消息頭等等.分裂協議層則可以將消息分成幾個更小的消息並在每個小消息上加一個頭,然後在接收端重新組裝這些片段.

 

The composition of the protocol stack, i.e. its layers, is determined by the creator of the channel: an XML file defines the layers to be used (and the parameters for each layer). This string might be interpreted differently by each channel implementation; in JChannel it is used to create the stack, depending on the protocol names given in the property.

組成協議棧的協議層,是由channel創建者決定的,其配置的xml文件定義了要使用的各協議層(以及各協議層參數).這些配置屬性對每個channel的實現可能不同,JChannel的實現中,協議棧的創建是根據屬性中的協議名而來的.

 

Knowledge about the protocol stack is not necessary when only using channels in an application. However, when an application wishes to ignore the default properties for a protocol stack, and configure their own stack, then knowledge about what the individual layers are supposed to do is needed. Although it is syntactically possible to stack any layer on top of each other (they all have the same interface), this wouldn't make sense semantically in most cases.

 

如果僅僅是在應用程序中使用協議棧,那有關協議棧的知識可以不瞭解.但是,當一個應用程序不想使用默認的協議棧而想配置一個自己的協議棧,則有關每個協議的相關知識還是需要了解的.雖然語法上每個協議可以隨意配置,當大部分情況下在語意上可能並不正確.

 

 

 

發佈了38 篇原創文章 · 獲贊 10 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章