PAXOS实现 —— libevent_paxos

该文章是项目的一部分。主要讲PAXOS算法的实现。                                                                        



 Qiushan, Shandong University

 Part I   Start     

 Part II  PAXOS

Part III  Architecture

Part IV  Performance

 Part V  Skills


Part I   Generated on November 15, 2014 (Start)

The libevent_paxos ensures that all replicas of an application(e.g., apache) receive a consistent total order of requests(i.e., socket operations) despite of a small number of replicas fail. That's why we used paxos.

To begin with, let's read Paxos Made Practical carefully. Below is a figure in it:

1)    In libevent_paxos, when a client connects with a PROXY via socket, then it sends a message ‘clientx:send’ to the proxy. When the connection is established, it will trigger a listener callback function called proxy_on_accept. Then when the message arrives at the proxy, it will trigger another listener callback function called client_side_on_read, the function will handle the message. Then client_process_data will be called, and in the function build_req_sub_msg will be invoked, it is responsible for building formal message (REQUEST_SUBMIT). Then the message will be sent to &proxy->sys_addr.c_addr,in another word, the corresponding consensus, the message will be sent to127.0.0.1:8000. And then the consensus will handle the coming message with handle_request_submit,handle_request_sumbit will invoke consensus_submit_request, if the current node is the leader, consensus_submit_request will use leader_handle_submit_req to combine the request message from the client with a view_stamp which is generated by function get_next_view_stamp. And then in leader_handle_submit_req, the new request message with type ACCEPT_REQ will be built by function build_accept_req, and then the message will be broadcasted to the other replicas via function uc (i.e.send_for_consensus_comp). In fact the process is just like the phase 1-2 of the following figure which cited from the paper Paxos Made Practical.

2)   In the figure, 3 is replicate_res which is the acknowledge that backups make after receiving the request information from the primary.In libevent_paxos, it should correspond to

handle_accept_req (src/consensus/consensus.c)

// build the reply to the leader
accept_ack* reply = build_accept_ack(comp,&msg->msg_vs);

After seeing build_accept_ack, we can find that what backups deliver to the primary is:

msg->node_id = comp->node_id;

msg->msg_vs = *vs;

msg->header.msg_type = ACCEPT_ACK;

which is similar to replicate_res in the paper:

So libevent_paxos also follows what Paxos Made Practical said.

Next for libevent_paxos should be execute the request after receiving a majority of replicas' acknowledge. The execution should be

handle_accept_ack

try_to_execute

leader_try_to_execute 

And how to send the ack to the primary, it is the function uc (a.k.a send_for_consensus_comp), let's see it.

// consensus part
static void send_for_consensus_comp(node* my_node,size_t data_size,void* data,int target){ consensus_msg* msg = build_consensus_msg(data_size,data);
if(NULL==msg){
goto send_for_consensus_comp_exit;
}
// means send to every node except me
if(target<0){
for(uint32_t i=0;i<my_node->group_size;i++){
if(i!=my_node->node_id && my_node->peer_pool[i].active){
struct bufferevent* buff = my_node->peer_pool[i].my_buff_event;
bufferevent_write(buff,msg,CONSENSUS_MSG_SIZE(msg));
SYS_LOG(my_node,
"Send Consensus Msg To Node %u\n",i);
}
}
}else{
if(target!=(int)my_node->node_id&&my_node->peer_pool[target].active){
struct bufferevent* buff = my_node->peer_pool[target].my_buff_event;
bufferevent_write(buff,msg,CONSENSUS_MSG_SIZE(msg));
SYS_LOG(my_node,
"Send Consensus Msg To Node %u.\n",target);
}
}
send_for_consensus_comp_exit:
if(msg!=NULL){
free(msg);
} return;
}

So, uc sees to delivering the message between the primary and the backups. For the same reason, when a client request arrives at the primary, the primary also uses uc (a.k.a send_for_consensus_comp) to broadcast the request information to backups.

3)  Next there is 4 left to be explained.

group_size = 3;

leader_try_to_execute
{
if(reached_quorum(record_data,comp->group_size))
{
SYS_LOG(comp,"Node %d : View Stamp%u : %u Has Reached Quorum.\n",…)
SYS_LOG(comp,"Before Node %d IncExecute %u : %u.\n",…)
SYS_LOG(comp,"After Node %d Inc Execute %u : %u.\n",…)
}
} static int reached_quorum(request_record*record,int group_size){
// this may be compatibility issue
if(__builtin_popcountl(record->bit_map)>=((group_size/2)+1)){
return 1;
}else{
return 0;
}
}

__builtin_popcountl which comes from GCC can calculate the number of 1 accurately.

So next we should pay attention to the data structure record->bit_map.

In concensus.c

typedef struct request_record_t{
struct timeval created_time; // data created timestamp
char is_closed;
uint64_t bit_map; // now we assume the maximal replica group size is 64;
size_t data_size; // data size
char data[0]; // real data
}__attribute__((packed))request_record;

Before our further exploration, let us suppose that the leader needs to use the bit_map to record that how many replicas has accepted the request that it proposed, and iff the number reaches the quorum (i.e. majority, i.e. (group_size/2)+1),the leader can execute the request. So based on the assumption, there must be a place where recording the number of ACCEPT ACK, and it should be after the leader has received the ACCEPT ACK messages which come from the other replicas.Let’s find the place, verifying our hypothesis.

consensus_handle_msg
{
case ACCEPT_ACK:
handle_accept_ack(comp,data)
{
update_record(record_data,msg->node_id)
{
record->bit_map= (record->bit_map | (1<<node_id));
//debug_log("the record bit map isupdated to %x\n",record->bit_map);
}
}
}

So our assumption is correct, and meanwhile through the expression

record->bit_map | (1<<node_id)

we could see that the number of 1 in record->bit_map is the number of replicas which has sent ACCEPT_ACK.


Evaluation Framework

  • Python script

./eval.py apache_ab.cfg

  • DEBUG Logs: proxy-req.log | proxy-sys.log | consensus-sys.log

node-0-proxy-req.log:

1418002395 : 1418002395.415361,1418002395.415362,1418002395.416476,1418002395.416476
Operation: Connects.

1418002395 : 1418002395.415617,1418002395.415619,1418002395.416576,1418002395.416576
Operation: Sends data: (START):client0:send:(END)

1418002395 : 1418002395.416275,1418002395.416276,1418002395.417113,1418002395.417113
Operation: Closes.

About proxy-req.log, what's the meaning of 1418002395 : 1418002395.415361,1418002395.415362,1418002395.416476,1418002395.416476

fprintf(output,"%lu : %lu.%06lu,%lu.%06lu,%lu.%06lu,%lu.%06lu\n",header->connection_id,
            header->received_time.tv_sec,header->received_time.tv_usec,
            header->created_time.tv_sec,header->created_time.tv_usec,
            endtime.tv_sec,endtime.tv_usec,endtime.tv_sec,endtime.tv_usec);

It shows the received time, created time and end time of the operation.

  • Google Spreadsheets

suites benchmark workload per client Server # Concurrency # Client # Requests # w/ proxy
consensus mean(us)
w/ proxy
consensus s.t.d.
w/ proxy
response mean(us)
w/ proxy
response s.t.d.
w/ proxy
throughput(Req/s)
w/ proxy
server mean(us)
w/ proxy
server throughput(Req/s)
w/o proxy
server mean(us)
w/o proxy
server throughput(Req/s)
overhead
mean(us)
notes
Mongoose Ab 10 3 10 100 5434 11784.4 12637 12137.4 12671 1125.57 6024 1660.03 1865 5361.93 4159  
Mongoose Ab 100 3 10 100 58384 9650.152 15138.11 9992.337 15145.30 2485.936 16216 616.69 1315 7605.72 14901  
Mongoose Ab 100 3 50 100 57812 17456.41 17694.93 18459.16 17518.62 5127.989 70611 708.1 5744 8704.74 64867  
Apache Ab 10 3 10 100
posted on
2017-08-03 15:26 
lxjshuju 
阅读(...) 
评论(...) 
编辑 
收藏

PAXOS: libevent_paxos的更多相关文章

  1. 分布式系列文章——Paxos算法原理与推导

    Paxos算法在分布式领域具有非常重要的地位.但是Paxos算法有两个比较明显的缺点:1.难以理解 2.工程实现更难. 网上有很多讲解Paxos算法的文章,但是质量参差不齐.看了很多关于Paxos的资 ...

  2. 分布式理论之一:Paxos算法的通俗理解

    维基的简介:Paxos算法是莱斯利·兰伯特(Leslie Lamport,就是 LaTeX 中的"La",此人现在在微软研究院)于1990年提出的一种基于消息传递且具有高度容错特性 ...

  3. 分布式系统理论进阶 - Paxos

    引言 <分布式系统理论基础 - 一致性.2PC和3PC>一文介绍了一致性.达成一致性需要面临的各种问题以及2PC.3PC模型,Paxos协议在节点宕机恢复.消息无序或丢失.网络分化的场景下 ...

  4. 分布式系统理论进阶 - Paxos变种和优化

    引言 <分布式系统理论进阶 - Paxos>中我们了解了Basic Paxos.Multi Paxos的基本原理,但如果想把Paxos应用于工程实践,了解基本原理还不够. 有很多基于Pax ...

  5. 【分布式】Zookeeper与Paxos

    一.前言 在学习了Paxos在Chubby中的应用后,接下来学习Paxos在开源软件Zookeeper中的应用. 二.Zookeeper Zookeeper是一个开源的分布式协调服务,其设计目标是将那 ...

  6. 【分布式】Chubby与Paxos

    一.前言 在上一篇理解了Paxos算法的理论基础后,接下来看看Paxos算法在工程中的应用. 二.Chubby Chubby是一个面向松耦合分布式系统的锁服务,GFS(Google File Syst ...

  7. 分布式一致性算法--Paxos

    Paxos算法是莱斯利·兰伯特(Leslie Lamport)1990年提出的一种基于消息传递的一致性算法.Paxos算法解决的问题是一个分布式系统如何就某个值(决议)达成一致.在工程实践意义上来说, ...

  8. Paxos

    Paxos算法原理与推导   Paxos算法在分布式领域具有非常重要的地位.但是Paxos算法有两个比较明显的缺点:1.难以理解 2.工程实现更难. 网上有很多讲解Paxos算法的文章,但是质量参差不 ...

  9. Zookeeper学习之:paxos算法

    paxos算法的重要性众所周知,它给如今的分布式一致性提供了迄今为止最好的解决方案.无论是Lamport自己的论文描述,还是网上的诸多资料,对paxos的描述都是及其简洁的,给人的感觉是paxos看似 ...

随机推荐

  1. Android NDK学习记录(一)

    一.NDK环境在Mac中部署 1.准备eclipse,android sdk安装包,android ndk安装包(http://dl.google.com/android/ndk/android-nd ...

  2. [C/C++]关于C++11中的std::move和std::forward

    http://www.cnblogs.com/cbscan/archive/2012/01/10/2318482.html http://blog.csdn.net/fcryuuhou/article ...

  3. javascript对于0的解读

      CreateTime--2017年6月29日10:36:01Author:Marydon javascript对于0的解读 1.0与“0” 1.1 判断0与"0"是否相等 测试 ...

  4. 带有key参数的函数filter,map,max,min

    内置函数———filter def is_not_empty(s): return s and len(s.strip()) > 0 filter(is_not_empty, ['test', ...

  5. 阿里云web播放器

    原文地址:https://help.aliyun.com/document_detail/51991.html?spm=5176.doc61109.6.703.ZTCYoi 一.概念说明 1. pla ...

  6. 使用Openssl创建证书

    概述 SSL证书通过在客户端浏览器和Web服务器之间建立一条SSL安全通道(Secure socketlayer(SSL),SSL安全协议主要用来提供对用户和服务器的认证:对传送的数据进行加密和隐藏: ...

  7. laravel的表单验证(下面有些信息未验证,转的)

    后台写法: 1.1类的方法 $rules = [ 'email'=>'required|between:4,20', 'password'=>'required|between:6,20' ...

  8. Failure [INSTALL_FAILED_OLDER_SDK] [每件问题100块]

    问题描述:链接真机时候出现的问题 解决问题: minSdkVersion 10targetSdkVersion 22 修改这两个值

  9. Sublime Text 编辑器 插件 之 "Sublime Alignment" 详解

    作者:shede333主页:http://my.oschina.net/shede333版权声明:原创文章,版权声明:自由转载-非商用-非衍生-保持署名 | [Creative Commons BY- ...

  10. maven下载源码和java docs

    方法一: mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc The first command will attem ...