This discussion is archived
10 Replies Latest reply: May 21, 2012 4:58 AM by tmazight RSS

Java NIO Frameworks

tmazight Newbie
Currently Being Moderated
Hi,

I'm on specification step of programming a network application with Java,in this application the server have to handle about 300 client and at a period of time each client send 60Message/Second (messages have relatively small size) so my server have to manage 60Message/s per client that's the only constraint that i have,

As i can see there is two standards for this, Java IO and Java NIO(New IO), i deduced that NIO gives more performance with sockets than NIO and that's using non blocking sockets, so now i think i will choose NIO.

From googling a little bit, i arrived to the shortlist of two frameworks : MINA and Netty ,they are two of them based on NIO, articles on internet tells that Netty gives more perfomance form using socket.

I'm posting this message to hear from you what will you choose in my situation (that i explained at the beginning) i'm open for any suggestion (IO or NIO / and if it is NIO witch framework to use , MINA Netty or other) and why ?

regards
  • 1. Re: Java NIO Frameworks
    EJP Guru
    Currently Being Moderated
    the server have to handle about 300 client[s]
    If you only have to handle 300 clients you have no reason whatsoever to be even thinking about NIO.
    i deduced that NIO gives more performance with sockets
    Deduced from what premisses? There is nothing in the Javadoc or the NIO specification that says so. It says it is more scaleable. With 300 clients you are about two orders of magnitude away from scalability problems.
    now i think i will choose NIO
    I strongly recommend you reconsider this decision.
  • 2. Re: Java NIO Frameworks
    tmazight Newbie
    Currently Being Moderated
    thanks for your response.

    So you thing that simple sockets can give me the performances that i need?
    i deduced that NIO brings more performance of I/O operations from test that others published on internet, do you see any disadvantages that can bring the using of NIO in my case?
    and please why do you recommend me to reconsider my decision about choosing NIO, i can change my decision bu i have to understand why

    regards
  • 3. Re: Java NIO Frameworks
    jtahlborn Expert
    Currently Being Moderated
    Otmane wrote:
    So you thing that simple sockets can give me the performances that i need?
    seems that the answer is pretty clearly "yes".
    i deduced that NIO brings more performance of I/O operations from test that others published on internet, do you see any disadvantages that can bring the using of NIO in my case?
    the word "performance" can mean many things. EJP has already indicated that NIO is more scalable than normal IO. scalability is a form of performance, but by no means the only one. as preveiously stated, you aren't dealing with the number of connections where scalability of normal IO becomes a problem.
    and please why do you recommend me to reconsider my decision about choosing NIO, i can change my decision bu i have to understand why
    because it is a much more complex programming model than standard IO.
  • 4. Re: Java NIO Frameworks
    EJP Guru
    Currently Being Moderated
    So you thing that simple sockets can give me the performances that i need?
    That is implicit in my answer. I'm surprised you're even asking.
    i deduced that NIO brings more performance of I/O operations from test that others published on internet
    What tests? and what did they test?
    do you see any disadvantages that can bring the using of NIO in my case?
    The programming model is foreign and at least 10 times as complex. You would have a lot of learning to do and a lot of redesign.
    and please why do you recommend me to reconsider my decision about choosing NIO, i can change my decision bu i have to understand why
    See above.
  • 5. Re: Java NIO Frameworks
    tmazight Newbie
    Currently Being Moderated
    i saw on many articles that the objects in the package java.io treated the data by bytes, those package java.nio, process blocks of data: this means that read oparation is accelerated! and that based on the "channel" flow and new types of buffers specially designed to accelerate the I / O.

    concerning complexity of the programming model, there are many framworks associated to NIO that make that more easier, the example that i gived are Netty and Mina.

    guys i know that you have more experiences that me with Java (i'm in internship) that's why you should explain to me why should i use IO package, up to now i have only had bref answers with no reasons.

    thanks
  • 6. Re: Java NIO Frameworks
    EJP Guru
    Currently Being Moderated
    up to now i have only had bref answers with no reasons.
    You mean no reasons apart from:

    1. "it is more +scaleable+".
    2. "With 300 clients you are about two orders of magnitude away from scalability problems".
    3. "scalability is a form of performance, but by no means the only one".
    4. "you aren't dealing with the number of connections where scalability of normal IO becomes a problem".
    5. "it is a much more complex programming model than standard IO".
    6. "The programming model is foreign and at least 10 times as complex."
    7. "You would have a lot of learning to do and a lot of redesign."

    Up to now, you have just completely ignored everything you've been told. You keep asking us to repeat things we have already said. Go ahead and do it the hard way if you wish. I for one have lost interest.
  • 7. Re: Java NIO Frameworks
    gimbal2 Guru
    Currently Being Moderated
    Otmane wrote:
    guys i know that you have more experiences that me with Java (i'm in internship) that's why you should explain to me why should i use IO package, up to now i have only had bref answers with no reasons.
    Why? Figure it out for yourself: create a simple echo server/client (client sends a String, server echos it back) using regular IO and create one using NIO. See for yourself why you shouldn't use NIO when you don't have to if you don't want to believe what is said.
  • 8. Re: Java NIO Frameworks
    tmazight Newbie
    Currently Being Moderated
    Thank guys
  • 9. Re: Java NIO Frameworks
    sabre150 Expert
    Currently Being Moderated
    Otmane wrote:
    guys i know that you have more experiences that me with Java (i'm in internship) that's why you should explain to me why should i use IO package, up to now i have only had bref answers with no reasons.
    So you want us to write a 10 page article! Come off it!

    Over the last few weeks I have been converting a client server system from a blocking IO architecture to a non-blocking NIO architecture. Initially I had very few problems (apart from one small hiccup which EJP helped me with both in this forum and by reading his excellent book) but that was only the start. I am now trying to deal with a major problem in that the system locks every now and again and diagnosis is proving very difficult. I can't work out whether this is due to a race condition or a deadlock but either way it will probably mean a significant re-structuring in order to solve the problem.

    Since this is a 'home' project with no time constraints I am lucky. I today decided to start the whole project again from scratch using my experience over the last few weeks. I will still use NIO because I want to understand it better but if this was for an employer for a project with only about 300 users at any time there is no way I would consider using NIO . It would just not be cost effective. I'm no dummy but I found the leaning curve particularly steep. Being very very very old and having worked with conventional Java IO for more than 10 years I am finding it difficult to switch from a blocking IO mindset to a not blocking IO mindset. NIO with a single thread (or very very few threads and a state machine) is to my mind much much more difficult than blocking IO with multiple threads but what do I know.

    Listen to EJP - he has decades of experience in this field. If you end up using NIO his book is worth buying but it doesn't really make a case for or against using NIO.

    Edited by: sabre150 on May 23, 2012 4:49 PM

    :-( My problem was neither a race condition nor a deadlock! Just stupidity. I made a silly assumption about how something worked and stuck with it even when the evidence was against it.
  • 10. Re: Java NIO Frameworks
    tmazight Newbie
    Currently Being Moderated
    thanks a lot :)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points