1 / 16

FastDHT ---- 分布式 Hash 系统

FastDHT ---- 分布式 Hash 系统. 余庆 2009-6-18. FastDHT 简介. 分布式 hash 系统,存储 Key Value Pair 支持两种存储方式 缓存方式的 MPOOL 持久存储方式的 BDB Key 包括三部分: Namespace ObjectID Key Key 可设置过期时间,自动清除过期数据 Server 端划分 group ,同 group 数据互相备份,并且可自动压缩 binlog 服务端可使用单线程,多线程模式. FastDHT 一些特性. 虚拟 farm ,便于扩容

pippa
Download Presentation

FastDHT ---- 分布式 Hash 系统

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FastDHT ----分布式Hash系统 余庆 2009-6-18

  2. FastDHT简介 • 分布式hash系统,存储Key Value Pair • 支持两种存储方式 • 缓存方式的MPOOL • 持久存储方式的BDB • Key包括三部分: • Namespace • ObjectID • Key • Key可设置过期时间,自动清除过期数据 • Server端划分group,同group数据互相备份,并且可自动压缩binlog • 服务端可使用单线程,多线程模式

  3. FastDHT一些特性 • 虚拟farm,便于扩容 • 分布式算法client端实现,不需要中心服务器 • 二进制通信协议,支持Proxy • 使用libevent,异步IO方式,支持大并发 • 自动failover • 支持长连接

  4. FastDHT通信协议 • typedef struct • { • char pkg_len[FDHT_PROTO_PKG_LEN_SIZE]; //body length • char key_hash_code[FDHT_PROTO_PKG_LEN_SIZE]; //the key hash code • char timestamp[FDHT_PROTO_PKG_LEN_SIZE]; //current time • /* key expires, remain timeout = expires - timestamp */ • char expires[FDHT_PROTO_PKG_LEN_SIZE]; • char cmd; • char keep_alive; • char status; • } FDHTProtoHeader;

  5. 长连接与短连接 • 短连接 • 每次请求需要重新连接服务器 • 长连接 • 将连接保存,进程没有停止、连接没有断掉就可以重复使用 • 断掉重连 • 需要设置SO_KEEPALIVE、TCP_NODELAY

  6. Client端分布算法

  7. 如何根据Key进行分布? • 读写分布算法相同 • 计算key的hash code • 由hash code决定分布到哪个组: group_index = hash_code % group_count • 计算新的hash code,决定分布到哪台机器: • new_hash_code = (hash_code << 16) | (hash_code >> 16) • server_index = new_hash_code % server_count_in_the_group

  8. Server流程

  9. BDB存储方式 • 建议采用虚拟farm,便于今后扩容 • 记录binlog,同group数据互备 • 持久存储

  10. MPOOL存储方式 • 全部存储于内存中 • 采用Hash Table • 各个server建议不进行互备,所有server配置到一个group中 • 对每个key可以设置过期时间,定期清除和临界点触发式清除两种方式 • 内存使用自动扩展 • 内存使用到达上限返回错误 • 强制单线程模式???

  11. FastDHT和Memcachedb对比

  12. FastDHT和Memcached对比

  13. 服务器列表配置示例 • fdht_servers.conf(2×2): • group_count = 2 • group0 = 192.168.209.107:11411 • group0 = 192.168.209.108:11411 • group1 = 192.168.209.107:11411 • group1 = 192.168.209.108:11411

  14. 服务器端配置示例 • bind_addr= • port=11411 • network_timeout=60 • base_path=/home/yuqing/fastdht • max_connections=32 • max_threads=32 • max_pkg_size=64KB • min_buff_size=64KB • store_type = MPOOL • cache_size = 32MB • … • mpool_init_capacity = 10000 • mpool_load_factor = 0.75 • mpool_clear_min_interval = 30 • … • sync_log_buff_interval=10 • sync_db_time_base=00:00 • sync_db_interval=86400 • write_to_binlog=0 • sync_binlog_buff_interval=60 • clear_expired_time_base=04:00 • clear_expired_interval=86400 • … • compress_binlog_time_base=02:00 • compress_binlog_interval=86400 • #include fdht_servers.conf

  15. 客户端配置实示例 • network_timeout=60 • keep_alive=1 • base_path=/home/yuqing/fastdht • log_level=info • use_proxy=0 • proxy_addr=127.0.0.1 • proxy_port=12200 • #include fdht_servers.conf

  16. PHP配置实示例 • extension = fastdht_client.so • fastdht_client.network_timeout=60 • fastdht_client.base_path=/home/yuqing/fastdht • fastdht_client.log_level=info • fastdht_client.log_filename= • fastdht_client.config_count = 2 • fastdht_client.config_file0 = /home/yuqing/fastdht/conf/fdht_client.conf • fastdht_client.config_file1 = /home/yuqing/fastdht/conf/fdht_client.conf

More Related