database - RocksDB JNI 慢读性能
问题描述
我正在使用 RocksDB JNI,我发现该程序的读取速度呈指数级增长
最初,它在可接受的范围内。但是当程序运行以使总记录达到 100 万条时,读取时间记录器打印显示大约 200-300 毫秒。随着程序的运行,情况变得更糟。我是否使用错误的 JNI?
long n = 0;
int counter = 0;
try(
final Options options = new Options()
.setCreateIfMissing(true)
.setComparator(new Comparator(new ComparatorOptions()){
@Override
public String name() {
return "default";
}
@Override
public int compare(final Slice a, final Slice b) {
long x = ByteBuffer.wrap(a.data()).getLong();
long y = ByteBuffer.wrap(b.data()).getLong();
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}
})
.setWriteBufferSize(64 * SizeUnit.MB)
.setMaxWriteBufferNumber(6)
.setMinWriteBufferNumberToMerge(2);
final RocksDB db = RocksDB.open(options, "/PathToDB/")){
boolean loop = true;
while(loop) {
if(n == Long.MAX_VALUE){
loop = false;
}
for (int j=0;j<4;j++){
try(WriteBatch writeBatch = new WriteBatch()) {
for (int i = 0; i < 200; i++) {
String urlStr = "dummy"+counter;
counter++;
Long score = getScore(urlStr);
ByteBuffer buf = ByteBuffer.allocate(Long.BYTES);
buf.putLong(score);
writeBatch.put( buf.array() , urlStr.getBytes(UTF_8));
}
long st = System.currentTimeMillis();
db.write(new WriteOptions(), writeBatch);
long et = System.currentTimeMillis();
logger.logMessage(Test.class.getName(), Level.INFO, "RocksDB write of 200 URLs successful. Time taken - {0}", new Object[]{ et-st});
} catch (RocksDBException ex) {
}
}
byte[] firstKey = null, lastKey = null;
int readC = 0;
long st = System.currentTimeMillis();
final RocksIterator it = db.newIterator();
it.seekToFirst();
while(it.isValid() && readC < 50){
lastKey = it.key();
if(firstKey == null){
firstKey = lastKey;
}
it.next();
readC++;
}
long et = System.currentTimeMillis();
logger.logMessage(Test.class.getName(), Level.INFO, "RocksDB read of 50 URLs successful. Time taken - {0}", new Object[]{ et-st});
if(lastKey != null){
db.deleteRange(firstKey, lastKey);
}
n++;
}
}catch (Exception e){
logger.logMessage(Level.SEVERE, Test.class.getName(), e);
}
解决方案
推荐阅读
- mongodb - 如何使用聚合 MongoDB 查找具有两列的不同字段
- powershell - Powershell从特定的WLAN获取接口
- html - 删除标题空间的 div 边框元素
- asynchronous - 如何在reactphp中检索外部响应变量
- cassandra - 星际之门是否适用于物化视图?
- json - 如何增加 json 对象属性值以动态填充 jmeter 请求的 json 正文
- django - 使用按字段名称分组的列表视图并链接到详细信息 - django admin
- python - 如何在 databricks 集群上运行非火花代码?
- python - 通过传递数据集路径、数据集名称和变量名称来修改代码
- php - 如果行检查,jquery sum 列