from dbclient import Beansdb
s1 = "localhost:7100"
s2 = "localhost:7101"
BEANSDBCFG = {
s1: range(16),
s2: range(16),
}
key = 'txt:test'
db = Beansdb(BEANSDBCFG, 16)
b1 = Beansdb({s1: range(16)}, 16)
b2 = Beansdb({s2: range(16)}, 16)
for i in xrange(1000000,2000000):
print i
db.set('num:test%s'%i,'%sabcefdsfadslkjfjkdslfjlkdsjflkdsjkfldsjlkfjdslfdsljfkldsjfldsjfldsjlkfjdslkjfdsjlkfjdslkfjldsjfljskdfjlkjdsfhlsfdhsd'%i)
1.启动两个beansdb实例
beansdb -d -n 200 -p 7101 -H /duitang/data/mediadb/7101 -u admin -L /duitang/logs/usr/beansdb.log
beansdb -d -n 200 -p 7100 -H /duitang/data/mediadb/7100 -u admin -L /duitang/logs/usr/beansdb.log
2. beansdb_client
db = Beansdb(BEANSDBCFG, buckets_count)
buckets_count = 16
self.servers= {'localhost:7100':memClient1,'localhost:7101':memClient2}
self.server_buckets = {'localhost:7100':[1,2,3,4,5],'localhost:7101':[6.7.8,9.10]}
self.buckets=[[memClient1,memClient2],[memClient1,memClient2],[memClient1,memClient2],...buckets_count]
写入的时候beansdb会多次写
rs = [s.set(key, value) for s in self._get_servers(key)]
其实之前我对beansdb一知半解就拿来用,今天看了一下dbclient的set方法才发现会多次写入, 当我下面这样配置的时候,其实是172.3和172.5相互备份是吧?
{"192.168.172.3:7700": range(16),
"192.168.172.5:7700": range(16),
}
对于图片这种文件总量很大,如果相互备份感觉挺浪费磁盘空间的(原始图片本地都有备份),那可以改成如下方案吧:
{"192.168.172.3:7700": range(8),
"192.168.172.5:7700": range(8:16),
}
这种方案优点是比较节约空间,缺点是存在单点故障。
另外一点体会是,beansb的扩容是基于buckets拆分来扩容的对吧,如下(不考虑备份问题)
{"192.168.172.3:7700": range(16)}
|
|
↓
{"192.168.172.3:7700": range(8),
"192.168.172.4:7700": range(8,16),
}
|
|
↓
{"192.168.172.3:7700": range(4),
"192.168.172.4:7700": range(4,8),
"192.168.172.5:7700": range(8,12),
"192.168.172.6:7700": range(12,16),
}
3.迁移方案
{"192.168.172.3:7700": range(16),
"192.168.172.5:7700": range(16),
}
|
|
↓
{"192.168.172.3:7700": range(16),
"192.168.172.5:7700": range(8),
"192.168.172.6:7700": range(8,16),
}