我正在使用Hbase作为键值存储,其中我们有一个具有单个值的列族。 java过滤器在不到一秒的时间内获取行,但在尝试检索该值时需要15秒。如果有人可以调查并给我指针,那将非常有帮助。这是代码: -
Scan scan1 = new Scan();
scan1.addColumn(Bytes.toBytes("column_family"), Bytes.toBytes("column_name"));
Filter filter1 = new RowFilter(CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes("hashvalue")));
scan1.setFilter(filter1);
long startTime = System.nanoTime();
ResultScanner scanner1 = table.getScanner(scan1);
System.out.println(scanner1.next().getColumnLatestCell(Bytes.toBytes("column_family"), Bytes.toBytes("column_name")));
long endTime = System.nanoTime();
double seconds = (double)(endTime - startTime) / 1000000000.0;
System.out.println("Scan with row key using scan: " + seconds);
scanner1.close();
答案 0 :(得分:1)
如果您知道密钥的确切值,则无需进行扫描,而是可以执行Get,这应该是超级高效的。
Result result = table.get(Bytes.toBytes("hashvalue"))
触发next
时花费太长时间的原因是因为对next
的每次通话都是RPC
来电(HBase
}本身,{可以使用setCaching在HBase
的单次旅行中获得一定数量的行。