Threading questions

452 views
Skip to first unread message

Quasar

unread,
Jan 5, 2011, 8:32:05 PM1/5/11
to kryonet-users
Hi,

Just wondering - does the Server create more than one thread to accept
incoming messages from clients? I had a quick flick through the source
and it seems that only thread is created; but I just want to double
check here before making any assumptions.

Also, if the server only creates one thread, then if the server has a
*lot* of clients (a couple hundred) would the single thread suffice?
Would performance be enhanced if more threads to accept incoming
connections/messages were created?

Cheers,
Mic

PS. Just thought you might be interested to know that I'm writing a
MMORPG usually KryoNet :)
If you wanna take a look, there's a video here: http://www.youtube.com/watch?v=24zAUhn8cxE

Nate

unread,
Jan 6, 2011, 4:04:28 PM1/6/11
to kryone...@googlegroups.com
Hi Mic!

An MMORPG sounds like a lot of work. :)

Only one thread is created if you use the Server#start() method. This *should* scale to support many clients: certainly hundreds, probably thousands. It hasn't been pushed yet. I believe Hsaka has scaled up to hundreds with All Fours Online:
http://www.ttafo.com/

NIO has the ability to use multiple threads for non-blocking IO. KryoNet currently doesn't support more than one thread for simplicity, but that could change if there was a need. For now you will probably get very far with the single thread. When you receive objects on this thread, you can hand them off to other threads for processing. This would reduce the amount of time the server's network thread spends doing game logic, allowing it to service more clients. However, I wouldn't kill myself over this until it became a problem.

When doing "old IO", you have 1 (or 2) threads per client. Each threads eats up a chunk of memory for stack space. Also, with many threads, the OS may have a difficult time scheduling them all. There are a lot of factors involved with the number of clients this can support. I've read after about 10,000 connections or so you probably want to reduce the number of threads with NIO.

This is interesting:
http://en.wikipedia.org/wiki/Native_POSIX_Thread_Library

I've toyed with the idea of KryoNet supporting both NIO and old IO. It might happen someday.

-Nate



--
You received this message because you are subscribed to the "kryonet-users" group.
http://groups.google.com/group/kryonet-users

Hsaka

unread,
Jan 6, 2011, 5:46:16 PM1/6/11
to kryonet-users
Hey Mic, the game looks great so far!

In all the tests that I've done, the single server thread was able to
scale to several hundred clients without any problems. I'm pretty sure
it will be able to scale to well over a thousand clients.
The ttafo server uses Listener.QueuedListener to hand off to other
threads for game logic processing.

Quasar

unread,
Jan 7, 2011, 4:54:28 PM1/7/11
to kryonet-users
Alright.
Thanks for the detailed response, Nate. I probably won't ever reach
10,000 connections anyways :P

Thanks for the compliment, Hsaka. I checked out your game and it seem
sto be doing extremely well! Good on you :)
Reply all
Reply to author
Forward
0 new messages