Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  NIO Article: RFP  (Read 3609 times)
0 Members and 1 Guest are viewing this topic.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Posted 2003-09-03 19:54:48 »

I'm trying to decide what to include in an article on NIO. Here's a provisional list of the topics I think people probably want to know about (and which I can write on Smiley). Each would easily be an article in it's own right.

EDIT: I'm only talking about using nio for networking...
EDIT: When I say "IO" below, I mean "networking using the old IO routines and classes", which means "java.io.* and java.net.*". Much of the java.io.* stuff is replaced with java.nio.* stuff, but the java.net.* stuff is replaced by stuff in the java.nio.channels.* package (there is no "java.nnet.*" package, which might make things a bit more obvious here! The .net to .nio.channels change makes sense because networking and file I/O have been unified a bit more, so it's no longer appropriate to speak only in terms of net)


  • Using NIO in a game: Where, How, Why
  • Should I use NIO, or just plain IO?
  • Patterns/architectures for NIO servers
  • Gotchas, bugs (in nio), platform-dependencies, etc
  • Useful dev and debugging tools (specifically for NIO development - i.e. not IDE's, but e.g. stress-testing tools)
  • Introduction to planning your server for a game: Mesage-protocols, msg-formats, transport layers, app-layers, app-layer semantics, distribution architectures (p2p, c-s, etc)
  • Attaining peak performance with NIO


...if you could let me know which of those is most useful to you, I'll get writing. Equally, any other suggestions, comments, etc? Maybe there's something else you want to know, more useful than what I have included in that list?

I'm not expecting that people want to know how to get a basic NIO server running - that's the ONLY part of NIO that's adequately covered by millions of free tutorials on the web. However, if people have trouble finding them, or running them, perhaps I could pull together a small set of examples?

malloc will be first against the wall when the revolution comes...
Offline shawnkendall

Senior Member





« Reply #1 - Posted 2003-09-03 21:54:28 »

NIO is "New" I/O using the ByteBuffers and deriviatives.
What is an NIO server?

Aren't you talking about networking and isn't that still the net package and independant of NIO?  How does NIO change server architexture?

Thanks for any infos! Smiley

Shawn Kendall
Cosmic Interactive, LLC
http://www.facebook.com/BermudaDash
Offline Mojomonkey

Senior Member




ooh ooh eee eeee


« Reply #2 - Posted 2003-09-03 22:06:19 »

I'm a little confused about this as well. Which leads to a great topic to include in the article. How/When/Why you'd use NIO for networking rather than just .net?

Don't send a man to do a monkey's work.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2003-09-03 23:04:05 »

Quote
NIO is "New" I/O using the ByteBuffers and deriviatives.
What is an NIO server?

Aren't you talking about networking and isn't that still the net package and independant of NIO?  How does NIO change server architexture?

Thanks for any infos! Smiley


Thanks, guys, it's great to know what you don't know Wink. It's also good to get a heads-up on what aspects of the vocab I (ab)use through laziness or familiarity, and need to be more careful with...

You can't do much real (certainly you can't do non-HTTP) networking in java without heavy use of java.io. When I say "NIO vs IO" I really should say "NIO vs (IO + NET)" (thanks for pointing that out Smiley), but the name NIO often makes people talk of it in contrast to IO (by which they typically mean "IO = java.io + java.net" when talking about networking).

NIO-networking classes (java.nio.channels.*) fundamentally alter the architecture of a java server. It's a bit like the difference between Java pre-Collections and post-Collections... It's a switch from an API which gives you little or no control over how your connections are being handled, how they are prioritized, how they are arranged etc, to one which (when it works) gives you (some) control over all of that.

Note: that's a gross generalization. You can, for instance, use the java.nio classes in a traditional net/io server without any architectural changes. I'm trying to just give you a taste of the differences here Smiley.

One example of how it changes the playing field is that it has the potential to allow several thousand simultaneously connected TCP clients (in theory, up to about 20 thousand on a typical PC...but I've not checked if Sun's umplementation can currently go that far Wink).

With standard io and net, you are effectively limited at 500 odd clients, although some tricks (e.g. using non-standard OS upgrades, like recent work on linux threading) can get you much higher.

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #4 - Posted 2003-09-03 23:07:44 »

Quote
I'm a little confused about this as well. Which leads to a great topic to include in the article. How/When/Why you'd use NIO for networking rather than just .net?


Sorry, that's what I meant when I said "NIO vs IO".

I should also be explicit and say that I'm only going to consider NIO for networking - i.e. not file I/O etc. There seem to be very few games devs here who need help with nio file stuff compared to those that would benefit from nio networking (channels) stuff.

This is mainly supposition on behalf, but AFAICS any games devs using nio file reading/writing know what they're doing very well already? Bearing in mind it's considerably slower to use nio for file io unless you have VERY big files or extreme memory-copying situations (e.g. sending megabytes of data directly to a video card, via a memory-mapped file IIRC)...

malloc will be first against the wall when the revolution comes...
Offline GergisKhan

Junior Member




"C8 H10 N4 O2"


« Reply #5 - Posted 2003-09-04 01:24:58 »

Wow, I get to be a newbie asking for help for a change!

I'd like two things out of this.  NIO is badly documented leading most devlopers, including myself, to completely missing the point.  Actually I shouldn't say that.  *I* cannot find good documentation for NIO.

Two, why should I use it?  It seems fundamentally different from the "old" way and I'm not sure it does anything for me.

gK

"Go.  Teach them not to mess with us."
          -- Cao Cao, Dynasty Warriors 3
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #6 - Posted 2003-09-04 05:39:07 »

The only good documentation for NIO comes from books you have to buy as the Sun documentation is horrible in this regard.

NIO's claim to fame in the server space is that it allows non-blocking IO with the use of selectors. Traditional designs spin up a thread for each user connecting to a server and this is resource intensive. With NIO selectors can be set up to send and receive data when channels (a new concept with respect to IO) are read to send and receive data. Since you aren't spawning a thread for each client you can clearly have a much more scalable architecture. If you're only trying to connect onesie - twosies to a server then NIO is NOT the best option for you as it does incur some overhead of its own - but if you're looking to do a traditional 32 person game - you will quickly find that blocking IO and spinning up threads per user will pretty much kill your performance.

NIO is one of the most important but least understood APIs that came along for the ride with JDK1.4. In my shop we build massively scalable servers (for obvious reasons) and without NIO life would absolutely suck. It does take a while to get used to, but if you're using NIO to talk ByteBuffers with JOGL or LWJGL, there is very little that you need to deal with in order to transfer that knowledge into the network world. In fact all of the relevant IO classes in 1.4 received the .getChannel() method so that you wouldn't have to change your code too much.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #7 - Posted 2003-09-04 17:31:42 »

Quote
The only good documentation for NIO comes from books you have to buy as the Sun documentation is horrible in this regard.


Nod. My sarcastic comments on the state of NIO docs from Sun are legion Smiley.

Quote

NIO's claim to fame in the server space is that it allows non-blocking IO with the use of selectors....If you're only trying to connect onesie - twosies to a server then NIO is NOT the best option for you as it does incur some overhead of its own - but if you're looking to do a traditional 32 person game - you will quickly find that blocking IO and spinning up threads per user will pretty much kill your performance.


The architectural/design changes are also a major improvement. Code is cleaner, easier to maintain, debug.

In most cases, you are NOT going to notice any performance difference with 32 players between NIO and IO/net/. No modern OS should have issues with anything less than several hundred threads (although if pressed I'd err on the safe side and assume it could only handle a hundred Smiley). There are libraries on linux (not yet standard) that allow 100,000 threads with litle or no performance degradation - and this is being used specifically in server development. Although I've not tested the claim, 10,000 threads with little/no performance loss is certainly believable.

Solaris also provides good examples (at similar numbers of threads) of what performance you can get out of massive multi-threading on a production OS.

The issues involved in choosing NIO or not are a little more complicated than you make out, although as a quick summary it's fair enough.

Quote

NIO is one of the most important but least understood APIs that came along for the ride with JDK1.4.... In fact all of the relevant IO classes in 1.4 received the .getChannel() method so that you wouldn't have to change your code too much.


I agree with your sentiment, hence I want to correct the situation. However, the getChannel() method has some major issues. It isn't actually fully safe. If you want an example, use getChannel to try using Socket's generated by an SSLSocketFactory with nio. (hint: it doesn't work - this is covered in the API docs IIRC, which specifically state that just because you can call the getChannel method doesn't mean it has to return a valid channel).

Would you like to collaborate on producing an example/article that shows how neatly networking can mesh with things like JOGL, using NIO? I'm still only dipping my toes in the water with JOGL at the moment, so...

malloc will be first against the wall when the revolution comes...
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #8 - Posted 2003-09-04 20:08:11 »

Well it really depends on what you have those threads doing. I don't want to elaborate too much on architectures, but if you're doing an asynchronous response architecture (like a P2P or chat system) - the idea of spawning a thread for each client should send chills down your spine Smiley It won't scale well at all.

Quote

In most cases, you are NOT going to notice any performance difference with 32 players between NIO and IO/net/.


If you're UDP no - if you're TCP and high traffic yes. Without NIO you have to use the nasty IO stream semantics to write to the sockets and that will dog performances as opposed to slapping together a packed with NIO and sending raw byte buffers over the wire.

Quote

It isn't actually fully safe. If you want an example, use getChannel to try using Socket's generated by an SSLSocketFactory with nio.


While it isn't 100% safe - for general use and porting, unless your SSL heavy (and who here is SSL heavy) - you can plug NIO into your existing server framework within a weekend in many cases.

Additionally, I'd love to colaborate with you on NIO docs. Just send me an email.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline shareme

Junior Member




Java games rock!


« Reply #9 - Posted 2003-09-05 11:00:05 »

Some very good information from you guys..thanks!

Now if only Sun would cover this info in their java.net site!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #10 - Posted 2003-09-05 13:20:05 »

OK, I've started Smiley. It's rather hard to predict when and where my spare time occurs at the moment (we're in alpha/beta test at the moment, so lots of spikes and troughs of activity).

http://grexengine.com/sections/people/adam/

So far, I've just got a very basic "Introduction to NIO Networking" up. It says not much more than we've covered already in this topic, but I'm not expecting to spend much time "introducing" NIO. I'll see if I can another, more useful, article up later today Smiley.

Any comments, suggestions, corrections, etc?

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #11 - Posted 2003-09-05 13:22:39 »

Quote
Some very good information from you guys..thanks!

Now if only Sun would cover this info in their java.net site!


P.S. Assuming the quality is high enough, once these articles are done, I'd much prefer it if they were published on JGO (alongside all the other great resources here - forums, wiki, project-pages, etc); I'm just making use of some free webspace I've got at the moment, while it's still a "work in progress".

I'm kind of hoping to kick-start a flow of JGO articles from other people...

malloc will be first against the wall when the revolution comes...
Offline gregorypierce

Senior Member




I come upon thee like the blue screen of death....


« Reply #12 - Posted 2003-09-05 23:39:30 »

Cool.... I'm actually working on a reference based on JOGL, JInput, JOAL and hopefully we'll be able to get all this on the Java.Net site.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #13 - Posted 2003-09-08 21:42:59 »

I am surprised that 'traditional' java.io based networking should be as fast and responsive as the a nio based. Some months ago I was involved in the development of a Java client of the popular board game Ursuppe (http://doris-frank.de/GamesUrsuppe.htm). A java-based server runs the game and communicates to the clients using a simple text based protocol. The client's task was to win the game using its AI.
Our problem: In tournament games the clients were given a 1.5 seconds timeout to do a valid response. Our client was at first using the conventional socket and stream classes and often missed the timeout.
Fortunately I found IBM's article to NIO and was able to rewrite the core component of our communications package.  This modification really helped against the evil timeout problem.
From the logs of the other clients (there are 8 in total) we know that they had the same problem. As far as I know the server and the other clients used conventional io+net.

I admit that a tournament which consists of the server and 4 clients ran on a single machine (4x i686 - Linux) ...

Can someone explain these discrepancies in performance to me?

To come back to the topic:
Although I have already done a clientside network component with nio I do not feel ready to create a full-featured networking package that can be used by a game. My main problem is that nio acts like an unbuffered input stream: you never know when you have gotten all of the bytes the other side sended. This should be highlighted more in an article.
Another story are these funky flip/mark/clear/limit Methods the nio-Buffers supports. Some images would be nice to describe their functionality to people who are not speaking english as their native language .. Cheesy

Some info about proper character conversion using nio would be nice as well.

I thank you for reading my suggestions and writing such a hot article that everyone will be interested in!

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #14 - Posted 2003-09-08 22:56:23 »

Quote
I am surprised that 'traditional' java.io based networking should be as fast and responsive as the a nio based. Some months ago I was involved in the development of a Java client of the popular board game Ursuppe


It is almost never possible to tell what the performance problem is without seeing the code Smiley. There were flaws in io/net that used to be serious enough to be called bugs - especially in the DNS resolution (which was absolutely rubbish until 1.3.x IIRC). But nothing that couldn't be worked around (except for the fact that you couldn't interrupt an active Socket, IIRC).

Quote

To come back to the topic:
Although I have already done a clientside network component with nio I do not feel ready to create a full-featured networking package that can be used by a game. My main problem is that nio acts like an unbuffered input stream: you never know when you have gotten all of the bytes the other side sended. This should be highlighted more in an article.


So, do you mean the high-level / architectural issues? How to design your classes and methods to work together with this behaviour?


Quote
Another story are these funky flip/mark/clear/limit Methods the nio-Buffers supports. Some images would be nice to describe their functionality to people who are not speaking english as their native language .. Cheesy

Some info about proper character conversion using nio would be nice as well.


Yeah, I'm currently projecting doing them in this order:

1. introduction and brief background to NIO. Brief comments on why you'd want to use it. Explanations of core concepts - such as the differences between synch and asynch I/O.

2. SelectableChannel, SelectionKey, and Selector - how to use them, how not to use them, what they're there for, what the advantages are, some of the funky things you can do with them.

3. Converting from IO to NIO - mainly featuring how to use Selector's etc in simple ways in an existing application.

4. NIO or IO? Which one is for me? Which one is for my current game? Why? ...etc

5. More detailed explanation of the ByteBuffers, how to use them, what to do with them, etc.

Have a look at the early drafts of 1 and 3 that are linked to from the page I quoted above, and let me know what you think. I'm afraid it's going to take a while before any are "complete" due to my work commitments at the moment Sad.

Orangy Tang (thanks!) has given me source to a real game that I can convert from IO to NIO, so I may well rewrite number 3 to use that game as a working example. Need to read through the source and check it all out first though...

malloc will be first against the wall when the revolution comes...
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #15 - Posted 2003-09-09 10:12:09 »

1)
The first article gives a good introduction to the topic. Nothing to complain. Good work!

3)
The game example was a little difficult to follow but it reminded me of a real problem I had with nio: Writing to a channel is not always possible. I think this is really annoying when migrating to asynchronous io. Although the article touches the writing problem I did not really understand how to face it properly.

Quote

So, do you mean the high-level / architectural issues? How to design your classes and methods to work together with this behaviour?

Yes but on a network library level. It would have helped me alot when JDK docs clearly stated that asynchronous io has to be supported by a sophisticated system of input and output buffers.
Maybe you could include these and other design considerations for people who want to use nio in their own network package (if not already planned Cheesy )



cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #16 - Posted 2003-09-09 10:23:35 »

Quote
1)

3)
The game example was a little difficult to follow but it reminded me of a real problem I had with nio: Writing to a channel is not always possible. I think this is really annoying when migrating to asynchronous io. Although the article touches the writing problem I did not really understand how to face it properly.


...so, basically, you'd like to see a whole article explaining how to use Asynchronous I/O? (in a generic way - which doesn't necessarily just mean NIO, but other asynch libs as well...)

There's quite a few mistakes in 3 at the moment Smiley, and it'll change quite a bit as I try to make it easier to understand etc. What I want to be is "A worked example so that you can see very quickly roughly how much work is involvd, and roughly what are the issues (design etc) you have to face". It intentionally glosses over the details, so that I can cover them elsewhere (e.g. explaining how to use Selectors/SelectionKeys/etc, and explaining how to use ByteBuffers/Charsets/etc).

So...any suggestions on how 3 could achieve that aim better (from your perspective)?

Thanks for the comments Smiley.

malloc will be first against the wall when the revolution comes...
Offline TheBohemian

Junior Member




Java will rule them all!


« Reply #17 - Posted 2003-09-10 15:13:57 »

[/quote]
...so, basically, you'd like to see a whole article explaining how to use Asynchronous I/O? (in a generic way - which doesn't necessarily just mean NIO, but other asynch libs as well...)
Quote


Yes maybe this would be a good idea. Showing a general idea (the asynch io with all its pitfalls) and then presenting the specialized Java solution may the reader feel more familiar with terms like 'selecting' and 'keys'.

-

I like the Java programming very much and help as I can to spread its acceptance. Commenting Java-related articles is a really small contribution but it helps. :-)

cya

TheBohemian

---------------------------------------
my favorite OS: http://jnode.sf.net
Java 1.5 -> 1.4 converter: http://retroweaver.sf.net
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #18 - Posted 2003-09-13 00:20:22 »

I've just added (most of) the third article...although slightly confusingly it's number 2 in the series Smiley.

The index URL listing all of them is the same as before, i.e. (since it's on the previous page Smiley)

http://grexengine.com/sections/people/adam/

and the new article is at

http://www.grexengine.com/sections/people/adam/nio/SelectableChannel_SelectionKey_and_Selector.html

Comments and feedback still appreciated...Although I don't really care about spelling mistakes (I'll run through them with a fine toothcomb/spellchecker once they're finished) - I DO want to know ASAP if there are any factual mistakes, and I want to know if there are any bits that are difficult to understand, or go into too little detail.

EDIT: The new article is titled "SelectableChannel, SelectionKey, and Selector (The Three Main Parts of NIO)"

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #19 - Posted 2003-10-08 03:20:32 »

Quote
My main problem is that nio acts like an unbuffered input stream: you never know when you have gotten all of the bytes the other side sended. This should be highlighted more in an article.

Another story are these funky flip/mark/clear/limit Methods the nio-Buffers supports. Some images would be nice to describe their functionality to people who are not speaking english as their native language .. Cheesy


I've just updated all three of the articles. You should find that both your problems above are quite well addressed now - have a look and let me know what you think.

(note: you may need to hit refresh on the pages for each article - the webhosting company is rubbish, and the pages are being cached for longer than they should be...on MSIE, you may even have to Ctrl-f5, unless they've fixed that particular bug by now - the one where refresh doesn't always refresh, but ctrl-f5 does)

malloc will be first against the wall when the revolution comes...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (12 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!