Thanks for your reply, it really helped.
But i am still having the same problem, the response time of the code you shared is way more than the response time of the 1.x API for get bulk. I am testing it with 5000 keys, sharing both the 1.x and 2.x codes.
Time difference:
Method Name Return Type Time taken (millis)
getBulkForumCodeV2 Map<String, Object> 703
getBulkV1 Map<String, Object> 419
// 1.x API code to do the get bulk
public Map< String, Object > getBulkV1(String ...keys )throws Exception{
long start = System.currentTimeMillis();
BulkFuture< Map< String, Object > > future = cbClient.asyncGetBulk(keys);
Map< String, Object > pairs = future.get();
long end = System.currentTimeMillis();
System.out.printf("%-35s%-35s%d","getBulkV1","Map< String, Object >",(end-start));
System.out.println();
return pairs;
}
// 2.x API code to do the get bulk
protected Map< String, Object > getBulkForumCodeV2(final Collection< String > ids) {
long start = System.currentTimeMillis();
Observable< Map< String, Object > > asyncResult = Observable.from(ids)
.flatMap(new Func1< String, Observable< LegacyDocument > >() {
@Override
public Observable< LegacyDocument > call(String id) {
return bucket.async().get(id, LegacyDocument.class);
}
})
.toMap(new Func1< LegacyDocument, String >() {
@Override
public String call(LegacyDocument legacyDocument) {
return legacyDocument.id();
}
},
new Func1< LegacyDocument, Object >() {
@Override
public Object call(LegacyDocument legacyDocument) {
return legacyDocument.content();
}
})
;
Map< String, Object > syncResult = asyncResult.toBlocking().single();
long end = System.currentTimeMillis();
System.out.printf("%-35s%-35s%d","getBulkForumCodeV2","Map< String, Object >",(end-start));
System.out.println();
return syncResult;
}