{"id":287,"date":"2015-08-19T07:53:21","date_gmt":"2015-08-19T07:53:21","guid":{"rendered":"http:\/\/smartfoxserver.com\/blog\/?p=287"},"modified":"2015-08-19T10:10:42","modified_gmt":"2015-08-19T10:10:42","slug":"fine-tuning-room-lists","status":"publish","type":"post","link":"https:\/\/smartfoxserver.com\/blog\/fine-tuning-room-lists\/","title":{"rendered":"Fine tuning Room Lists"},"content":{"rendered":"<p>In this new recipe we will take a look at how to optimize the Room List that SmartFoxServer 2X sends to each\u00a0client.<\/p>\n<p>Room Lists are very important to show players what is going on in the server and allow them to quickly find games to join. Sometimes, however, they can get too big and result in a waste of bandwidth and information overload for clients.<\/p>\n<p><!--more--><\/p>\n<h3>\u00bb Room Lists in a nutshell<\/h3>\n<p>SmartFoxServer 2X\u00a0sends the Room List to clients once,\u00a0in response to a successful login event. After this it only\u00a0sends updates related to changes in the list which include: a Room being added or removed and any change in the count of players and spectators in any Room.<\/p>\n<p>While this may sound like a lot of updates, especially in high traffic situations, the actual update packets are pretty small, in the order of 30 bytes and the SmartFoxServer API offer a number of tools to fine tune how all these events are generated.<\/p>\n<h3>\u00bb\u00a0Fine tuning the contents of the Room List<\/h3>\n<p>The first and most important aspect of the Room List is deciding\u00a0which Rooms the player will be able to see when he logs in the system.<\/p>\n<p>SmartFoxServer 2X provides a convenient way for\u00a0categorizing Rooms in different\u00a0<strong>Room Groups.\u00a0<\/strong>If you&#8217;re not familiar with the concept, we highly recommend that you take a look at our &#8220;<a title=\"Room Architecture\" href=\"http:\/\/docs2x.smartfoxserver.com\/DevelopmentBasics\/room-architecture\" target=\"_blank\">Room Architecture<\/a>&#8221; article in main documentation website.<\/p>\n<p>The purpose of Groups is to segregate different types of Rooms (for example all Poker Rooms, from all Lobby Rooms) so that users can just see one portion of the full Room List, based on their current activity.<\/p>\n<p><a href=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/room-groups-diag.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-290\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/room-groups-diag.png\" alt=\"room-groups-diag\" width=\"410\" height=\"308\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/room-groups-diag.png 410w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/room-groups-diag-300x225.png 300w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><\/a><\/p>\n<p>For example, if your server hosts a number of different games there&#8217;s no need for players interested in playing <strong>Game A<\/strong> to see and receive updates for all <strong>Game B<\/strong> Rooms. Instead clients can dynamically subscribe and unsubscribe to Room Groups according to their interest, thus avoiding to deal with huge Room Lists.<\/p>\n<p>The first thing to configure is your Zone&#8217;s &#8220;Default Groups&#8221; setting, which specifies which Room Groups are going to be auto-subscribed upon login by any User.<\/p>\n<p>To do this open the <strong>AdminTool<\/strong> &gt; <strong>Zone Configurator<\/strong> and edit the field making sure only the Groups that are strictly needed are\u00a0subscribed to. If your application doesn&#8217;t require Users to see any Rooms when they have just logged in, you can leave the field empty.<\/p>\n<p><a href=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/DefRoomGroups.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-291\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/DefRoomGroups.png\" alt=\"DefRoomGroups\" width=\"415\" height=\"140\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/DefRoomGroups.png 415w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/DefRoomGroups-300x101.png 300w\" sizes=\"(max-width: 415px) 100vw, 415px\" \/><\/a><\/p>\n<h3>\u00bb\u00a0Fine tuning Room Events<\/h3>\n<p>Once the User is subscribed to one or more Room Groups he will start to receive a number of events that can be tweaked in several different ways.<\/p>\n<ul>\n<li><strong>ROOM_ADD<\/strong>: notified when a new Room has been created in any of the subscribed Groups<\/li>\n<li><strong>ROOM_REMOVE<\/strong>: notified when a Room is destroyed<\/li>\n<li><strong>ROOM_VARIABLES_UPDATE<\/strong>: notified for RoomVariables that have the &#8220;global&#8221; flag turned on<\/li>\n<li><strong>USER_COUNT_UPDATE<\/strong>: notified every time the user and spectator count of a Room changes<\/li>\n<\/ul>\n<p>The first two events (<strong>ROOM_ADD<\/strong> \/ <strong>ROOM_REMOVE<\/strong>) are mandatory: they represent the essential mechanisms by which the Room List is kept synchronized with Users. There&#8217;s not much we can tweak for these two: we either receive them or not, and this is based on the choice of subscribing\/unsubscribing to a specific group.<\/p>\n<p><strong>ROOM_VARIABLES_UPDATE\u00a0<\/strong>is a different beast: normally Room Variables are only visible to the Users that are joined in a specific Room. People from &#8220;outside&#8221; don&#8217;t see the variables and don&#8217;t receive any updates.<\/p>\n<p>Additionally, RoomVariables can be marked as <strong>global\u00a0<\/strong>which makes them visible from outside without the need of joining the target Room. This can be useful to provide extra information to players before they choose which Room they want to join. This however\u00a0has a small cost: every global Room Variable update is dispatched to all people subscribed to the Room Group.<\/p>\n<p>We highly recommend to keep this in mind when working with global Room Variables, especially if they are intended for very frequent updates, as this may potentially use significant resources.<\/p>\n<p>Finally we have the\u00a0<strong>USER_COUNT_UPDATE\u00a0<\/strong>event which keeps everyone in sync about the number of players and spectators in every Room. In high traffic situations these events can be generated every few milliseconds causing a lot of small packets to be sent continuously to all clients.<\/p>\n<p>To optimize this event, SmartFoxServer provides a specific <strong>User Count Event Throttler<\/strong> which allows the system to aggregate multiple updates at\u00a0specific intervals before sending them. This way we\u00a0can save significant bandwidth at the cost of a slightly &#8220;less real-time&#8221; user count updates (which is usually acceptable).<\/p>\n<p>By default we recommend to set the Throttler to 1000ms. The setting is per Zone and it can be changed from the <strong>Admin Tool<\/strong> &gt; <strong>Zone Configurator<\/strong>, under the <strong>Advanced<\/strong> tab.<\/p>\n<p><a href=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/ucount-throttler.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-292\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/ucount-throttler.png\" alt=\"ucount-throttler\" width=\"668\" height=\"223\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/ucount-throttler.png 668w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/ucount-throttler-300x100.png 300w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/ucount-throttler-624x208.png 624w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><\/a><\/p>\n<h3>\u00bb\u00a0Working without Room Lists<\/h3>\n<p>There is one last interesting concept that is also worth discussing, which involves avoiding Room Lists altogether. A number of games and applications may not require that the client knows about the details of every Room available, at all.<\/p>\n<p>The Room List is essentially needed only when the joining process is left to the User entirely, but there are many scenarios in which the server side logic will decide where to join the players instead.<\/p>\n<p>Let&#8217;s explore a simple use case:<\/p>\n<p><a href=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/simple-use-case.png\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-295\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/simple-use-case.png\" alt=\"simple-use-case\" width=\"522\" height=\"169\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/simple-use-case.png 522w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2015\/07\/simple-use-case-300x97.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/a><\/p>\n<ul>\n<li>We have one main Lobby Room where all Users are joined as soon as they log in. We don&#8217;t need to know about any other Room from client side, because the joining will be done on the server side.<\/li>\n<li>A number of Game Rooms are available.<\/li>\n<\/ul>\n<p>In this scenario we don&#8217;t need Room Groups and we can avoid sending any Room List related data to the client. To do this we simply leave the Zone&#8217;s &#8220;Default Room Groups&#8221; setting empty.<\/p>\n<p><strong>NOTE<\/strong>: even without a local Room List clients can still join Rooms from their side if they know the name of the target Room. If you want to completely remove the possibility for clients to send <strong>JoinRoom<\/strong> requests you will need to inhibit the functionality from the Permission Profiles.<\/p>\n<p>You can learn more about it in this <a title=\"Permission Profiles doc\" href=\"http:\/\/docs2x.smartfoxserver.com\/AdvancedTopics\/privilege-manager\" target=\"_blank\">documentation page<\/a><\/p>\n<h3>\u00bb Conclusions<\/h3>\n<p>To recap, there are a number of strategies we can employ to optimize the traffic generated by the Room List and it&#8217;s related updates:<\/p>\n<ul>\n<li>Use Room Groups to\u00a0your advantage by\u00a0separating Rooms in different\u00a0categories.<\/li>\n<li>Make sure the player only subscribes to the Room Groups that he needs to see in his\/her current state.<\/li>\n<li>Unsubscribe to any Room Group that is no longer required by the application.<\/li>\n<li>Tread lightly with global Room Variables, they can be useful if used sparingly.<\/li>\n<li>Configure the\u00a0USER_COUNT throttler to a default of 1000ms or higher to avoid excessive user count updates.<\/li>\n<li>When possible, move the Room joining logic on the server side and avoid subscribing to too many Room Groups or avoid the Room List altogether.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this new recipe we will take a look at how to optimize the Room List that SmartFoxServer 2X sends to each\u00a0client. Room Lists are very important to show players what is going on in the server and allow them to quickly find games to join. Sometimes, however, they can get too big and result [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[40,34,32,7],"_links":{"self":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/287"}],"collection":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":8,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"predecessor-version":[{"id":327,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/287\/revisions\/327"}],"wp:attachment":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}