I wrote a simple test for Aeron
one client, one server, the client sends data to the server, then the server sends it back and counts the elapsed time.
The final result is much lower than I expected, the following is part of my code and configuration, and some monitoring data
client publication
// client publication
@Scheduled(fixedRate = 1000)
private void start() {
if (!publishTaskEnable) {
return;
}
ConcurrentPublication publication = aeron.addPublication(
aeronProperties.getClient().getPublication().getChannel(),
aeronProperties.getClient().getPublication().getStream());
while (!publication.isConnected()) {
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
AtomicLong counter = new AtomicLong(0);
LongStream.range(0, aeronProperties.getRound()).forEach(i -> publish(publication, counter));
}
private void publish(Publication publication, AtomicLong counter) {
UnsafeBuffer buffer = new UnsafeBuffer(BufferUtil.allocateDirectAligned(16, 8));
long count = counter.incrementAndGet();
buffer.putLong(0, count);
publication.offer(buffer, 0, 16);
startTimeMap.put(count, System.currentTimeMillis());
}
client subscribe
@SneakyThrows
public void receive(String channel, Integer stream) {
clientPublication.setAeron(Aeron.connect(new Aeron.Context()
.aeronDirectoryName(aeronProperties.getDirname())
.idleStrategy(new NoOpIdleStrategy())));
try (Subscription subscription = clientPublication.getAeron().addSubscription(channel, stream)) {
IdleStrategy idleStrategy = new BusySpinIdleStrategy();
FragmentHandler fragmentHandler = this::onMessage;
while (true) {
int fragmentsRead = subscription.poll(fragmentHandler, 1000);
idleStrategy.idle(fragmentsRead);
}
}
}
@SneakyThrows
public void onMessage(DirectBuffer buffer, int offset, int length, Header header) {
long data = buffer.getLong(offset);
Long startTime = clientPublication.getStartTimeMap().get(data);
if (startTime == null) {
return;
}
long interval = System.currentTimeMillis() - startTime;
clientPublication.getTimeList().add(interval);
clientPublication.getStartTimeMap().remove(data);
}
Media Driver
java --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
-XX:+UseBiasedLocking
-XX:BiasedLockingStartupDelay=0
-XX:+UnlockExperimentalVMOptions
-XX:+UseParallelGC
-XX:+TrustFinalNonStaticFields
-XX:+UnlockDiagnosticVMOptions
-XX:GuaranteedSafepointInterval=300000
-Djava.net.preferIPv4Stack=true
-Daeron.dir=$AERON_DIR
-Daeron.threading.mode=DEDICATED
-Daeron.conductor.idle.strategy=org.agrona.concurrent.BusySpinIdleStrategy
-Daeron.sender.idle.strategy=org.agrona.concurrent.NoOpIdleStrategy
-Daeron.receiver.idle.strategy=org.agrona.concurrent.NoOpIdleStrategy
-Daeron.term.buffer.length=16M
-Daeron.socket.so_sndbuf=2m
-Daeron.socket.so_rcvbuf=2m
-Daeron.rcv.initial.window.length=2m
-Dagrona.disable.bounds.checks=true
-Daeron.pre.touch.mapped.memory=true
-cp aeron-all-1.44.1.jar io.aeron.driver.MediaDriver
below is some monitor data
iostat -sxz 1
Linux 5.15.0-112-generic (VM-0-2-ubuntu) 06/23/2024 _x86_64_ (8 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
20.43 0.01 5.24 0.13 0.00 74.19
Device tps kB/s rqm/s await areq-sz aqu-sz %util
loop0 0.02 0.15 0.00 0.98 7.33 0.00 0.00
loop1 0.02 0.15 0.00 1.16 8.05 0.00 0.00
loop2 0.09 0.92 0.00 0.66 10.14 0.00 0.01
loop3 0.02 0.46 0.00 1.04 21.18 0.00 0.00
loop4 0.03 0.47 0.00 1.23 15.56 0.00 0.00
loop5 0.02 0.15 0.00 1.00 8.39 0.00 0.00
loop6 0.81 31.72 0.00 0.22 39.30 0.00 0.27
loop7 0.01 0.01 0.00 0.00 1.36 0.00 0.00
sr0 1.54 54.31 0.00 0.24 35.33 0.00 0.05
vda 15.58 418.32 12.74 1.85 26.85 0.03 1.44
sar -n UDP 1
Linux 5.15.0-112-generic (VM-0-2-ubuntu) 06/23/2024 _x86_64_ (8 CPU)
02:18:57 PM idgm/s odgm/s noport/s idgmerr/s
02:18:58 PM 7436.00 303.00 0.00 0.00
02:18:59 PM 14266.00 482.00 0.00 0.00
02:19:00 PM 18488.00 151.00 0.00 0.00
02:19:01 PM 13230.00 149.00 0.00 0.00
02:19:02 PM 16710.00 153.00 0.00 0.00
02:19:03 PM 15754.00 173.00 0.00 0.00
pidstat -t -r -p 4517
Linux 5.15.0-112-generic (VM-0-2-ubuntu) 06/23/2024 _x86_64_ (8 CPU)
01:47:56 PM UID TGID TID minflt/s majflt/s VSZ RSS %MEM Command
01:47:56 PM 1000 4517 - 18.98 0.01 661284 111056 0.70 aeronmd
01:47:56 PM 1000 - 4517 18.98 0.01 661284 111056 0.70 |__aeronmd
01:47:56 PM 1000 - 4518 0.00 0.00 661284 111056 0.70 |__aeron_executor
01:47:56 PM 1000 - 4519 0.00 0.00 661284 111056 0.70 |__sender
01:47:56 PM 1000 - 4520 0.00 0.00 661284 111056 0.70 |__receiver
Is there something wrong? How can I optimize it?
I keep trying various parameters, but it doesn’t work very well.
New contributor
litchi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.