I'm looking for a UDP library for Java that works garbage free. The reason is that i'm developing a daemon application for a real-time system. My requirement is latency of 5 micro-sec per request (from arrival to my socket until the response gets to destination).
There are a couple of messaging services who support UDP and produce no garbage (Tibco FTL & Aeron), but both require that all communicating components will use the flatform.
My situation is that I have no control over the other components, all I know is that i'm going to get UDP messages to my socket and I need to handle them without producing any garbage.
Will appreciate any ideas :)
A very short example of this is just:
import java.lang.System;
public class UdpNoGc {
public static void main(String[] args) throws Exception {
var buf = new byte[1024];
var pkt = new java.net.DatagramPacket(buf, buf.length);
try (var sock = new java.net.DatagramSocket(4321)) {
for (;;) {
sock.receive(pkt);
System.out.write(buf, 0, pkt.getLength());
System.gc();
}
}
}
}
the explicit System.gc()
call is just there so you can run with:
java "-Xlog:gc,heap*" UdpNoGc
and see that it doesn't allocate anything after startup. Note that writing code that doesn't allocate is somewhat difficult in Java, it might be easier using another language that provides more support for this.