ColdFusion Performance Tuning, Multi-Instance Management, and ...

collectivemodernSoftware and s/w Development

Jun 30, 2012 (4 years and 9 months ago)

689 views

®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

8
Performance Tuning,
Multi-Instance

Management and
Clustering
Sven Ramuschkat
MAX 2008 Milan
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Agenda


ColdFusion

8 Performance Gains


Best Settings

for

Performance


ColdFusion

Installation Options


ColdFusion

Multi-Instance

Management and Clustering
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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.pd
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

Performance with

Version 8
So an update to ColdFusion

8 is

a
must

from

a performance

perspective!
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Best settings

for

Performance
This

can

not

fix bad or

slow

code!
So always

start to optimize

your

code

first!
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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)
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
CF-Administrator



Server Settings

-

Request

Tuning
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

Processing

Overview


J2EE App

Server passes

request

to Web Container running

ColdFusion


On first

request

for

new

or

newly-changed

template:
1.

Template/component

CFML source

read

from

file
2.

CFML parsed

+ compiled

down to Java bytecode

(.class

file)
3.

Compiled

Java bytecode

cached

to memory

& disk

for

reuse

on subsequent

requests


On subsequent

requests
1.

If not in memory, Java bytecode

loaded into memory (if
Template Cache size is exceeded, some LRU template
bytecode

is ejected)
2.

Java bytecode

executed from memory
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Database Drivers in ColdFusion
Never

use

ODBC!
Always

use

JDBC-Level

4 Drivers.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Data Source

Settings
Called

when

a connection

fromthe

pool

is

resued. This

can

slowquery

response

time
because

an additional query

is

generated. You

should

specify

this

just before

restarting

the

database

to verify

all connections, but

remove

the

validation

query

after

restarting

the

database

to avoid

any

performance

loss.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Important

Datasource

Parameters
Maintain

ConnectionsConnection-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

StatementsEnables

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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
JVM-Settings

for

ColdFusion

Standalone
In 32-Bit Windows max

is

1.6 GB RAM
So try

to use

64 Bit Windows
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
JVM-Settings

for

JRun
The

Java-Settings

for

the

JRun

Server are

stored

in
jvm.config

which

is

located

in c:\Jrun4\bin.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Java.args

=
-serverHas to be

the

first

parameter
-Xmx512mMax Heap

Size. Set as high as possible

(1024 max

limit

on
Windows) but

I would

not

surpass

1/2 total RAM
-Xms256mMin Heap

Size. Set this

higher

than

the

default

64MB.Some like

to
set

this

equal

to max

size

but

I have

seen

start up issues

because

the

jvm

tries

to grab too

much

memory

too

fast, causing

CF/JRun

to fail.
-XX:NewSize=64mCreates

a larger default

Young generation
-XX:PermSize=32mCreates

a larger default

Permanent generation

size
-

XX:MaxPermSize=128m
Sets the

maximum

Permanent generation

size. Increase

this

as
you

increase

max

heap

size
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

8 Installation
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installation
Option 1:
CF 8 Standalone

with

embedded

JRun

4
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

Standalone

Installation
ColdFusion

will be

installed

to C:\CFusion8
The

Windows Service Name
is

„ColdFusion

8
Applicationserver“
JRun

is

completely

hidden
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installation
Option 2:
CF 8 as J2EE-

Application inside

a
JRun

4 full

installation
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installation
Option 3:
Creating a EAR-

or

WAR-File

for

deployment

on
other

J2EE-Servers
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

as J2EE Installation
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installation
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installation
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Installed

Services and Directories
JRun

4 with

Updater

7
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Instance-

and
Clustermanagement
(onlypossiblewithOption 2:
Multiserver configuration)
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Instance

Management
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Instance

Management
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Instance

Management
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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

round-

robin, weighted

random)
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

WebServer

Connector

Clustering
ColdFusion

Cluster Manager
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.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Important

Cluster Parameters
AlgorithmDescription
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 weightedThe 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.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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.
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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>
...
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

Clustering



connecting

the

web server


JRun

web server

connector

clustering


Use

wsconfig

to connect

your

webserver

to the

cluster
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
ColdFusion

Clustering



Testing
<cfobject

action="create" type="java" class="jrunx.kernel.JRun" name="jr">
<cfset

servername

= jr.getServerName()>
<cfoutput>Jrun

ServerName: #servername#</cfoutput>
http://localhost/cluster.cfm
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
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
®
Copyright 2008 Adobe Systems Incorporated. All rights reserved.
Mixed Cluster-Concepts
1.

Web server

clustering
2.

Connector

clustering
3.

Object

clustering

(session

replication)