Closed jkvargas closed 1 year ago
The first async command response times are usually slow because there are a lot of extra classes that need to load in the current process. Is this the first test that you run?
Also, I don't understand the need for the following code here:
var eventLoops = new NioEventLoops(eventPolicy, 4);
This creates a new set of event loops for each test run. This should really be done once just before instantiating AerospikeClient.
var eventLoops = new NioEventLoops(eventPolicy, 4);
ClientPolicy policy = new ClientPolicy();
policy.eventLoops = eventLoops;
AerospikeClient client = new AerospikeClient(policy, hosts);
Then, pass in null for the eventloop. The client will use the next eventloop when null is passed in.
Finally, pass in null instead of instantiating BatchPolicy to use the defaults.
Hi @BrianNichols, Thanks for the tips, I am passing null in order to use the defaults. I made a bunch of requests querying for random items. Always 3 items, I got the following in milliseconds, 5, 79, 98, 95, 5, 52, 5, 95. 3, 67, 51, 16, 3, 96, 61, 19, 1, 72, 96, 75, 4, 61, 14, 97. 4, 82, 105, 78, 7, 76, 10, 96
Results does not seem consistent even though all of them seem to be or bellow 20ms or 50ms+. Maybe I am missing something?
@Test
public void batchOfItemsReturnedCorrectlyUsingAerospikeClientAsync_2() {
final var future = new CompletableFuture<List<Record>>();
final var listCompleter = new CustomRecordListFutureCompleter(future);
var random = new Random();
var keys = new Key[] { new Key(NAMESPACE, SET_NAME, "id-" + random.nextInt(10000)),
new Key(NAMESPACE, SET_NAME, "id-" + random.nextInt(10000)),
new Key(NAMESPACE, SET_NAME, "id-" + random.nextInt(10000)) };
var startTime = System.currentTimeMillis();
client.get(null, listCompleter, new BatchPolicy(), keys, StoryBinId);
var result = future.join();
logger.info("batch dao get: {}", System.currentTimeMillis() - startTime);
assertEquals(3, result.size());
}
You can pass in null for the default BatchPolicy:
client.get(null, listCompleter, null, keys, StoryBinId);
Record[] will never be null in the callback, so you don't need to check for that.
public void onSuccess(Key[] keys, Record[] records) {
future.complete(Arrays.asList(records));
}
An individual Record entry can still be null though.
Might want the CompletableFuture to return Record[] instead of a list.
These are minor improvements. One other way to test async batch performance is to use the benchmarks program.
cd benchmarks
# seed records
./run_benchmarks -h <host> -w I -k 100000 -a
# run batch reads
./run_benchmarks -h <host> -w RU,100 -k 100000 -a -eventLoops 4 -B 3 -latency 7,1
The tps values are for the entire batch. To obtain records per second (rps), multiply tps * batchsize (in this case 3).
Hi, I would like to ask how can I improve the speed to get a batch of items. Using a mac m1, client version 6.+ and server being aerospike:ce-5.7.0.10. the results I am getting would be between 40ms and 60ms to get those 3 initialBinBatch items. My requirements would be results taking 12-20ms to obtain. Is there a way to improve these results?
client is an AerospikeClient instance and follows CustomRecordListFutureCompleter definition: