{"id":6185,"date":"2009-12-30T09:59:08","date_gmt":"2009-12-30T13:59:08","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=6185"},"modified":"2015-06-03T16:50:07","modified_gmt":"2015-06-03T21:50:07","slug":"mmo-population-problems","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=6185","title":{"rendered":"MMO Population Problems"},"content":{"rendered":"<p>Someone emailed me with a series of questions about the server limits in MMO games.  The whole thing was too big to tackle in one go, but the central question was roughly:<\/p>\n<p>&#8220;Why can you have millions of people viewing the same webpage, but you can&#8217;t have more than a thousand or so users in the same shard of an MMO?&#8221;<\/p>\n<p>While the availability of processing power and bandwidth have skyrocketed in the last decade, that &#8220;1,000 users&#8221; number has changed very little in the same time period?  (And perhaps it&#8217;s even gone down in practice.)<\/p>\n<p>Welcome to the thorny problem of multiplayer worlds, which involves population density, server network throughput, client framerate, client side prediction, and a whole bunch of other variables. I&#8217;m not an expert at this by any stretch of the imagination (I usually stay away from server-side work) but I offer my non-expert overview of the problem here.<\/p>\n<p>Consider you, in an MMO, standing all by yourself:<\/p>\n<p><table width='256'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/traffic_alone.jpg' class='insetimage' width='256' alt='traffic_alone.jpg' title='traffic_alone.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>As you move around the world, you send your positional data to the server. At minimum, you need to send your x, y, and z position, along with a heading to indicate which way you&#8217;re facing and some additional data to indicate how you&#8217;re <em>moving<\/em>. You might also send data indicating if you&#8217;re looking up or down, and what other things you might be doing.  (Performing emotes, shooting, changing weapons, spell effects, etc etc.) <\/p>\n<p>How often this is sent depends on the game in question. A fast-paced action game might have a base framerate of 30fps, which works out to you sending your positional data 30 times a second.  (Or as close as your PC can come, if you&#8217;re really struggling to run the game.)  An MMO might get away with a lot less.  I wouldn&#8217;t be surprised if they only updated a few times a second. <\/p>\n<p><table width='800' class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/wowpop2.jpg' class='insetimage' width='800' alt='Goldshire represents a worst-worst case scenario: The worst distribution of the worst sort of players.' title='Goldshire represents a worst-worst case scenario: The worst distribution of the worst sort of players.'\/><\/td><\/tr><\/table><\/p>\n<p>In our case above, you send this positional data to the server, and in turn the server sends back its own idea of where you &#8220;really&#8221; are.  If you&#8217;re lagging it&#8217;s possible that you and the server might not agree.  The server is ultimately in charge, and so your game client will &#8220;correct&#8221; your position, yanking you back to where the server says you are.  People call this &#8220;rubber banding&#8221;, because you appear to walk forward and then snap back to where you were a few seconds ago.<\/p>\n<p>So you&#8217;re constantly sending your position, and the server is sending back your position.  For the sake of simplicity, let&#8217;s just assume these two things happen at the same rate.  You send one up, and get one back down.  The server gets one, and sends one back out.  No problem.<\/p>\n<p>Now, you find yourself standing near another user:<\/p>\n<p><table width='256'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/traffic_two.jpg' class='insetimage' width='256' alt='traffic_two.jpg' title='traffic_two.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>You send your data, and you get back data for two.  You get your position, and the other player&#8217;s position.  The other player gets the same deal.  One up, two down.  No problem.<\/p>\n<p>But the server is doing something different.  It&#8217;s getting two updates, but then it must send two updates to two people.  So, it gets two, but sends four.  I&#8217;m sure you can see where this is going:<\/p>\n<p><table width='256'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/traffic_twenty.jpg' class='insetimage' width='256' alt='traffic_twenty.jpg' title='traffic_twenty.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Twenty users.  Everyone sends an update, and gets twenty in return.  (Their own position, plus one for each of the other 19 people.)  The server gets twenty updates, and sends four hundred &#8211; twenty updates to twenty people. <\/p>\n<p>Well, obviously we&#8217;ve got a very annoying growth curve here where the outgoing updates is the square of the number of people in the environment.  <\/p>\n<p>We need to mitigate this problem if we want to get anywhere near making a half-decent MMO. We do this by trying to cut down on the numbers on both sides of the multiply sign:<\/p>\n<p><strong>Maximum Distance<\/strong><\/p>\n<p><table width='800' class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/wowpop1.jpg' class='insetimage' width='800' alt='The population here is distributed sparsely, but the people themselves are pretty dense.' title='The population here is distributed sparsely, but the people themselves are pretty dense.'\/><\/td><\/tr><\/table><\/p>\n<p>Obviously we can implement some sort of maximum-view radius. Everyone will only see other users that are within some reasonable distance. Picking a good value is crucial, and that &#8220;good value&#8221; depends on a lot of other factors. Making this value too small means people will pop in and out of view abruptly, and two people might have trouble finding each other even in a perfectly open area.  The woods might be thick with players, but if they&#8217;re spread out and I can only see people within twenty meters of me, the place can feel sort of empty.  Suddenly you start to lose the &#8220;massive&#8221; in MMO.<\/p>\n<p>On the other hand, people are not spread out evenly over the world. They tend to congregate in cities and around key locations. It might seem reasonable to see everyone within fifty meters when I&#8217;m out in the wilderness, but with a view distance like that I&#8217;ll be able to see almost everyone in town.  If you&#8217;ve ever been to the bank or the auction house in World of Warcraft, you know that a huge number of people cluster around those areas.  This optimization fails to help in dense areas, which is where most of the problem occurs. <\/p>\n<p><strong>Limit Viewable Characters<\/strong><\/p>\n<p>For the auction house clustering problem, you might consider putting an upper limit on how many people you can see. Perhaps if the local population gets to be extremely dense, everyone will only see the closest (say) forty people? <\/p>\n<p>This will introduce a little strangeness to the world, in that you&#8217;ll have I-can-see-you-but-you-can&#8217;t-see-me issues. To help picture this, imagine a super-simple world where you only see yourself and the one person closest to you:<\/p>\n<p><table width='256'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/traffic_radius.jpg' class='insetimage' width='256' alt='traffic_radius.jpg' title='traffic_radius.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Blue and green will each see one another and not be aware of yellow.  Yellow will see blue but not green. Try adding this feature to a game with PvP and see how fast it all flies apart and gameplay turns into a morass of confusion and exploits. <\/p>\n<p><strong>Cull Extraneous Data<\/strong><\/p>\n<p>Some games will go to great lengths to reduce how much data is sent.  For example, perhaps your vertical position is only sent when it changes.  (Left 4 Dead does this.)  This can let you leave out one of the x, y, z values if you don&#8217;t need it, although a feature like this would be worthless in a world without a good supply of flat surfaces.  <\/p>\n<p>An obvious way to cut down on data sent is to simply not send out updates for a character that&#8217;s standing still.  This works really well for people who might be using the bank, auction house, or a shop (finally! a technique that helps with the in-town crowds!) but won&#8217;t be a great deal of help in the wild when people are always on the move, looking around, and firing off abilities and spell effects.<\/p>\n<p>The server might decide to &#8220;throttle&#8221; updates from other users.  So, the game might give me ten updates per second if I&#8217;m with just one other person, but if I&#8217;m in a huge crowd I might get updates for other people once a second. I&#8217;ll still be able to see a huge crowd without bringing the server to its knees, but everyone else will appear to have very choppy or uneven movement.<\/p>\n<p><strong>CPU Concerns<\/strong><\/p>\n<p><table width='800' class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/wowpop3.jpg' class='insetimage' width='800' alt='Arg. So many people in the way. When are they gonna make a single-player version of this game?' title='Arg. So many people in the way. When are they gonna make a single-player version of this game?'\/><\/td><\/tr><\/table><\/p>\n<p>Ideally you&#8217;d want a system that scales based on what&#8217;s around the user.  If they&#8217;re out in the wilderness alone, it should be aggressive at showing other players and showing them at great distances.  But if they&#8217;re socializing in town on a Saturday night during a holiday event and the place is wall-to-wall with players, then the server should be working to limit how much you see.  Oh! Don&#8217;t forget that the server should always try to show you people who are in your party, even if they&#8217;re a little distance away and you&#8217;re in a crowd.  Also don&#8217;t forget that there&#8217;s an overhead to introducing you to someone new because it has to send a larger block of data describing their avatar.  And the server also needs to propagate chat messages which, while pretty lightweight on their own, still have to be sorted by distance and zone so that everyone sees the text that they should. Don&#8217;t forget that you need to transmit data for pets and mounts. And then the killer: moving all those tens (or perhaps hundreds) of thousands of monsters around and keeping players up to date on where they are.  <\/p>\n<p>Okay, it&#8217;s obvious that this stuff can get incredibly complex in a hurry. <\/p>\n<p>And typical of the tradeoffs that that you face in these sorts of situations: The more of these <strong>bandwidth<\/strong>-saving techniques we use, the more <strong>CPU<\/strong> we need.  In a world with 1,000 or 1,500 users (a common user count for an MMO) you can end up doing an absolute ton of per-frame-per-user operations.  For example, finding the closest 50 users for everyone in the world means doing a ton of distance calculations and sorting.  Every one of the 1,000 users has a unique list of monsters and other users that they can see.  That list needs to be updated and sorted on a regular basis.  While this doesn&#8217;t need to be done <em>every<\/em> frame, it&#8217;s still a nasty multiplicative problem because for each of the 1,000 users, the other 999 need to be considered for visibility. Any number that ends up being squared is a number you want to keep a low as possible.  <\/p>\n<p>We have lots of great algorithms for doing these sorts of sorting and comparison operations.  (A <strong>lot<\/strong> of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Information_science\">Information Science<\/a> theory is spent on these very subjects.  Very smart people were sorting and comparing massive lists of data long before anyone ever thought about making an MMO.) But even with our fancy new whiz-bang computers and advanced sorting technology, 1,000+ people moving X times a second produce (and demand) more than enough data to tax a server. Given the multiplicative effects of crowds, a modest increase in population can lead to  severe spikes in demand.<\/p>\n<p><table width='256'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/traffic_world.jpg' class='insetimage' width='256' alt='traffic_world.jpg' title='traffic_world.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>And in the end, do we <em>want<\/em> more than 1,000 people in the world with us at once? There is a certain &#8220;sweet spot&#8221;.  You don&#8217;t want that &#8220;ghost town&#8221; feel, but you also don&#8217;t want the &#8220;smothering&#8221; effect you get in high population areas.  Big cities are notorious for rudeness, small towns are famous for being friendly.  This isn&#8217;t because only jerks live in cities and only nice people live in small towns. There is a psychological effect to having a press of people around us, competing for our resources and taking up our elbow room.  People get impatient and edgy when they&#8217;re fighting a crowd.   But if you&#8217;ve got lots of resources and lots of room, you might even find yourself eager to connect with someone else.  You&#8217;re more inclined to greet them on the road and help them if you can. This behavior carries over to the virtual world. <\/p>\n<p>I think that despite an MMO being &#8220;massive&#8221;, it&#8217;s actually a lot more fun and a lot more conducive to team play if you can get people to have that &#8220;small town&#8221; feel.  That sense that we&#8217;re all in this together.  You want enough people that players will be able to meet, interact, and form groups, but few enough that they&#8217;ll actually want to. Even if your servers have lots of power and bandwidth and your MMO could support 5,000 simultaneous users, it would probably be detrimental to gameplay to do so. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone emailed me with a series of questions about the server limits in MMO games. The whole thing was too big to tackle in one go, but the central question was roughly: &#8220;Why can you have millions of people viewing the same webpage, but you can&#8217;t have more than a thousand or so users in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-6185","post","type-post","status-publish","format-standard","hentry","category-game-design"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/6185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6185"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/6185\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}