I'm looking in code of "Rainning Sockets" : http://jniosocket.sourceforge.net I wondering if somebody use it for his own game here, and if you got comments about it (blah³ ? ) . I'm starting to hack around for understand how it work and kick HTTP out for put my own connected protocol

I'm looking in code of "Rainning Sockets" : http://jniosocket.sourceforge.net I wondering if somebody use it for his own game here, and if you got comments about it (blah³ ? ) . I'm starting to hack around for understand how it work and kick HTTP out for put my own connected protocol

'fraid I haven't really used it, just scanned it. Seems a worthwhile project, and seems to work fairly well.

If you want advice on HTTP...this is the standard way to optimize HTTP for ultra-high performance:

Use asynchronous I/O

Use one-pass parsers (i.e. they read directly from the ByteBuffer, building the in-memory data structures as they go; they don't read the whole thing, convert to a string, read it all again as a string, parse it several times over)

Work out what parts of an HTTP response are unchanging on your server, and clump them into direct ByteBuffers. Use gathering writes of your response body's, using views of those direct BB's to write.

...but watch out! If you don't use views then you can't send partial responses. Since you're using asynch I/O you probably will be sneding partial responses. If you can be sure each response will write atomically, you could actually use just one copy of each header buffer, and rewind it after each use.

...and in the experiments I did last year, 1.4.1 gathering writes can be VERY slow for no apparent reason (read: Sun's NIO team screwed up on the implementation). There's a thread here somewhere which has profiling data - I made a small demo of gathering writes and people posted performance figures. Most people could write about 10 buffers at *almost* full speed, others could only get about 4. In all cases, non-gathering writes were at least as fast or faster. This was only a simple test, so all I'm saying is test carefully - at the moment we use a "faked" gathering write class which actually uses single writes; if/when we get a fast gathering write working, we can just replace that one class.

Investigate shceduling algos - these make a BIG difference. In particular, look up SRPT, which seems to provide most bang for your buck. Bear in mind though that this makes your network logic start to get pretty complex. I wouldn't bother unless you are trying to show off or have a real need for this.

Use caches, lots of caches. Multiple layers of caches. Webserver's have managed to serve millions of hits hourly running Perl (!) just by intelligently layering caches on top of each other so that as much as possible of each page is cached between hits (usually you have front-end caches that cache things that never change, like images. Behind that you have 2nd line caches that cache things that rarely change. Then another layer with things that often change, etc etc. Really this is just an over-simplified version of staged servers, allowing you to tune each stage separately).

use hardware where possible. SSL accelerators in particular have a big effect (encrypting and decrypting can really slow down a webserver)....but I'm guessing this isn't an option for you

load-balancing across multiple servers. Most requests are side-effect free, so you can serve each request to a different server without having to worry about synchronization etc.

well I don't want to use http, I implement my own protocol (connecterd, not like HTTP)

O, I C. It should be fairly obvious that HTTP optimization is quite specialized, so I wouldn't recommend that. The best you could hope for is that raining sockets wasn't HTTP biased, in which case it would probably be hardly any better than writing your own NIO server from scratch.

I whould like to make my own NIO server from scratch, but where is sun doc about it ? So I try to find a starting point (like a working framework)

Have you looked at my NIO articles (incomplete, but still)? I updated them last in late February. There should be enough there to get a framework up and running (nb: I've had quite a few emails from people telling me they've used them successfully this way).

If there's some part that is lacking, let me know and I can try and improve it.

yes looked at it (and printed it), it's a good startIt helped me a lot to get started, now I think I get the selector/key/non-blocking system after lot of trial/error

Didn't seen the Tetris part it's new ? going to read it.

My remark about the article is the lack of a simple examples for the first part (like a simple ECHO server)

for example I wondered if I needed to cancel the key or unregister the channel when I finished to read a packet and want to register the channel as OP_WRITE, that can sound obvious but a simple example could solved it in 2 sec.

I whould like to have more info about how it behave in multiple threads environement and example of implementation using the usual strategies (4 stages, etc..)

but if you give me time next week (need to finish my work travel) I think I can write a simple echo server:) I whould like to write doc about NIO & server when I finished to understand the whole block, but my english doesn't help me much

My remark about the article is the lack of a simple examples for the first part (like a simple ECHO server)

Yeah, that's been suggested a couple of times now; my plan is to write complete source code for the tetris game, and make the final article just a description of the source code plus javadocs link plus the downloadable source itself.

Just haven't had time .

Quote

for example I wondered if I needed to cancel the key or unregister the channel when I finished to read a packet and want to register the channel as OP_WRITE, that can sound obvious but a simple example could solved it in 2 sec.

The different ops are independent. You can be registered for read and write simultaneously on one selector, or simultaneously on multiple selectors. They don't interact AT ALL, except that each key can only have one attachment.

Quote

but if you give me time next week (need to finish my work travel) I think I can write a simple echo server:) I whould like to write doc about NIO & server when I finished to understand the whole block, but my english doesn't help me much

If you (or anyone else) wants to compose the example snippets in the articles into complete working source I'm happy to help debug and advise on getting it working (and I can probably provide much of the necessary code for you) if I can then publish it in the article (with obvious credit to you of course). Best of all would be if someone would actually write a tiny tetris game as described in the article.

Part of the problem is that it's harder for me to write complete code because I have to be very careful not to copy code from my day job, and I find that difficult. So it's easy for me to contribute ideas and bits of code, and someone else will produce an example in their own "style" and I won't get into any trouble for giving away any of our classes .

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