sockets - JAVA NIO ByteBuffer allocatation to fit largest dataset? -


I am working on an online game and kills a few difficulties while working on the server side of things. / P>

When using non-blocking socket in Java, what is the best action to handle the full packet data set, which can not be processed until all data is available? For example, sending a large 2D tiled map to the socket.

I can think of two ways to handle it:

  1. Handling a bytebuff on a large scale, from my example, on a large 2D tiled map Continue to add data to the complete data set buffer needed to process, until all of this is achieved and there is a process from there.

  2. If the bytebuffer is a small size (maybe 1500), then it can be read later and as long as the file can not be completely processed, one Out of file It prevents big bitbuffers, but decreases performance due to disk I / O.

I am using a dedicated ByteBuffer for each socket channel so that I can read the data until it is complete for processing the problem is that if My 2D tiled map is equal to 2 MB size, is it really to use 1000 2MB byte buffers (assuming 1000 customer limit and all they are in use)? There is a better way that I am not thinking about it.

I like to keep things simple, but I am open to any suggestions and appreciate the help. Thanks!

Perhaps the best solution for now is to use a full 2 ​​MB byte buffer and let the OS take Paging care on the disk (virtual memory) If necessary, you probably will not have 1000 concurrent users right away, and when you do, you can customize, you might be surprised that what are your real performance issues.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -