{"id":283,"date":"2024-11-20T21:42:57","date_gmt":"2024-11-20T21:42:57","guid":{"rendered":"https:\/\/shrubbgames.com\/?p=283"},"modified":"2024-11-20T21:44:02","modified_gmt":"2024-11-20T21:44:02","slug":"vv-eekly-update-23-networking-2","status":"publish","type":"post","link":"https:\/\/shrubbgames.com\/?p=283","title":{"rendered":"VV Eekly Update #23 &#8211; Networking 2"},"content":{"rendered":"\n<p>Hello everyone, and welcome back to the VV Eekly Update! It has been a <em>very<\/em> long time since the last update &#8211; a whole two weeks! In case anyone missed it, I decided to turn this into a <strong>VV Bi Eekly Update<\/strong>, only updating every two weeks. Here&#8217;s the message I posted last week:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Hey @Eekly Updates! Quick update &#8211; I\u2019m now planning on doing biweekly updates for VV Eekly Update. Two big reasons for that: First, the release date being moved back to the summer in 2025 means that there\u2019s a much longer runway. I\u2019m afraid that I just don\u2019t have that much content to share! Second, the work is getting to the point where I need to do little tweaks, fix little bugs, and put a lot of time into tasks. There\u2019s not too much that I can show off anymore week-to-week.<\/p>\n<\/blockquote>\n\n\n\n<p>I&#8217;m sorry to everyone who has been looking forward to reading the VV Eekly Update mid-week every week, but I think this is the right decision to make sure I can stay productive on getting <em>Vyn and Verdan<\/em> out the door!<\/p>\n\n\n\n<p>Anyway, today, I&#8217;m going to be telling you a bit about a networking issue that we discovered in a playtest, and what I&#8217;m doing to investigate and mitigate the issue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Problem<\/h2>\n\n\n\n<p>Playtests have been going fairly well! As my head playtester-in-chief said, it&#8217;s starting to feel like <em>Vyn and Verdan<\/em> is a real game instead of a bug-laden tech demo. That&#8217;s very exciting! However, there&#8217;s definitely still issues that we come across. One issue that we found only occurs in certain rooms.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"575\" src=\"https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-1024x575.png\" alt=\"\" class=\"wp-image-285\" srcset=\"https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-1024x575.png 1024w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-300x168.png 300w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-768x431.png 768w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-1536x862.png 1536w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-3-2048x1149.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Essentially, in rooms with a <em>lot<\/em> of enemies, the ping jumps up really high! You can see in the top right corner of this picture that the ping says it&#8217;s 4232 ms (milliseconds). We had been testing with computers in the same room, and the ping had been a mere 32 ms before. This means that the non-hosting player will feel a lag of 4 whole seconds when moving, dodging, and using abilities. Obviously, this isn&#8217;t great.<\/p>\n\n\n\n<p>How did I approach debugging this problem? First, some background: ping measures the <em>round-trip<\/em> time for a packet to be sent from one player to the other. I implemented a fairly simple system in <em>Vyn and Verdan<\/em> that just sends a ping from the host to all connected players that then waits for the ping to be returned.<\/p>\n\n\n\n<p>When I say it&#8217;s &#8220;fairly simple&#8221; &#8211; I mean it. There&#8217;s not much to it! It doesn&#8217;t interact with the rest of the game at all! That was pretty confusing to me &#8211; how could this possibly be impacted by what room the players are in?<\/p>\n\n\n\n<p>With some further investigation, I found the answer. The game engine, Godot, actually processes all incoming RPCs within a single queue in the order that they arrive. You can imagine that, for example, in a really busy room with lots of enemies, that queue might take longer to process than there&#8217;s time between frames, meaning that the queue gets overloaded. I&#8217;m assuming that Godot automatically purges non-mandatory requests when the queue gets too long, which is why the ping didn&#8217;t keep increasing to infinity. You can split incoming RPCs into different queues to make sure that one queue getting clogged doesn&#8217;t clog different RPCs, which is what I needed to do to fix the ping measurement!<\/p>\n\n\n\n<p>However, there was still the issue of the lag in busy rooms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Network Clog<\/h2>\n\n\n\n<p>After some investigation, I boiled down the problem to &#8220;there&#8217;s too much data being sent&#8221;. Clearly, the solution is &#8220;reduce the amount of data being sent&#8221;. But how?<\/p>\n\n\n\n<p>Thankfully, Godot has some pretty nifty tools to help debug network usage.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"244\" src=\"https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4-1024x244.png\" alt=\"\" class=\"wp-image-286\" srcset=\"https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4-1024x244.png 1024w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4-300x71.png 300w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4-768x183.png 768w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4-1536x365.png 1536w, https:\/\/shrubbgames.com\/wp-content\/uploads\/2024\/11\/image-4.png 1992w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can see here the <strong>Network Profiler<\/strong> that Godot has embedded. It&#8217;s not exactly the same as what gets sent on the network &#8211; there&#8217;s protocol headers, protocol compression, other lower level stuff &#8211; but this definitely can show you what&#8217;s the biggest offenders and whether your changes help.<\/p>\n\n\n\n<p>The problem manifested only in rooms with at least 20 enemies. Therefore, although I&#8217;m sure it would help to reduce some of the other load that&#8217;s not enemy-related, I should focus on reducing enemy usage.<\/p>\n\n\n\n<p>You can see in the screenshot above that enemies will send ~116 bytes in every RPC. That includes where the enemy is located, what the enemy&#8217;s label is, what the enemy&#8217;s health is at, and what the enemy&#8217;s max health is at. Enemies will also send this data every frame.<\/p>\n\n\n\n<p>But wait&#8230; the enemy&#8217;s max health never changes, and I decided against showing the enemy&#8217;s label! If I remove those, then the enemies only send ~84 bytes in every RPC! Wow, that&#8217;s a ~25% improvement!<\/p>\n\n\n\n<p>I&#8217;m in the middle of this process so far &#8211; finding what small improvements I can make here or there to make a huge improvement to the lag issue. After compressing the data a little more, next on my list is only sending the data every few frames rather than every frame. Theoretically, that should cut down on the data usage by a LOT.<\/p>\n\n\n\n<p>If you have any comments about today&#8217;s VV Eekly Update, please ping them my way in an appropriate number of bytes in the regular Discord!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello everyone, and welcome back to the VV Eekly Update! It has been a very long time since the last update &#8211; a whole two weeks! In case anyone missed it, I decided to turn this into a VV Bi Eekly Update, only updating every two weeks. Here&#8217;s the message I posted last week: Hey [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":73,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[3],"tags":[],"class_list":["post-283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vv-eekly-updates"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/posts\/283"}],"collection":[{"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283"}],"version-history":[{"count":2,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":288,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions\/288"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=\/wp\/v2\/media\/73"}],"wp:attachment":[{"href":"https:\/\/shrubbgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shrubbgames.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}