Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PublisherAsBlockingIterable LinkedBlockingQueue -> LinkedTransferQueue #2386

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

Scottmitch
Copy link
Member

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

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
```
@Scottmitch Scottmitch force-pushed the blocking_iterable_xfer branch from 7145e7c to 1f064c1 Compare October 4, 2022 18:49
@Scottmitch Scottmitch merged commit 1c463da into apple:main Oct 4, 2022
@Scottmitch Scottmitch deleted the blocking_iterable_xfer branch October 4, 2022 19:11
idelpivnitskiy added a commit to idelpivnitskiy/servicetalk that referenced this pull request Dec 20, 2022
idelpivnitskiy added a commit that referenced this pull request Dec 21, 2022
…sferQueue (#2386)" (#2472)

This reverts commit 1c463da (#2386).

We didn't observe visible improvements for `ServiceTalkGrpcBlockingClientStrAgg`, but saw negative impact on HTTP/1.1 blocking-streaming cases:
1. On the client-side for `GET` : -10k RPS, +5-10ms p99
2. On the server-side for `POST` : -10k RPS, +5ms p99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant