Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #65 from radixdlt/feature/backpressure-fix
Browse files Browse the repository at this point in the history
Add backpressure buffer to TCP/UDP channels processor
  • Loading branch information
LukasGasior1 authored Feb 16, 2021
2 parents 4228aeb + 9ed3d74 commit 0cedf1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.radixdlt.counters.SystemCounters;
import com.radixdlt.network.messaging.InboundMessage;
import hu.akarnokd.rxjava3.operators.FlowableTransformers;
import io.reactivex.rxjava3.core.BackpressureOverflowStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.processors.PublishProcessor;
import io.reactivex.rxjava3.schedulers.Schedulers;
Expand Down Expand Up @@ -60,6 +61,8 @@
final class NettyTCPTransportImpl implements NettyTCPTransport {
private static final Logger log = LogManager.getLogger();

private static final int CHANNELS_BUFFER_SIZE = 128;

// Set this to true to see a detailed hexdump of sent/received data at runtime
private final boolean debugData;

Expand Down Expand Up @@ -203,6 +206,11 @@ public void initChannel(SocketChannel ch) {
}

return channels
.onBackpressureBuffer(
CHANNELS_BUFFER_SIZE,
() -> log.error("TCP channels buffer overflow!"),
BackpressureOverflowStrategy.DROP_LATEST
)
.compose(FlowableTransformers.flatMapAsync(v -> v, Schedulers.single(), false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@

import com.radixdlt.counters.SystemCounters;
import com.radixdlt.network.messaging.InboundMessage;
import hu.akarnokd.rxjava3.operators.FlowableTransformers;
import io.reactivex.rxjava3.core.BackpressureOverflowStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.processors.PublishProcessor;
import io.reactivex.rxjava3.schedulers.Schedulers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -54,6 +57,8 @@
final class NettyUDPTransportImpl implements Transport {
private static final Logger log = LogManager.getLogger();

private static final int CHANNELS_BUFFER_SIZE = 128;

// Set this to true to see a dump of packet data
protected static final boolean DEBUG_DATA = false;

Expand Down Expand Up @@ -187,7 +192,13 @@ public void initChannel(NioDatagramChannel ch) {
throw new UncheckedIOException("Error while opening channel", e);
}

return Flowable.mergeDelayError(channels);
return channels
.onBackpressureBuffer(
CHANNELS_BUFFER_SIZE,
() -> log.error("UDP channels buffer overflow!"),
BackpressureOverflowStrategy.DROP_LATEST
)
.compose(FlowableTransformers.flatMapAsync(v -> v, Schedulers.single(), false));
}

@Override
Expand Down

0 comments on commit 0cedf1c

Please sign in to comment.