Hi together,
in my current project I have the following szenario:
I have to continuously stream data via UDP in chunks which are about 1200
bytes. I only want to send this data to one specific host,
so this is the only connection which I need.
My data is prepared natively and it is stored in a ByteBuffer, which I
prepare in the background and reuse via an object pool.
My first approach was to send it via the old plain java way like this
example here:
byte[] data = new byte[byteBuffer.capacity()];
byteBuffer.rewind();
byteBuffer.get(data);
DatagramPacket udp = new DatagramPacket(data, 0, data.length,
holder.getRemoteAddress());
serverSocket.send(udp);
I switched to Apache Mina as I thought it might be faster, the code now
looks like this:
byteBuffer.rewind();
IoBuffer ioBuffer = IoBuffer.wrap(byteBuffer);
IoSession session = getSession();
session.write(ioBuffer);
I figured out, that this solution is not really faster. Actually, I have the
strong feeling, that it is actually a bit slower, maybe the GC is running
more often.
My question to you guys is, does it makes sense to use the NIO approach here
or is just fine to use the old java approach?
Is it worth to use MINA and the IoBuffer directly or is the overhead of the
framework to much?
Kind regards
fritzr