Small online 2d RPG game, single vs. multithread server?

yes i know about this
but when you want to create an rpg with different dungeons etc you need to separate the game in different game loops etc
i thing that single threaded software architecture becouse every user needs different response
or at least i thing so

even with a bufferedwriter ?

using buffered Reader & Writer should just run fine, no ?

no tis is unrelated, having a single thread does not mean you will not differencite client, you just associate a socket per client

BufferedWriter/BufferedOutputStream flushes when their buffer is full, and flushing blocks.
=> Impossible to work around.

BufferedReader/BufferedInputStream only read when their buffer is empty, and reading blocks.
=> Work around by calling socket.getInputStream().available() directly.

thk, I did not kwnew about the flush block, that’s stupid… bha multithread is so much simpler :-X

The link above about Linux NPTL, states quite clearly that without NPTL the whole thing melts with just 400 connections.

We can learn 2 things from this. If you need cross platform scalability on networks you had better think hard about how many threads you have. And two, games don’t need huge scalability if done right compared to what high end servers mean with scalability (MMO notwithstanding of course, in which case you don’t need to care about cross platform of the server). So both approaches are quite doable.

But we should also learn a 3rd thing. Whats best depends. And what it depends on changes over time and OS.

In terms of ease of programing. TBO I found both pretty straightforward to implement. But I am getting lost on why you need the BufferedReaders/Writers etc? Its network IO we talking about right? I which case the nio/net packages do that for you. A TCP connection will have NAGLE or whatever its called enabled by default and won’t send a packet until the buffer is full. The reads will always have a (or more) packet buffered.

about the buffered it was just a parentesis on a possible workaround when using (or forced to use) blocking socket vs pooling non-blocking socket (personally I prefer full blocking on a separated thread both for server and client, but that just a matter of taste ) I am just not enought confident in letting a library manage buffers for me.

my english is sometime limited does the paper stand that 400 threads will blowup a linux serveur ? seems strange as found it pretty low ?

anyway this discussion is pretty interresting for me as I am being writing a MMO and even if we will do earlier heavy benchmark, I wouldn’t really like to have any surprise but 400 threads/users per servers is already enought…

On standard Linux 1000 threads with only one doing something is fine. But if they all need to work… Then they you will often get very high CPU usage but no thread will make much progress. Or alternatively most threads will never get a turn. Even with a few threads you need to be careful that some threads don’t get shut out from ever having a turn with the use of a shared object (aka the network).

It should be pointed out that on a computer with one network card, only two things can really happen at once. Sending/receiving single packets. Thus a few 100 threads on a single card does imply that most will have nothing to do at any given time (yes I am ignoring individual socket buffers).

If you are writing something scalable then general wisdom is you use both approaches. That is you have a number of connects handled by a single thread, but you also have many threads. If however you can specify what type of hardware/OS the server is then reading up on NPTL would be a good idea .

thanks for all those informations.

for now I have choosen to build a hierarchical network architecture, so I should be able to put new server pretty easily if I fall in a maximum connection problem, something like :

Level 1 Level 0
----A-----|
----B-----|----abc—abc----D
----C-----|

“A” receive up to 500/1000 connection & it multiplexe them via a single connection to “D” (same for B / C)

so with only two “stage/level” and 20 servers in front I should be able to reach up 201000 = 20000 persistents connections… but would be really better for example to have 102000 or 4*5000 so I will take care to read about NPTL and possible overthread issues