SFS2X 2.14 boosts performance for all web services

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 dependency used for this service, namely Jetty.

» The good, the bad, the slow

While Jetty 9.x is a flexible and overall good enough platform for deploying web services, we’ve always found that its performance left something to be desired, in particular in the Websocket department. When we originally integrated it in SmartFoxServer 2X 2.9 (as a replacement for the older Jetty 6.x) we had already done lots of performance tests and provided ample feedback to the Jetty team,  indicating which areas needed improvement.

Unfortunately many of these issues haven’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.

With Tomcat we immediately found several welcome improvements:

  • a lean, well-organized distribution: 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.
  • excellent performance: both standard HTTP and Websocket performance is decidedly better than Jetty, by a long shot actually. We have seen massive reductions in memory footprint and CPU usage (more details in a moment).
  • fine grained management: 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.

» So… what changes now?

Well, you’ll be glad to hear that nothing really changes for SmartFoxServer developers. All of your applications using the BlueBox or Websocket will continue to work transparently, and with a significant improvement in efficiency!

All of the changes we’ve made are hidden under the hood and because HTTP and Websocket are standard protocols there is no need to change anything in your current code.

Also if you were running custom servlets you should be able to deploy them under Tomcat just like you did before with Jetty. The only exception might be for servlets using specific Jetty features, which is normally very unlikely.

» What sort of improvement should you expect?

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).

The setup:

  • Packet Cloud t1.small.x86
    • Intel Atom C2550, quad core @2.4Ghz
    • 8GB RAM
    • 2.5Gbs network
  • 5000 Concurrent users
  • Users are joined in Rooms created with a random capacity of 5-10 users, then they start sending public chat messages to each others, every 900 milliseconds. Each message is ~50 characters.

This is what SmartFoxServer 2.13.6 + Jetty looks like:

  • Process CPU: ~43.5%
  • Allocated heap: 3.5GB

This is what SmartFoxServer 2.14.0 + Tomcat looks like:

  • Process CPU: ~28%
  • Allocated heap: 900MB

Under Tomcat there is almost a 90% improvement in CPU usage and a three fold reduction in memory usage.

» Tomcat management

As mentioned at the top of the article, Tomcat comes with its own management tool which allows to check every detail of the server’s state and start/stop/redeploy every servlet in the system.

The tool is browser based and can be accessed via http(s)://<ip-address>:<port>/manager, but before you attempt to access it you will need to set your credentials.

To do so you need to edit the tomcat-users.xml file located under SFS2X/lib/apache-tomcat/conf/ adding the following lines:

<role rolename='manager-gui'/>
<user username='MyUserName' password='MyAdminPassword' roles='manager-gui'/>

To learn more about this tool check the Tomcat’s official documentation here.