我们在我们的项目中使用NoSQL(Cassandra)。我们有一个表A(5000条记录),它是一个主表。我们还有另一个表B(2000年的记录)。表B有4列,表A有25列。我们公开了一个REST服务来获取B中的所有记录;像/ service/getB。这项服务将在响应,返回6列 -提高Cassandra和java集合的性能
{
"result": [
{
"col1FromB": "1B",
"col2FromB": "2B",
"col3FromB": "3B",
"col4FromB": "4B",
"col1FromA": "1A",
"col2FromA": "2A"
},
{
"col1FromB": "11B",
"col2FromB": "12B",
"col3FromB": "13B",
"col4FromB": "14B",
"col1FromA": "11A",
"col2FromA": "12A"
}
]
}
所以,有一个查找查询表A表B.每个项目这是我正在做它 -
//Get all from Table B (took 90 ms in Local and 30 ms in Test)
Select select = QueryBuilder.select().from("B");
List<B> bList = cassandraOperations.select(select, B.class);
//Loop through bList and do a lookup using id in Table A (took 46000 ms (46 sec) in Local (horrible) and 6000 ms (6 sec) in Test)
For(B b: bList) {
Select select = QueryBuilder.select(“col1FromA”, “col2FromA”).from("A");
select.where(QueryBuilder.eq(“id”, b.getId()));
A a = cassandraOperations.selectOne(select, A.class);
----
----
//Prepare final Pojo with a and b objects and add into a List<finalPjo> and return
}
因此,本地环境中的查找时间非常高,在测试环境中也不太好。我所使用的只是Java集合。
有没有什么办法让它更好,让我们在较短的时间内获得记录。
是否有这些记录不能共位的原因? – dilsingi