mirror of https://github.com/grpc/grpc-java.git
okhttp: Fair treatment when writing out streams (#9545)
When allocating bytes to streams within a flow control window we always go through the streams in the same order. This can lead to large streams hogging all the bytes and a smaller one down the list getting starved out. This change shuffles the stream array to lower the chance of this happening. Fixes #9089
This commit is contained in:
parent
341fea8996
commit
79c4c355ba
|
|
@ -25,6 +25,8 @@ import static java.lang.Math.min;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.grpc.okhttp.internal.framed.FrameWriter;
|
import io.grpc.okhttp.internal.framed.FrameWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
|
|
||||||
|
|
@ -152,6 +154,7 @@ class OutboundFlowController {
|
||||||
*/
|
*/
|
||||||
public void writeStreams() {
|
public void writeStreams() {
|
||||||
StreamState[] states = transport.getActiveStreams();
|
StreamState[] states = transport.getActiveStreams();
|
||||||
|
Collections.shuffle(Arrays.asList(states));
|
||||||
int connectionWindow = connectionState.window();
|
int connectionWindow = connectionState.window();
|
||||||
for (int numStreams = states.length; numStreams > 0 && connectionWindow > 0;) {
|
for (int numStreams = states.length; numStreams > 0 && connectionWindow > 0;) {
|
||||||
int nextNumStreams = 0;
|
int nextNumStreams = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue