从数据库取数据,我使用了ByteIterator数据接口,其例子和好处如下。
代码示例:
@Override
public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) {
try {
byte[] value = db.get(key.getBytes());
Map<String, ByteIterator> deserialized = deserialize(value);
result.putAll(deserialized);
} catch (RocksDBException e) {
System.out.format("[ERROR] caught the unexpceted exception -- %s\n", e);
return Status.ERROR;
}
return Status.OK;
}
Why I use ByteIterator here?
a.出于性能考虑,主要考虑字符串的成本、拷贝转码问题,流可能是一个图片(blob形式)
b.byte是字节,可以屏蔽utf8、gbk等编码细节。文本从磁盘拿出来本来是二进制,需要通过编码转化为对应的字符。ByteIterator可以屏蔽不同服务器编码不一样的的问题。
使用Byte来存储数据有什么缺点和优点?
略
使用Iterator有什么缺点和优点?可以屏蔽细节?
略
使用ByteIerator来有什么缺点和有点?
略
http://wiki.github.com/brianfrankcooper/YCSB/
https://labs.yahoo.com/news/yahoo-cloud-serving-benchmark/
[email protected]
-
Download the latest release of YCSB:
curl -O --location https://github.com/brianfrankcooper/YCSB/releases/download/0.12.0/ycsb-0.12.0.tar.gz tar xfvz ycsb-0.12.0.tar.gz cd ycsb-0.12.0
-
Set up a database to benchmark. There is a README file under each binding directory.
-
Run YCSB command.
On Linux:
bin/ycsb.sh load basic -P workloads/workloada bin/ycsb.sh run basic -P workloads/workloada
On Windows:
bin/ycsb.bat load basic -P workloads\workloada bin/ycsb.bat run basic -P workloads\workloada
Running the ycsb
command without any argument will print the usage.
See https://github.com/brianfrankcooper/YCSB/wiki/Running-a-Workload for a detailed documentation on how to run a workload.
See https://github.com/brianfrankcooper/YCSB/wiki/Core-Properties for the list of available workload properties.
YCSB requires the use of Maven 3; if you use Maven 2, you may see errors such as these.
To build the full distribution, with all database bindings:
mvn clean package
To build a single database binding:
mvn -pl com.yahoo.ycsb:mongodb-binding -am clean package