   1 thread per user or 1 thread to run all packets
  Heya guys. Im currently writing the basics of my MMORPG's server. And, I was wondering, what is better;Making a new thread for every user, or just using 1 thread to process all packets? ~ Quil   
  hrm..   my instincts tell me it's too costly to have one thread per user. maybe one thread per 50 users?  100? 500??  definitely not one for one... but I actually don't know what I'm talking about.   ;  A thread per client is acceptable when the number of clients is small, but it is not scalable. A OS thread is quite an expensive, on Windows a thread comes with (by default) a 1 MB stack. So, 500 clients means 500MB of thread stack, and it gets worse with more clients.You can use select() or equivalent, which is quite good up to a given number of connections (which varies with the OS, or so I've heard). Then you can use the most complex but supposedly the best methods, like IOCP on Windows (I'm sure there is something similar on Linux).   ;Quote:Original post by rip-offA thread per client is acceptable when the number of clients is small, but it is not scalable. A OS thread is quite an expensive, on Windows a thread comes with (by default) a 1 MB stack. So, 500 clients means 500MB of thread stack, and it gets worse with more clients.You can use select() or equivalent, which is quite good up to a given number of connections (which varies with the OS, or so I've heard). Then you can use the most complex but supposedly the best methods, like IOCP on Windows (I'm sure there is something similar on Linux).Im using Windows Vista. :P (Vista sucks, but I cant get XP on my laptop :S).I never heard of IOCP or w/e, and dont how to use select.. Can you give me an example?   ;  Google gives plenty of results for socket select example and IOCP example.   ;  One thread per user is definitely something to avoid, as the other posters have already stated. Not only does it have a heavy impact on performance as the number of clients grows -- it also introduces many hard-to-find bugs in your application such as deadlocks and race conditions, if not designed properly. Based on your post you appear to be a beginner (pardon me if I'm wrong), and if that's the case I would avoid multithreading altogether for now, and simply use select(); you can always migrate to a more scalable method later. Quote:Original post by rip-offThen you can use the most complex but supposedly the best methods, like IOCP on Windows (I'm sure there is something similar on Linux).There is; see epoll. :)After googling a bit I also found this: http://blog.kovyrin.net/2006/04/13/epoll-asynchronous-network-programming/.   ;  The Forum FAQ is pretty clear that thread-per-client isn't what you want to do.Also, I think that Vista (from 2006) is a significant step up from XP (from 2001). Anyone wanting XP is probably the same kind of person who wanted 2000 still when XP SP2 came out -- it's easier to not change, but you shouldn't confuse "I don't feel a need to change" (which is fine) with "the older version is better than the newer version" (which is seldom actually the case).When it comes to networking, Vista is a lot less insecure than XP, and it ships with default IPv6 support, among other things.   ;Quote:Original post by hplus0603When it comes to networking, Vista is a lot less insecure than XP, and it ships with default IPv6 support, among other things.And FreeBSD is a lot more secure than Vista ;)  , in fact every POSIX system is better than Vista on network security.If you want to take advantage of multi-thread capabilities for processing packets, you also must think about Thread Pools; they provide an efficient way for distributing the workload of processing a huge amount of tasks from many clients.Java has it's Concurrent framework for processing a lot of tasks with a limited amount of Worker threads . (See Doug Lea's  java.util.concurrent package )At c++ you could use Intel Thread Building Blocks too.I also recommend give a try to Sun's project Darkstar for building MMORPGs systems.;Quote:Original post by superoptimoAnd FreeBSD is a lot more secure than Vista ;)  , in fact every POSIX system is better than Vista on network security.In my experience, security is an organizational problem, involving management and administration. There are networks running banking systems on Windows that are air-tight, and there are linux systems, where unencrypted /var/mail directories are symlinked to user's public www directories - for easier backup.I've also made a personal observation. Windows XP+ behind NAT router is very secure, excluding the ID10T errors. Same system directly on net however is a lost cause. Those stories about virgin installs getting infected in 10 minutes are quite true.While this obviously falls very much in line with MS propaganda, the recent news of Linux reaching 1% market share really made me think, especially after taking into consideration the way machines are actually used.I'd still say that price will be the first decision point when choosing an OS, and that includes finding administrators for such system. Just like with usage ratio, it may actually be considerably cheaper and faster to find a fresh MSCP to put things in place and keep them running, than finding a *nix guru to do the same.   ;Quote:I also recommend give a try to Sun's project Darkstar for building MMORPGs systems.While it's an interesting case study, have you actually tried building and operating an MMO on Darkstar? As far as I can tell, those who have tried it in anger has realized that the architecture differences actually hurt (no ad-hoc reporting, etc), and the transaction infrastructure only works for transactional thing (trade, spells, etc), and not for the real-time simulation part (movement, combat).