{"id":1227,"date":"2019-12-09T11:09:50","date_gmt":"2019-12-09T11:09:50","guid":{"rendered":"http:\/\/smartfoxserver.com\/blog\/?p=1227"},"modified":"2019-12-09T11:38:17","modified_gmt":"2019-12-09T11:38:17","slug":"sfs2x-2-14-boosts-performance-for-all-web-services","status":"publish","type":"post","link":"https:\/\/smartfoxserver.com\/blog\/sfs2x-2-14-boosts-performance-for-all-web-services\/","title":{"rendered":"SFS2X 2.14 boosts performance for all web services"},"content":{"rendered":"<p>The launch of SmartFoxServer 2.14 is particularly significant for all the web-related services, in particular Websockets and BlueBox. This was an area where we were still looking for performance improvements but we were mostly dependent on the underlying\u00a0dependency\u00a0used for this service, namely Jetty.<\/p>\n<p><!--more--><\/p>\n<h2>\u00bb The good, the bad, the slow<\/h2>\n<p>While Jetty 9.x is a flexible and overall\u00a0good enough platform for deploying web services, we&#8217;ve always found that its performance left something to be desired, in particular in the Websocket department. When we originally\u00a0integrated it in SmartFoxServer 2X 2.9 (as a replacement for the older Jetty 6.x) we had already done\u00a0lots of performance tests and\u00a0provided ample\u00a0feedback to the Jetty team,\u00a0 indicating\u00a0which areas needed improvement.<\/p>\n<p>Unfortunately many of these issues haven&#8217;t been addressed over the course of the past 5 years and very recently we stumbled upon even more performance problems that we could only partially solve on our side. Since then we had started testing other solutions, such as Apache Tomcat, to potentially replace Jetty and during summer 2019 we finally decided to move to Tomcat as the servlet container for SmartFoxServer 2X.<\/p>\n<p>With Tomcat we immediately found several welcome improvements:<\/p>\n<ul>\n<li><strong>a lean, well-organized distribution<\/strong>: the tomcat 9.x distro is very light and comes with a file structure and configuration system that makes sense immediately. On the other hand Jetty has gotten very bloated with each new release and system files get often reworked or shuffled around, which breaks consistency on almost every update.<\/li>\n<li><strong>excellent performance<\/strong>: both standard HTTP and Websocket performance is decidedly better than Jetty, by a long shot actually. We have seen\u00a0massive reductions in memory footprint and CPU usage (more details in a moment).<\/li>\n<li><strong>fine grained management<\/strong>: Tomcat comes with its own set of tools to monitor and manage running applications which is a welcome addition and facilitates the deployment of new servlets.<\/li>\n<\/ul>\n<h2>\u00bb\u00a0So&#8230; what changes now?<\/h2>\n<p>Well, you&#8217;ll be glad to hear that <strong>nothing really changes<\/strong> for SmartFoxServer developers.\u00a0All of your applications using the <strong>BlueBox<\/strong> or <strong>Websocket<\/strong>\u00a0will continue to work transparently, and with a\u00a0significant\u00a0improvement in efficiency!<\/p>\n<p>All of the changes we&#8217;ve made are\u00a0hidden under the hood and because HTTP and Websocket are standard protocols there\u00a0is no need to change anything in your current code.<\/p>\n<p>Also if you were running custom servlets you should be able to deploy them under Tomcat just like you did before with Jetty.\u00a0The only exception\u00a0might be\u00a0for servlets using specific Jetty features, which is normally\u00a0very unlikely.<\/p>\n<h2>\u00bb\u00a0What sort of improvement should you expect?<\/h2>\n<p>To give you an idea here is the same stress test, based on Websocket, and running under the previous SFS2X 2.13.6 (w\/ Jetty) and the new SFS2X 2.14 (w\/ Tomcat).<\/p>\n<p><strong>The setup:<\/strong><\/p>\n<ul>\n<li>Packet Cloud t1.small.x86\n<ul>\n<li>Intel Atom C2550, quad core @2.4Ghz<\/li>\n<li>8GB RAM<\/li>\n<li>2.5Gbs network<\/li>\n<\/ul>\n<\/li>\n<li>5000 Concurrent users<\/li>\n<li>Users are joined in Rooms created with a random capacity of 5-10 users, then they start sending\u00a0public chat messages\u00a0to each others, every 900 milliseconds. Each message is ~50 characters.<\/li>\n<\/ul>\n<p>This is what <strong>SmartFoxServer 2.13.6 + Jetty<\/strong> looks like:<\/p>\n<ul>\n<li>Process CPU: ~43.5%<\/li>\n<li>Allocated heap: 3.5GB<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1230\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Jetty-5kCCU.png\" alt=\"\" width=\"800\" height=\"560\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Jetty-5kCCU.png 800w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Jetty-5kCCU-300x210.png 300w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Jetty-5kCCU-768x538.png 768w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Jetty-5kCCU-624x437.png 624w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>This is what <strong>SmartFoxServer 2.14.0 + Tomcat<\/strong>\u00a0looks like:<\/p>\n<ul>\n<li>Process CPU: ~28%<\/li>\n<li>Allocated heap:\u00a0900MB<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"aligncenter size-full wp-image-1231\" src=\"http:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Tomcat-5kCCU.png\" alt=\"\" width=\"800\" height=\"560\" srcset=\"https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Tomcat-5kCCU.png 800w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Tomcat-5kCCU-300x210.png 300w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Tomcat-5kCCU-768x538.png 768w, https:\/\/smartfoxserver.com\/blog\/wp-content\/uploads\/2019\/12\/Tomcat-5kCCU-624x437.png 624w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Under Tomcat there is almost a <strong>90% improvement in CPU usage<\/strong> and a <strong>three fold reduction in memory usage<\/strong>.<\/p>\n<h2>\u00bb\u00a0Tomcat\u00a0management<\/h2>\n<p>As mentioned at the top of the article, Tomcat comes with its own <strong>management tool<\/strong> which allows to check every detail of the server&#8217;s state and start\/stop\/redeploy every servlet in the system.<\/p>\n<p>The tool is\u00a0browser based and can be accessed via <strong>http(s):\/\/&lt;ip-address&gt;:&lt;port&gt;\/manager<\/strong>, but before you attempt to access it you will need to set your credentials.<\/p>\n<p>To do so you need to edit the tomcat-users.xml file located under <strong>SFS2X\/lib\/apache-tomcat\/conf\/\u00a0<\/strong>adding the following lines:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;role rolename='manager-gui'\/&gt;\r\n&lt;user username='MyUserName' password='MyAdminPassword' roles='manager-gui'\/&gt;\r\n<\/pre>\n<p>To learn more about this tool check the Tomcat&#8217;s <a href=\"https:\/\/tomcat.apache.org\/tomcat-9.0-doc\/manager-howto.html\" target=\"_blank\" rel=\"noopener noreferrer\">official documentation<\/a> here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The launch of SmartFoxServer 2.14 is particularly significant for all the web-related services, in particular Websockets and BlueBox. This was an area where we were still looking for performance improvements but we were mostly dependent on the underlying\u00a0dependency\u00a0used for this service, namely Jetty.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[115,116,9],"_links":{"self":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1227"}],"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=1227"}],"version-history":[{"count":12,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1227\/revisions"}],"predecessor-version":[{"id":1257,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/posts\/1227\/revisions\/1257"}],"wp:attachment":[{"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/media?parent=1227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/categories?post=1227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartfoxserver.com\/blog\/wp-json\/wp\/v2\/tags?post=1227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}