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

Create an appropriate buffer with the size that accommodates signal frame payload #537

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public DispatchAgent(
this.timerWheel = new DeadlineTimerWheel(MILLISECONDS, currentTimeMillis(), 512, 1024);
this.tasksByTimerId = new Long2ObjectHashMap<>();
this.futuresById = new Long2ObjectHashMap<>();
this.signaler = new ElektronSignaler(executor);
this.signaler = new ElektronSignaler(executor, Math.max(config.bufferSlotCapacity(), 512));

this.poller = new Poller();

Expand Down Expand Up @@ -1672,9 +1672,10 @@ public Affinity resolveAffinity(
return affinity;
}

private static SignalFW.Builder newSignalRW()
private static SignalFW.Builder newSignalRW(
int capacity)
{
MutableDirectBuffer buffer = new UnsafeBuffer(new byte[512]);
MutableDirectBuffer buffer = new UnsafeBuffer(new byte[capacity]);
return new SignalFW.Builder().wrap(buffer, 0, buffer.capacity());
}

Expand All @@ -1691,16 +1692,18 @@ private Int2ObjectHashMap<MessageConsumer>[] initDispatcher()

private final class ElektronSignaler implements Signaler
{
private final ThreadLocal<SignalFW.Builder> signalRW = withInitial(DispatchAgent::newSignalRW);
private final ThreadLocal<SignalFW.Builder> signalRW;

private final ExecutorService executorService;

private long nextFutureId;

private ElektronSignaler(
ExecutorService executorService)
ExecutorService executorService,
int slotCapacity)
{
this.executorService = executorService;
signalRW = withInitial(() -> newSignalRW(slotCapacity));
}

public void executeTaskAt(
Expand Down