av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Apache Mesos底層基礎庫

1. Protocol buffer

創(chuàng)新互聯(lián)專注于開江企業(yè)網站建設,響應式網站開發(fā),商城網站建設。開江網站建設公司,為開江等地區(qū)提供建站服務。全流程按需設計,專業(yè)設計,全程項目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務

Protocal Buffer是google開源的用于數據交換的庫,常用于跨語言的數據訪問,擔任的角色一般為對象的序列化/反序列化。 另一個與之類似的開源軟件是facebook開源的thrift,它們兩個最大區(qū)別是thrift提供了自動生成RPC的功能而Protocal Buffer需要自己實現(xiàn),但Protocal Buffer的一個優(yōu)勢是其序列化/反序列化非常高效。

2. Libprocess

libprocess是采用C/C++編寫的高效消息傳遞編程模型(基于消息傳遞的網絡通信模型,而不是RPC),由伯克利開源。 其整個實現(xiàn)非常簡單,包括最基本的消息發(fā)送和接收等。

2.1 Libprocess模型

在mesos中,主要有四個角色,分別是:mesos-master,mesos-slave,framework(Hadoop/Spark /MPI等) scheduler,executor(在mesos-slave上執(zhí)行framework task的組件),每種角色均是一個Process,在實現(xiàn)時會繼承l(wèi)ibprocess中的ProtobufProcess類(它又繼承了 Process類),這樣,它們均會編成一個后臺運行且不斷監(jiān)聽protocal buffer消息的socket server,如下圖所示:

2.2 各種常用函數

Libprocess+protocol buffer組合是mesos最底層最重要的消息傳遞基礎庫(沒有采用RPC機制),由于該庫采用了基于Protocal Buffer消息傳遞的通信機制),因而非常高效。Mesos常用的兩個頭文件是libprocess\include\process下的 process.hpp和protobuf.hpp,這兩個提供了用于消息傳遞的API,其中process.hpp是最核心的文件,提供了原始的接口, 而protobuf.hpp是在process.hpp基礎上,加入了ProtocalBuffer對象參數,使ProtocalBuffer使用起來更 加容易。

(1) install

void install(void (T::*method)(P1C),P1 (M::*param1)() const);

安裝一個處理ProtocalBuffer消息的handler,其中,消息類型是M,該消息對應的處理函數是method,函數參數為M::*param1。舉例:mesos中slave/slave.cpp:

 
 
 
 
  1. install( 
  2.       &Slave::newMasterDetected, 
  3.       &NewMasterDetectedMessage::pid); 

安裝一個處理NewMasterDetectedMessage(ProtocalBuffer對象)的handler,mesos slave一旦接收到該消息,便會調用newMasterDetected函數處理, 且該函數的輸入參數是NewMasterDetectedMessage消息中的pid屬性。

 
 
 
 
  1. void install(const std::string& name,void (T::*method)(const UPID&, const std::string&)) 

安裝一個處理字符串的handler,也就是說,當收到字符串name后,調用函數method進行處理。這個API在mesos中的典型應用時維持master與slave之間的心跳,以確定彼此活著:

在slave/slave.cpp中:

 
 
 
 
  1. install("PING", &Slave::ping); 
  2.   
  3. void Slave::ping(const UPID& from, const string& body) 
  4.   send(from, "PONG"); 

在master/master.cpp中:

 
 
 
 
  1. install("PONG", &SlaveObserver::pong); 
  2.   void pong(const UPID& from, const string& body) 
  3.   { 
  4.     timeouts = 0; 
  5.     pinged = false; 
  6.   } 
  7.   void timeout() 
  8.   { 
  9.     if (pinged) { // So we haven't got back a pong yet ... 
  10.       if (++timeouts >= MAX_SLAVE_TIMEOUTS) { 
  11.         deactivate(); 
  12.         return; 
  13.       } 
  14.     } 
  15.     send(slave, "PING"); 
  16.     pinged = true; 
  17.     delay(SLAVE_PONG_TIMEOUT, self(), &SlaveObserver::timeout); 
  18.   } 

(2)send

 
 
 
 
  1. void send(const process::UPID& to, const google::protobuf::Message& message) 

向某個UPID上發(fā)送消息,其中UPID代表一個socket,里面含有ip和port信息,而消息message是ProtocalBuffer定義的對象。

(3) dispatch

 
 
 
 
  1. void dispatch(const UPID& pid, 
  2.   const std::tr1::shared_ptr >& f) 

執(zhí)行進程pid中的函數f,為了提高效率,該函數并不會等到函數f執(zhí)行完成,而是采用了異步的方法:將函數f放入一個函數隊列,由另外一個進程(或者多個)不斷從隊列中獲取函數,依次執(zhí)行。

(4) delay

 
 
 
 
  1. Timer delay(double secs,const PID& pid,void (T::*method)()) 

延遲secs秒調度進程pid中的方法method,并返回一個計數器,通過這個計時器,可取消該調度。

在mesos中,巧妙地通過該函數構造了一個無限循環(huán)以不斷檢測空閑資源,并將之分配給各個框架,代碼如下:

 
 
 
 
  1. void Master::initialize() { 
  2. …… 
  3.   timerTickTimer = delay(1.0, self(), &Master::timerTick); 
  4. void Master::timerTick() { 
  5.   …… 
  6.   timerTickTimer = delay(1.0, self(), &Master::timerTick); 

上面函數代碼段可完成每1s調用一次timerTick函數的功能。

3. Boost

非常有名的開源C++基礎庫,里面的STL非常高效方便,已被很多著名軟件采用。

4. Zookeeper

是一個針對大型分布式系統(tǒng)的可靠協(xié)調系統(tǒng),提供的功能包括:配置維護、名字服務、分布式同步、組服務等。 Mesos采用zookeeper解決master單點故障問題,使用zookeeper搭建一個master集群,當master出現(xiàn)故障時,選擇一個 standby master 變?yōu)閙aster。

5. glog

Google開源的C++日志庫,主用于C++程序中打印日志,打印格式如下:

I0411 17:26:54.150193 20653 main.cpp:111] Creating “process” isolation module

I0411 17:26:54.150400 20653 main.cpp:119] Build: 2012-04-11 16:50:21 by root

I0411 17:26:54.150658 20653 main.cpp:120] Starting Mesos slave

I0411 17:26:54.152981 20669 slave.cpp:191] Slave started on 123.145.2.2:34694

I0411 17:26:54.153024 20669 slave.cpp:192] Slave resources: cpus=2; mem=490

6. gmock

開源 C++ 單元測試框架

7. 參考資料

(1)Mesos主頁:http://www.mesosproject.org/index.html

(2)Mesos代碼:https://svn.apache.org/repos/asf/incubator/mesos/trunk/


當前名稱:Apache Mesos底層基礎庫
轉載注明:http://uogjgqi.cn/article/ccejjge.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流