Aeron

Aeron offers efficient reliable UDP unicast, UDP multicast, and IPC message transport — with a core design goal of reaching the highest throughput with the lowest and most predictable latency of any messaging system. Aeron Archive allows message streams to be recorded to persistent storage for later, or real-time, replay. Aeron Cluster provides fault-tolerant total ordering across multiple streams.

components

  • aeron
  • aeron archive
  • aeron cluster
  • agrona
  • SBE
    • header.wrap(buffer, offset)
    • request.wrap(buffer, offset + headerLentgh, actingLength, actingVersion)

agrona

  • duty cycles
    • business logic
    • connectivity
  • Agent
    • Agrona Agents are containers for application logic that execute in a duty cycle, such as processing messages from an Aeron subscription.
  • IdleStrategy
    • Sleeping
    • SleepingMillis
    • Yielding
    • Backoff
    • NoOp
    • BusySpin

what is this

Aeron

.

core components

  • driver conductor: cordinator/dispatcher, accept and process the command from publication/subscription
  • client conductor: resides in user app, communicate with driver conductor (IPC Ring/Broadcase Buffers)
  • sender/receiver: communicate with media (IPC, UDP)

file system

media driver owns a folder exclusively (MMAP), real data resides in memory usually

  • blank.template – empty template, to create new publication
  • cnc.dat – command and control data
  • images: any open images of remote publications
  • loss-report.dat: packet loss report (LossState)
  • publications: log buffer
    • three equal sized sections - each a Term with a unique Term ID - which hold header and message data
    • a metadata section, which resides at the end of the file

thread models

  • dedicated – isolated thread for each sender, receiver, conductor
  • shared network – one thread for sender, receiver, one for conducor
  • shared – only one thread
  • invoker – no thread, controlled by caller

channel stream

pub/sub needs to specify channel and stream-id.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class ServerAgent implements Agent
{
    private final Aeron aeron;
    private final Logger log = LoggerFactory.getLogger(ServerAgent.class);
    private final ServerAdapter serverAdapter;
    private Subscription subscription;

    public ServerAgent(final Aeron aeron, final ShutdownSignalBarrier barrier)
    {
        this.aeron = aeron;
        this.serverAdapter = new ServerAdapter(aeron, barrier);
    }

    @Override
    public void onStart()
    {
        log.info("Server starting");
        subscription = aeron.addSubscription(Constants.SERVER_URI, Constants.RPC_STREAM);
    }

    @Override
    public int doWork() throws Exception
    {
        return subscription.poll(serverAdapter, 1);
    }

    @Override
    public void onClose()
    {
        serverAdapter.closePublication();
    }

    @Override
    public String roleName()
    {
        return "server";
    }
}

publication

  • offer – byteBuf -> log-buffer
  • tryClaim – use pre-defined log-buffer, spare memory copy (doesn’t support fragmentation)
    • commit

back pressure

  • increase the size of log buffer (no more than 1G)
  • decrease the size of sending data
  • aeron archive for persistence
  • send less data
  • figure out io bottleneck

subscription – (controlled)fragmentHandler

log buffers & images

log buffer is memory mapped file in aeron, contains three identical memory space (term | clean,active,dirty) with different termId; and an area for maintaining metadata in the file end.

each publication has its own log-buffer.

position

  • streamId
  • sessionId
  • termId
  • termOffset

Aeron Archive

  • Aeron Archive, which resides on the process persisting and replaying streams
  • Aeron Archive Client, which resides on the process receiving archived streams.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
public void setup()
{
    mediaDriver = ArchivingMediaDriver.launch(
        new MediaDriver.Context()
            // ensures the publication can be written to without there being an attached subscriber
            .spiesSimulateConnection(true)
            .dirDeleteOnStart(true),
        new Archive.Context()
            .deleteArchiveOnStart(true)
            .archiveDir(tempDir)
    );
    aeron = Aeron.connect();
    aeronArchive = AeronArchive.connect(
        new AeronArchive.Context()
            .aeron(aeron)
    );
}

Aeron Cluster

  • consensus module
    • memberId
    • members
    • archive ctx
    • replication channel
    • consensus channel
    • ingress channel
    • egress channel
  • clustered service container
    • clustered service

best practice

  • /dev/shm is a temporary file storage (also known as a RAM-backed filesystem) on Linux systems. The “shm” stands for shared memory, and it is a special type of filesystem that allows applications to store and share data in memory, rather than on disk. It uses the tmpfs filesystem type, which resides in the system’s RAM, providing faster access compared to disk-based filesystems.

other suggestion

to run cookbook

remove AZUL requirement in gradle configuration.

references

Licensed under CC BY-NC-SA 4.0
Get Things Done
Built with Hugo
Theme Stack designed by Jimmy