Skip to content

Commit 1c463da

Browse files
authored
PublisherAsBlockingIterable LinkedBlockingQueue -> LinkedTransferQueue (#2386)
Motivation: LinkedBlockingQueue goes through LockSupport park and unpark methods which can incur relatively expensive context switching if the EventLoop thread has to unpark an application thread. This has been shown to be a bottleneck as throughput increases. Modifications: - Use LinkedTransferQueue which does a `Thread.yield()` before parking on the consumer thread. This may use more CPU on the consumer thread but the assumption is there will be many more application threads than EventLoop threads and we want to minimize producer costs. Results: LinkedTransferQueue ``` Running 30s test @ http://localhost:8080/medium, using 'ServiceTalkGrpcBlockingClientStrAgg' client 1024 threads and 1024 connections Thread Stats Avg Stdev Max +/- Stdev Latency - - - - Req/Sec 0.01k - 0.01k - 290977 requests in 30s Requests/sec: 9699.23 Transfer/sec: - OK: 290977 KO: 0 ``` LinkedBlockingQueue ``` Running 30s test @ http://localhost:8080/medium, using 'ServiceTalkGrpcBlockingClientStrAgg' client 1024 threads and 1024 connections Thread Stats Avg Stdev Max +/- Stdev Latency - - - - Req/Sec 0.01k - 0.01k - 256778 requests in 30s Requests/sec: 8559.27 Transfer/sec: - OK: 256778 KO: 0 ```
1 parent abc0d75 commit 1c463da

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

servicetalk-concurrent-api/src/main/java/io/servicetalk/concurrent/api/PublisherAsBlockingIterable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Iterator;
3131
import java.util.NoSuchElementException;
3232
import java.util.concurrent.BlockingQueue;
33-
import java.util.concurrent.LinkedBlockingQueue;
33+
import java.util.concurrent.LinkedTransferQueue;
3434
import java.util.concurrent.TimeUnit;
3535
import java.util.concurrent.TimeoutException;
3636
import javax.annotation.Nullable;
@@ -39,7 +39,7 @@
3939
import static io.servicetalk.concurrent.api.SubscriberApiUtils.wrapNull;
4040
import static io.servicetalk.concurrent.internal.TerminalNotification.complete;
4141
import static io.servicetalk.concurrent.internal.TerminalNotification.error;
42-
import static io.servicetalk.utils.internal.PlatformDependent.throwException;
42+
import static io.servicetalk.utils.internal.ThrowableUtils.throwException;
4343
import static java.lang.Math.min;
4444
import static java.lang.Thread.currentThread;
4545
import static java.util.Objects.requireNonNull;
@@ -101,7 +101,7 @@ private static final class SubscriberAndIterator<T> implements Subscriber<T>, Bl
101101

102102
SubscriberAndIterator(int queueCapacity) {
103103
requestN = queueCapacity;
104-
data = new LinkedBlockingQueue<>();
104+
data = new LinkedTransferQueue<>();
105105
}
106106

107107
@Override

0 commit comments

Comments
 (0)