想搭建起来paxos算法看看源代码,跑一下试试。从这个地址下载了LibPaxos3
https://bitbucket.org/sciascid/libpaxos/overview
又从这个地址下载了cmake
https://cmake.org/download/
放到rhel5.5 64bit下,还需要libevent、messagepack。也可选支持LMDB。
其中
(1)
libevent是个异步事件回调封装。支持epoll、select、poll等模式;支持定时器、IO、信号等事件。看起来很好用,回头一定要写几个简单程序测试下。
下载地址 http://libevent.org/
下载了libevent-2.0.22-stable.tar。
./configure
make && make install
路径/root/libevent/libevent-2.0.22-stable
(2)
messagepack是个跨平台的序列化库,号称比json升成的数据小,速度又非常快。下载要注册,也值得用一下试试。
下载地址 https://github.com/msgpack/msgpack-c
需要cmake来产生Makefile。
过程
cmake .
sodo make install
(3)
lmdb是个快速KV库。比leveldb快15%。内存占用比leveldb大。比leveldb的优点是支持多进程同时读取。不过这个是共享软件,只有rpm下,值得在生产环境里测试下。
这里我们不用。
世界的科技进步还真是要靠美国。以上这些都是美国的公司搞出来并开源(或者部分开源)了,国人都是拿来主义。相比之下。国内的BAT的共享太少了,特别是腾讯。
解压paxos
[root@rel5 sciascid-libpaxos-d255f8b67a32]# ll
total 44
-rw-r--r-- 1 root root 516 May 10 2016 CMakeLists.txt
-rw-r--r-- 1 root root 1517 May 10 2016 COPYING
-rw-r--r-- 1 root root 2567 May 10 2016 README.md
drwxr-xr-x 2 root root 4096 May 10 2016 cmake
drwxr-xr-x 3 root root 4096 May 10 2016 evpaxos
drwxr-xr-x 3 root root 4096 May 10 2016 paxos
-rw-r--r-- 1 root root 1809 May 10 2016 paxos.conf
drwxr-xr-x 2 root root 4096 May 10 2016 sample
-rwxr-xr-x 1 root root 878 May 10 2016 tmux-test.sh
drwxr-xr-x 4 root root 4096 May 10 2016 unit
drwxr-xr-x 3 root root 4096 May 10 2016 utils
cmake .
make
自此编译完成。
测试试试。
[root@rel5 sciascid-libpaxos-d255f8b67a32]# ll sample/
total 140
drwxr-xr-x 8 root root 4096 Dec 11 16:53 CMakeFiles
-rw-r--r-- 1 root root 610 May 10 2016 CMakeLists.txt
-rw-r--r-- 1 root root 14565 Dec 11 16:53 Makefile
-rwxr-xr-x 1 root root 9945 Dec 11 16:54 acceptor
-rw-r--r-- 1 root root 2620 May 10 2016 acceptor.c
-rwxr-xr-x 1 root root 16224 Dec 11 16:54 client
-rw-r--r-- 1 root root 8101 May 10 2016 client.c
-rw-r--r-- 1 root root 1439 Dec 11 16:53 cmake_install.cmake
-rwxr-xr-x 1 root root 12838 Dec 11 16:54 counter
-rw-r--r-- 1 root root 5503 May 10 2016 counter.c
-rwxr-xr-x 1 root root 9923 Dec 11 16:54 learner
-rw-r--r-- 1 root root 2909 May 10 2016 learner.c
-rwxr-xr-x 1 root root 9945 Dec 11 16:54 proposer
-rw-r--r-- 1 root root 2626 May 10 2016 proposer.c
-rwxr-xr-x 1 root root 10599 Dec 11 16:54 replica
-rw-r--r-- 1 root root 3560 May 10 2016 replica.c