Monday, October 19, 2009

Java and Jingle Nodes

For a couple of months, I was wondering if Java would be suitable to provide relay services, in case of a Java Jingle Client wanted to enable it.
Of course Java is perfectly suitable for using a Relay Service, no doubt about the trivial statement. But is Java suitable to be used on providing it?
Researching on Internet I found nothing but rumors and assumptions. So I decided to try it myself. I agreed with a Jingle Node Project Contributor to provide a Java Relay Channel Class just like we have the C++ version using Boost. And I would provide the UnitTest Cases in order to measure added latency. This weekend with the code in our hands we ran the tests.

All the tests were conducted using loopback interface in order to prevent real network to influence in the results.
You can find the Test Case in Jingle Nodes Repository:

Results running 10 simultaneous channels processing and relaying 30 packets, the overall average values after 100 tests, for Latency was:
  • Max: 52ms
  • Min: 7ms
  • Avg: 10.0ms
Surprisingly the results are very satisfactory for Client Side Relaying. And I have to admit that the Java Code is by far more elegant and simple.

This means that SIP Communicator is not only a good candidate for Jingle Nodes usage, but also a great candidate to also provide Jingle Nodes relaying features.
For comparison criteria I created an extra test case based on a single Relay Channel using a C++ and a Java Channel measuring the added latency by using a Relay, instead of direct traffic. The results were the following:

C++/Boost-ASIO Latency:
Max: 16ms, Min: 2ms, Avg: 3.0ms

Java NIO Latency:
Max: 90ms, Min: 2ms, Avg: 5.0ms

I strongly encourage Java and C++ Developers to do a try out and spicy the discussion.


  1. How do the C++ relays compare in latency, etc?

  2. I would love to answer this in the next post.
    So far we didn't right the latency meter for the C++ version, as we know for sure that IO on C++ is way faster and no proof of concept is needed at all.

    But indeed the comparison on numbers would be interesting.

  3. Yes - Java is pretty fast nowadays. I had a similar experience with relays for SIP RTP traffic.

    There are various existing products (such as a Python based and a C based relay). When using the C version the program was IO bound - hardly using any CPU even when the network links were saturated. The Python version on the other hand was CPU bound - we were not able to fully saturate the link as it would hit 100% CPU load before.

    We then also did some tests using self-written toy implementations in C, Python and Java. Java has high memory requirements, but performancewise there is not much difference to C. The only major difference that we observed is that worst-case latency in the Java version is higher than in the C version, but I guess that this can be attributed to Java garbage collection running every once in the while.

    While I really love C, Java provides a much better readability at a similar performance. And while Python code looks even nicer, the performance was too low to be acceptable. This was one of the events that converted me from a (mostly) C/Python programmer to a Java programmer.

  4. Well...
    I know about Java but I don't know about Java Jingle Notes....
    Is there any kinds of help for me..?
    Is there any ideas about it..? What exactly it is...?
    If any information..Post here..