ColdFusion 8 Performance Tuning, Multi-Instance Management and Clustering Sven Ramuschkat MAX 2008 Milan
About me Sven Ramuschkat CTO of Herrlich & Ramuschkat GmbH ColdFusion since Version 3.1 Authorized ColdFusion Trainer since 1998 Also Specialist for Flash Media Server, Adobe Connect and LiveCycle ES www.richinternet.de www.richinternet.de/blog (English Blog) SR@richinternet.de
Agenda ColdFusion 8 Performance Gains Best Settings for Performance ColdFusion Installation Options ColdFusion Multi-Instance Management and Clustering
ColdFusion Performance with Version 8 Adobe Observations of CF8 over CF7 Most applications average 30-40% performance gain some applications 3 or 4 times better Structure manipulation in CF 8 twice as fast as CF 7 List manipulation three times faster CFSET more than four times faster CFPARAM tag 35 times faster Date functions about 6 times as fast Regular expression functions more than twice as fast CFC instantiation over 20 times faster http://www.adobe.com/products/coldfusion/pdfs/cf8_performancebrief.pdf
ColdFusion Performance with Version 8 ColdFusion 8 now deployed atop JDK 1.6 fixes some past problems, adds some new features adds substantial performance increases Unfortunate JVM bug with class loading Fall back to Java 1.5 Some have also updated to 1.6 update 10 (1.6 update 10 unsupported by Adobe yet)
ColdFusion Performance with Version 8 Think about ColdFusion 64 Bit and Windows 2008 64-Bit: No memory heap restrictions anymore As you can see, there are performance gains of around 0-15% in most of the tags. This can be attributed to the fact that most of these tags are computationally intensive and perform better on 64- bit systems
ColdFusion Performance with Version 8 So an update to ColdFusion 8 is a must from a performance perspective!
Best settings for Performance This can not fix bad or slow code! So always start to optimize your code first!
CF-Administrator Server Settings Settings Enable Whitespace Management Setting Tradeoff between extra server work and download speed Can be expensive (up to a ~10% hit) on server side Some webservers offer HTTP compression Squeezing whitespace out of.cfm files in batch can help Please solve the whitespace problem inside your source code: <cfsetting enablecfoutputonly="true"> <cfoutput>hello World! </cfoutput> DEMO http://localhost:8300/spaces.cfm
CF-Administrator Server Settings - Request Tuning Simultaneous Requests Controls number of worker (request) threads created and able to service requests simultaneously Single most important CF Admin setting (Def = 10) Under the hood, this sets the JRun Active Handler Threads No magic formula, BUT: Optimal CF5 setting may be too low for CFMX Generally, start tuning at 3 per CPU (i.e.: 6 on 2-way or 12 on 4-way) Too high can cause heavy context switching Optimum Sim Req setting for your application: Use a load test tool and the testing process (test, adjust setting, test, repeat)
CF-Administrator Server Settings Caching Template Cache Size Use to cache compiled template Java bytecode Where templates actually execute from Memory considerations: Consumption can be 3-10X ASCII template size Can get OutOfMemory conditions if set too high for the Java VM MaxHeapSize on a very large site CFMX = the NUMBER of templates CF5 = the KB size of the cache
CF-Administrator Server Settings Caching Trusted Cache If ON, no check of template source file date/time If OFF, will check and recompile templates if newly changed Turn it ON for production Enabling Trusted Cache Admin switch minimizes file system stat() calls Includes Application.cfm and OnRequestEnd.cfm Can dramatically increase performance under load Especially on shared network file systems No server restart required You can deploy new files dynamically
CF-Administrator Server Settings Caching Some people have been noticing dramatically slower application startup times on ColdFusion 8 compared to ColdFusion MX 7. The answer is Java 6. For all the other performance improvements and increased functionality in Java 6, it introduced a bug in the class loader that causes substantially slower class loading. A fix appears to be out now. JDK 6 update 10. http://java.sun.com/javase/downloads/?intcmp=1281
CF-Administrator Server Settings Caching Number of Cached Queries Sizing: Default = 100, maximum is memory size Make: Big enough to fit a popular RS s in memory Small enough to keep out of swap space NOT too big that you exceed Heap Size (OutOfMemory) How much memory does each DB result set require? Depends on (# Rows) X (# Bytes per Row) Plus some standard CF overhead per RS
Database Drivers in ColdFusion Never use ODBC! Always use JDBC-Level 4 Drivers.
Data Source Settings
Important Datasource Parameters Maintain Connections Connection-Pooling: ColdFusion establishes a connection to a data source for every operation that requires one. Enable this option to improve performance by caching the data source connection Max Pooled Statements Enables reuse of prepared statements (that is, stored procedures and queries that use the cfqueryparam tag). Although you tune this setting based on your application, start by setting it to the sum of the following: Unique cfquery tags that use the cfqueryparam tag Unique cfstoredproc tags
JVM-Settings for ColdFusion Standalone In 32-Bit Windows max is 1.6 GB RAM So try to use 64 Bit Windows
ColdFusion 8 Installation
ColdFusion Versions Limited = Enterprise feature that runs through the Enterprise Feature Router (EFR). These features will run in the Standard Edition. However, all features running through the EFR will be limited to one shared simultaneous request
Installation Option 1: CF 8 Standalone with embedded JRun 4
ColdFusion Standalone Installation ColdFusion will be installed to C:\CFusion8 The Windows Service Name is ColdFusion 8 Applicationserver JRun is completely hidden
Installation Option 2: CF 8 as J2EE- Application inside a JRun 4 full installation
ColdFusion on JRun4 JRun 4 full installation to C:\JRun4. ColdFusion-Instance will be deployed automatically. Windows Service Name is Macromedia JRun CFusion Server You can create as many CF- Instances as you like later.
Installation Option 3: Creating a EAR- or WAR-File for deployment on other J2EE-Servers
ColdFusion as J2EE Installation
Installation
Installation
Installed Services and Directories JRun 4 with Updater 7
Instance- and Clustermanagement (onlypossiblewithoption 2: Multiserver configuration)
Instance Management You can delete the samples Instance, because this is JRun Stuff The CF-Instance named CFusion is the Master-Instance. Only the Master Instance has the Instance- and Cluster-Manager. The Master Instance can not be added to a cluster.
Instance Management
Instance Management
Instance Management Every CF-Instance has: 1. It s own JVM-Instance (Application Isolation) 2. It s own CF-Admin with separate Settings 3. It s own CustomTag Directory
Instance Management
ColdFusion WebServer Connector Clustering JRun Webserver Connector allows a webserver to communicate with JRun, runs as a filter or plugin in the webserver Cluster by connecting multiple instances of ColdFusion to a single webserver with the JRun Webserver Configuration Tool Load balancing and Failover built in to the connector Connector load balancing algorithms (round-robin, weighted roundrobin, weighted random)
ColdFusion WebServer Connector Clustering ColdFusion Cluster Manager A sticky session specifies that once a session is created by a given server, subsequent requests from the user will continue to be routed to that same server in order to preserve session information When a cluster uses session replication, session data is copied to other servers in the cluster each time it is modified. This can degrade performance if you store a significant amount of information in session scope. If you plan to store a significant amount of information in session scope, consider storing this information in client variables saved in a database.
ColdFusion WebServer Connector Clustering After enabling session replication you will need to enable J2EE session variables within the ColdFusion admin. Uses jsessionid in addition to CFID and CFTOKEN
Important Cluster Parameters Algorithm Description Round robin (default) The web server connector sends each request to the next JRun server in the list. Specify ROUNDROBIN to use this option. Weighted round robin The web server connector sends relatively more requests (one after the other) to certain JRun servers, as specified in the serverweight attribute. Specify ROUNDROBIN_WEIGHTED to use this option. Random weighted The web server connector sends relatively more requests (in a random order) to JRun servers, as specified in the serverweight attribute. Specify RANDOM_WEIGHTED to use this option.
Important Cluster Parameters sticky sessions Yes The web server connector detects whether a request has an existing session and automatically routes that request to the original JRun server instance. If your ColdFusion application uses session management but does not use session replication, you must enable sticky sessions. No The web server connector routes incoming request to the next JRun server instance, as determined by the cluster algorithm. session replication Yes JRun automatically replicates session in-memory to other servers in the cluster. No Session replication is disabled. If your ColdFusion application uses session replication, sticky sessions are not typically required.
Cluster Parameters C:\JRun4\servers\clusterInstance1\SERVER-INF\jrun.xml <service class="jrun.servlet.jrpp.jrunproxyservice" name="proxyservice"><attribute name="activehandlerthreads">25</attribute><attribute name="backlog">500</attribute><attribute name="deactivated">false</attribute><attribute name="interface">*</attribute><attribute name="maxhandlerthreads">1000</attribute><attribute name="minhandlerthreads">1</attribute><attribute name="port">51004</attribute><attribute name="threadwaittimeout">20</attribute><attribute name="timeout">300</attribute><attribute name="bindtojndi">true</attribute><attribute name="stickysessions">false</attribute><attribute name="loadbalancingalgorithm">roundrobin</attribute><attribute name="serverweight">3</attribute> </service>...
ColdFusion Clustering connecting the web server JRun web server connector clustering Use wsconfig to connect your webserver to the cluster
ColdFusion Clustering Testing http://localhost/cluster.cfm <cfobject action="create" type="java" class="jrunx.kernel.jrun" name="jr"> <cfset servername = jr.getservername()> <cfoutput>jrun ServerName: #servername#</cfoutput>
Web Server Clustering - Overview Two or more web servers that support one or more domains are grouped together as a cluster of servers Use Load balancing scheme to manage increases in load using roundrobin DNS or a hardware device Failover is used to protect against web server failures, implemented using a hardware or software solution
Web Server Clustering - Hardware Common hardware options F5 Big IP Cisco CSS Advantages Highly scalable Support probes Disadvantages Cost Can be difficult to configure Links CSS with CF http://www.adobe.com/devnet/coldfusion/articles/css_multi.html F5 Big IP - http://www.adobe.com/devnet/coldfusion/j2ee/articles/balancing_j2ee.html
Mixed Cluster-Concepts 1. Web server clustering 2. Connector clustering 3. Object clustering (session replication)