merlimat opened a new pull request, #3838:
URL: https://github.com/apache/bookkeeper/pull/3838
### Motivation
One of the main contention points in bookies is the Journal queue. There are
multiple threads posting entries to be added on the journal on the queue.
In order to reduce contention and increase overall throughput (when there
are many small entries), we can adopt a strategy of "bulk" inserting to the
queue.
`BatchedArrayBlockingQueue` is a fixed size blocking queue, very similar to
Java `ArrayBlockingQueue` with 2 additional methods:
1. `putAll(T[] array, int offset, int len)` --> Add all the items from the
array in one shot, block if full
2. `takeAll(T[] dest)` --> Take all the available items in the queue that
fit into the destination array, block if empty
We use arrays here instead of List/Collection because it enables to do
`System.arrayCopy()` which is way faster than a for loop and assignments.
This PR only introduces the queue, subsequent work will make use of it for
the journal.
### Benchmarks
When inserting items in bulk, this queue is 10x to 20x faster than
`ArrayBlockingQueue`
```
// 4 producing threads
Benchmark Mode Cnt
Score Error Units
MpScQueueBenchmark.arrayBlockingQueue thrpt 5
46.844 ± 3.445 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueBatch thrpt 5
846.931 ± 36.330 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueSingleEnqueue thrpt 5
51.522 ± 4.505 ops/us
// 8 producing threads
Benchmark Mode Cnt
Score Error Units
MpScQueueBenchmark.arrayBlockingQueue thrpt 3
43.090 ± 7.548 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueBatch thrpt 3
825.470 ± 293.480 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueSingleEnqueue thrpt 3
47.250 ± 16.575 ops/us
// 16 producing threads
Benchmark Mode Cnt
Score Error Units
MpScQueueBenchmark.arrayBlockingQueue thrpt 3
44.185 ± 12.999 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueBatch thrpt 3
655.073 ± 565.844 ops/us
MpScQueueBenchmark.batchAwareArrayBlockingQueueSingleEnqueue thrpt 3
47.575 ± 37.798 ops/us
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]