Showing posts with label ColdFusion. Show all posts
Showing posts with label ColdFusion. Show all posts

Wednesday, July 15, 2009

Enhanced Flash Remoting (CF9) Vs. Old Flash Remoting

One may wonder, what is this deal about in ColdFusion 9 for “Enhanced Flash Remoting”? Or One may also wonder what was wrong with Old Flash Remoting (CF8 style) that we needed to enhance Flash remoting in ColdFusion 9?


To find answers for these questions, let’s first explore, what was wrong with CF8 style flash remoting. Mainly there was one problem and that was the “Circular reference serialization-deserialization” bug.


This bug was long standing problem for Advanced CF-Flex developers who tried to send nested or related ActionScript Objects having circular reference to each other, over wire to ColdFusion from Flex Clients, resulting in following error.


[Flex]Exception when invoking service 'remoting-service': flex.messaging.Message

Exception: java.lang.StackOverflowError

.

.

.

Exception: flex.messaging.MessageException: java.lang.StackOverflowError

at coldfusion.flash.messaging.ColdFusionAdapter.getFlexError(ColdFusionA

dapter.java:361)

at coldfusion.flash.messaging.ColdFusionAdapter.invoke(ColdFusionAdapter

.java:273)

.
.

.


--> This Bug is fixed in ColdFusion 9 – Enhanced Flash Remoting feature. So Developers are no more blocked writing advanced Flex-CF Applications with having AS Objects with circular references.


Let’s discuss another advantage of using new Enhanced Flash Remoting. Fixing the circular reference bug wasn’t an easy task, many radical changes were required to be done to fix this issue and most of the ActionScript-CF datatype translation or serialization-deserialization process has to be re-written in many ways. This gave us the opportunity to improve the entire process, resulting in faster AS-CF datatype translation which made New Enhanced Flash Remoting faster many times against Old Flash Remoting.


--> A Significant Performance Boost for Flash Remoting.

  • Enhanced Flash Remoting is 6 -7 times faster against CF 8.0.1
  • Enhanced Flash Remoting is 10-11 times faster against CF 8.


So How did I measure this Performance Gain?


To measure this performance gain, I created a small Flex Application which will send an Actionscript Object to ColdFusion 9 and ColdFusion 9 will echo it back to Flex application. So making an entire server trip and back will give an appropriate idea about the serialization-deserialization process both ways.


The below Actionscript Object that I used for this purpose has most of the common datatypes of AS.


package com

{

[RemoteClass(alias="perf.DataSamples")]

public class DataSamples

{

public var firstname:String = "";

public var lastname:String = "";

public var city:String = "";

public var zip:uint;

public var email:String = "";

public var ContactNos:Object;

public var designation:String = "";

public var experience:int;

public var salary:Number;

public var CompaniesWorkedFor:Array;

public var dateOfBirth:Date;

public var IsMarried:Boolean;

public var Children:Object;

public function DataSamples()

{

}

}

}


As you observe that, this DataSample class has properties of varying datatypes like String / uint /int / Objects(CFC mapped Objects, Plain AS objects) / Number / Array (Indexed, Associative) / Dates / Boolean. Also observe that this DataSample AS class also maps with a ColdFusion server side CFC “perf\DataSamples.cfc”. So most common Flex app scenarios are being covered through this AS class.


I am assuming here that similar sort of AS object would broadly represent a Flex application’s Custom AS Class.

Now, so in what quantum or magnitude I should send this DataSample objects I should use to find out the performance difference between Enhanced Flash Remoting and Old Flash remoting. Sending a Few DataSample objects may not give a real idea about the performance gain, so in order to measure the real difference in speed, we have to magnify it by replicating a high traffic Flex application which sends DataSamples Objects around in the range of 10,000 – 50,000. See the following stat metrics that has been gathered in similar environments ( Win2k3 R2 + Intel Xeon CPU 2GHz + 2GB RAM) for ColdFusion 8 / ColdFusion 8.0.1 and ColdFusion 9.

No. of CFCs

Response Time

( Readings for Echo operation in ms )


ColdFusion 8

ColdFusion 9ColdFusion 8.0.1

10 K

14599, 14301, 13890, 14203, 13725

1278, 1297, 1285, 1266, 1250

7203, 7609, 7062, 7125, 7235

20 K

29484, 32531, 27188, 27219, 27600

2821, 2812, 2815, 2500, 2828, 2515, 2703, 2516

14328, 14672, 14375, 14437, 14523

30 K

41907, 41078, 41355, 41688

3969, 4032, 3765, 4031, 3719, 4031, 3718

21703, 22312, 22578, 22469

40 K

55032, 54782, 55392, 55189

5000, 5328, 5219, 5313, 5000, 5344

30625, 30641, 30516, 30629, 30593

50 K

70312, 69890, 70891, 70234

6562, 6281, 6500, 6297, 6578, 6297, 6265

42297, 41516, 39610, 39188, 38010

Each of the reading given in the metrics represents an average of 10-20 server cycles response time. Why I opted to it this way, instead of just taking 1 server cycle, is to get an average time which will be most nearer to the actual figure. For 10K/20K CFCs, average is for 20 server cycles, and for higher 30K-50K CFCs, average is for 10 server cycles.


So If you observe the stats, it suggest that ColdFusion 9 is significantly faster over CF8(10-11 times) and CF801(6-7 times).


A few Basics Questions One may have in mind…..


--> Does ColdFusion 9 also support Old Flash Remoting ?


Yes. It supports, CF8 style, “Old Flash Remoting” for backward compatibility purpose. As “Enhanced Flash Remoting” of ColdFusion 9 requires a few structural changes in the WEB-INF\flex\ XML configuration files at Channel as well as Destination level. By default ColdFusion 9 installation supports new Enhanced Flash Remoting.



--> What are these changes at Channel and Destination level in flex Configuration files from previous CF releases to CF9?


The following properties have been moved from Destination to Channel level. You need to move these properties under <channel-definition > --> <properites> --> <coldfusion> from your destinations.


For more details, refer Documentation, Changes in the XML configuration files for New Flash Remoting in ColdFusion 9.


<access>

<use-mappings>

<method-access-level>

</access>


<use-accessors>

<use-implicit-accessors>

</use-accessors>


<use-structs>

<property-case>

<force-cfc-lowercase>

<force-query-lowercase>

<force-struct-lowercase>

</property-case>

</use-structs>



--> So What happens, while migrating from previous CF installs to ColdFusion 9, if I just simply drop my old WEB-INF\flex XML configuration files, without above changes, over ColdFusion 9 installation?


With Old style XML Flex configuration files, it will continue to work but in this case ColdFusion 9, will use Old Flash Remoting and not the Enhanced Flash Remoting.

One must follow above suggested XML changes, in order to take advantages offered by Enhanced Flash Remoting.

Thursday, September 4, 2008

ColdFusion 8 Enterprise- Free for Educational purpose

"ColdFusion 8 Enterprise" is now free for Students and Educators....See the details on the following link.
http://www.webbschofield.com/index.cfm/2008/9/2/ColdFusion-8-Now-Available-to-Students-and-Educators-for-Free
There’s also a FAQ posted here about the offer: http://www.stage.adobe.com/products/coldfusion/faq/

Thursday, July 17, 2008

Finetune ColdFusion Server Performance

Let me just put across some terminologies before I present my thoughts on improving/fine tuning the ColdFusion Server performance.

Request Wait Time
The number of milliseconds that a request was waiting in the queue before starting to execute.

Requests Running
The number of request currently under execution by server.

Request Execution Time
The number of milliseconds that a request took to execute on server.

Requests Queued
The number of queued requests that are waiting to be processed.

Keeping all the above terms in consideration the Response time could roughly be calculated as below...

HTTP Response time / PageLoad Time = "Webserver trip time for Browser and Application Server" + "Request Wait Time" + "HTTP Request Execution Time on Application Server"

Now, Before we move on let us know what different kind of requests ColdFusion server can handle.

What Kind of Requests can ColdFusion Server accept via HTTP ?

Currently with ColdFusion8, it accepts 4 kinds of requests via HTTP
1. CFML Template requests
2. Flash Remoting requests
3. WebService requests
4. CFC function requests

Each of the above 4 type of HTTP requests can be moderated for simultaneous request execution from "CFAdmin->ServerSettings->Request Tuning". So Next question here could be asked is, What should be the limit for each one of the above 4 ?

It depends, what kind of Applications are deployed on the ColdFusion server. One need to find out, which of the above 4 techniques are hugely used in the deployed Applications.

--> Traditionally ColdFusion Application generally uses CFML template Requests, so in this case increase the CFML template request accordingly.

--> With Flex/AIR technologies gaining momentum, a lot many Flash Remoting Calls could be coming into the server, so in this case it would make sense to increase the Flash Remoting Request Limit.

--> Likewise, if your application is hugely using CF WebService / CFC function requests then it would make sense to increase "webservice" and "CFC" request limits respectively.

ColdFusion uses JRun as underlying J2EE application server to run on. Here JRun is the master server which can control the simultaneous request execution limit. So Coldfusion has to respect this limit in order to moderate the simultaneous running request for the above 4 types of HTTP request, Meaning....... "Maximum number of running JRun threads Limit must be, greater than Simultaneous ( CFML Template + Flash Remoting + WebService + CFC ) Limits"
For example say,

CFML Template requests --> 20
Flash Remoting requests --> 20
WebService requests --> 10
CFC function requests --> 20
-----------------------------------------
Total --> 70

so, "Maximum number of running JRUN threads" must be greater than 70. If the value "Maximum Run Threads" is changed, then ColdFusion server needs to be restarted for the change to take effect

By how much we should/can increase the Request limits or What should be the threshold for Request Limits ? OR How to do the performance fine tuning for ColdFusion server ?

There is no standard formula to determine the thresholds. It depends on the machine/hardware capabilities on which the ColdFusion is deployed. Powerful the hardware(processor and memory), higher could be the threshold for each of those request limits. So how do you determine it?....It could be done by a trial and error method as mentioned below.

--> If the "Sum of (CFML+Flash+webService+CFC) Requests Running" value nearly matches the value of the "Maximum number of running JRUN threads" property, and also if the Requests Queued is large, and IF CPU USAGE IS LOW, you can increase the threshold for "CFML,Flash,webservice,CFC" and accordingly for "Maximum number of running JRUN threads".

Try this method starting with lower threshold values and keep increasing them until CPU usage is not underutilized. you would be able to determine the ideal load handling capabilities of your hardware by trying this method.

Note: The value of the "Maximum Running Run Threads" can significantly influence the scalability of your Web applications and the performance of your server.

So this trial and error approach to determine the threshold should be first tried on a similar configuration machine in development environment and then once you get your ideal threshold, same can be applied to ColdFusion server in production.

Ideally, the "Requests Queued" should remain close to zero; however, they can vary under varying loads (depending on the application) while the server still provides good performance.

If these numbers vary too much from their expected range, you might want to take Server Monitoring help to find out which portion of your code is taking too much time and accordingly might want to rewrite that portion of code to make it efficient.

If the queue size and wait time increases, or if the queue limit is reached, browser displays the HTTP error message "500/Server Too Busy".