Performance and Scalability
Scalability
AjaxSwing is as scalable as your application and the server you are running it on and as fast as your Swing application. It adds a thin layer that replaces the Java graphical environment and emulates the events. In many aspects it can make your application run faster because no drawing, buffering and output to the screen occurs in the emulated mode. There are less events to process and less memory needs to be allocated and garbage collected. Using AjaxSwing dynamic clustering you can combine several virtual clients into the same JVM and specify when to launch more JVMs as the load increases. This model gives a significant performance improvement to each client because shared resources are already loaded and initialized in the JVM. However, not every application may work correctly in a shared JVM without modifications if it uses global variables and heavy multithreading. You can specify how many virtual uers should emulated by each JVM, and if there are more users connecting then a JVM can handle, AjaxSwing will launch a new one. JVMs are pooled and are "warmed up" in the background to ensure that a new user session is handled instanteneously. For example, if your client code is fairly thin, you may choose to have up to 100 virtual clients in a JVM. In this case, if your server needs to handle 1000 concurrent users AjaxSwing will use 10 JVM processes. Typically, one running JVM takes 20-100M so the total amount of memory needed to support this traffic would be 200-1000M.
In general, you probably should expect higher resource consumption and slower response time then a pure servlet solution, but lower resource consumption then the Swing application running standalone. Check out this Performance Metrics to see specific performance data and the difference in memory consumption and response time between a regular GUI app, simple servlet and AjaxSwing emulation. Note that the Excel table shows data for one JVM. AjaxSwing applications has been load tested for thousands of concurrent users and the response time has always been comparable to the execution of the native Swing application.
Improving Performance
Performance of AjaxSwing applications is subject to the same constraints as any other web application using HTMl, CSS, JavaScript and XmlHttpRequest. Some tips for better performance are listed below
- Reduce log level by setting com.creamtec.core.TraceMgr.level to a smaller value in AjaxSwing/conf/TraceMgr.properties
- Reduce HTML page size by showing less windows and components at a time. Each component show in a Swing window will add to AjaxSwing rendering time, HTML page size, transfer speed and browser parsing.
- Improve application startup time by initializing all application resources and windows in main() method and using clientAgent.preloadApp=true
- Use modal dialogs because AjaxSwing only submits updates to the top modal window, ignoring updates to the blocked windows until the modal window is closed
- Compress images to JPEG to reduce the page load time
- Use client side validation instead of adding changed listeners to do most of the validations on the client instead of the server
- Share resources between virtual clients by placing shared classes that do not have global static variables on the application server classpath (for Tomcat that would be shared/lib directory) instead of specifying it on the clientAgent.classPath. Add JDBC connection pooling and other resource pooling for resources that are expensive to obtain
- Initialize browser cache. When opening a typical webpage the browser spends about 5 times as much loading external resources
then it spends on the HTML page itself. This affects the initial load time of the AjaxSwing generated pages, because the pages
include external JavaScript files and stylesheets. The key to speed up the loading of the application page is to ensure that the
expensive resources are present in the browser cache. AjaxSwing provides init_cache.jsp page that includes expensive AjaxSwing resources
and can be customized to include application-specific resources such as images. Typically, application has a "launch" page that provides
description and/or instructions to the user, but the browser cache initialization can be done from any page that the user visits
prior to AjaxSwing application. The following code can be added to the launch pages to asynchronously load expensive resources into the
browser cache:
<!-- Initialize browser cache for AjaxSwing --> <iframe src="http://host/ajaxswing/init_cache.jsp" style="width:0px;height:0px;border:0px;overflow:hidden"/>
where "host" is the host name or address of the server running AjaxSwing application.