Database RocksDB JNI慢读性能
我正在使用RocksDB JNI,我发现这个程序的读取速度正以指数级的速度变慢 最初,它在可接受的范围内。但是当程序运行到总记录达到100万条时,读取时间记录器打印的数据显示大约为200-300毫秒。随着程序运行,情况变得更糟。我使用JNI错误吗Database RocksDB JNI慢读性能,database,performance,rocksdb-java,Database,Performance,Rocksdb Java,我正在使用RocksDB JNI,我发现这个程序的读取速度正以指数级的速度变慢 最初,它在可接受的范围内。但是当程序运行到总记录达到100万条时,读取时间记录器打印的数据显示大约为200-300毫秒。随着程序运行,情况变得更糟。我使用JNI错误吗 long n = 0; int counter = 0; try( final Options options = new Options() .setCreateIfMissing(true) .setComparator(new Comparato
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);
}
long n=0;
int计数器=0;
试一试(
最终选项=新选项()
.setCreateIfMissing(true)
.setComparator(新比较器(新比较器选项()){
@凌驾
公共字符串名称(){
返回“默认”;
}
@凌驾
公共整数比较(最终切片a、最终切片b){
long x=ByteBuffer.wrap(a.data()).getLong();
long y=ByteBuffer.wrap(b.data()).getLong();
回报率(x