Archive

Posts Tagged ‘Alagad’

ColdFusion 9 ORM on Tomcat Gotcha

September 21st, 2009

I am sitting here working through an application that makes use of the new ColdFusion 9 ORM capabilities.  I have a simple business object that I created using EntityNew(), then populated it, and attempted to save it using EntitySave().  Nothing fancy and everything straight out of the docs.
The problem was, when I ran this code I would just get a blank screen – no errors, nothing.  I started up my application server – Tomcat – in the console and checked the output as I ran the script.  Sure enough, there was a slew of Java errors being displayed with the first being …

java.lang.NoClassDefFound: javax/transaction/Synchronization

With a bit of googling, I came across a blog article by Rupesh Kumar which mentioned this issue in the comments.  I had heard that Tomcat was not officially supported by ColdFusion which did not make a lot of sense, but apparently this just came back and bit me.
Somewhere in the Hibernate integration with ColdFusion 9, it is expecting a library called jta.jar (part of the Java Transaction support) to be included with the application server.  This library is not included by default with Tomcat and thus the error I was seeing, or not seeing.
I did some searching and could not find the jta.jar library to download, but I did find a zip download of all of the classes available on the Java site at http://java.sun.com/javaee/technologies/jta/index.jsp.  So, I simply downloaded this and renamed it to jta.jar, then dropped it into my Tomcat /lib folder.  With that in place, I restarted Tomcat, fired up my CF template again and everything worked like it should.
I can’t fault Adobe since they don’t support Tomcat.  I am curious as to why they don’t support it since it used to be supported, but hopefully this will save somebody a couple of hours digging around when their script fails to show anything.

Source:ColdFusion 9 ORM on Tomcat Gotcha

admin Alagad

Apache's Jmeter Part III - Using a csv to replicate real traffic

September 21st, 2009

Time for post number 3 regarding Jmeter, and today I will go over simulating users performing searches for keywords feeding from a CSV file. Lets start with a basic test plan, with one thread group, a single web request to google, a random timer, and a results tree listener so we can see what is going on.  It should look something like this to begin with (refer to my earlier posts to get to this point, either Jmeter part I or Jmeter part II)

Now you need to create or obtain a CSV file containing your search terms you wish to run through (or users to login, items to view, whatever you would like to change during each request).  I made a super simple one here, feel free to download or create your own, and name it searches.csv.
Download a sample searches.csv file.
Now, save that csv file in the same directory that you saved your test plan file. Add a new element as a child of your thread group, called ‘CSV Data Set Config’.

Set the filename to ’searches.csv’ (or whatever you named your data file), set the Variable Names to ‘TERM’, delimiter to a comma, and stop thread on EOF to false, and sharing mode to ‘All Threads’.  The sharing mode just sets the scope of where this variable name (defined as term above) will be available, inside this thread group, inside a single thread, or to the entire test on any thread.

Now we have to tell our individual search to use this CSV data, which is actually really simple to do.  Go to your HTTPClient sampler, and in the HTTP parameters list, change the q value, which is currently a string ‘coldfusion’, to ${TERM}.

Now when you save your plan and run it, take a look at your results tree, and click on ‘Request’.  You will see that each search sent to google uses the next item from your CSV data file to perform the test. 

This is a great technique to use for simulating multiple user logins. Combine this with the cookie manager, and you can fully simulate users logging in, performing a series of actions, and logging out at the end.

Source:Apache's Jmeter Part III - Using a csv to replicate real traffic

admin Alagad

Setting the edit position on the Datagrid

September 21st, 2009

Just quickly wanted to describe setting the edit position on the Flex Datagrid component.

I recently wanted to add a new empty row to my datagrid and make sure that new row had focus and was ready to be edited. Setting the editedItemPosition property on the datagrid requires passing an object in the following format:
 
{ rowIndex : 0 , columnIndex : 1 }
Here’s some code to get you there if your looking to do something similar:

import mx.collections.ArrayCollection;
import mx.events.DataGridEvent;
 
[Bindable]–>

protected var dataGridDataProvider:ArrayCollection = new ArrayCollection([{name:'firstName', description:'First Name'}, {name:'lastName', description:'Last Name'}, {name:'email',  description:'Email'}])
 
/**
* Handles the click event from the add row btn.
*
* @param event MouseEvent
*/
public function addRowBtnClickHandler(event:MouseEvent):void
{
//add am empty item
dataGridDataProvider.addItem({name:”, description:”});
//select the empty item
dataGrid.selectedIndex = dataGridDataProvider.length - 1;
//set the new item to edit
dataGrid.editedItemPosition = {rowIndex:dataGrid.selectedIndex, columnIndex:1}
}
 
/**
* Handles DataGridEvent that is dispatched when an item editing session ends on the dataGrid.
*
* @param event DataGridEvent
*/
public function dataGridItemEditEndHandler(event:DataGridEvent):void
{
  trace(’Edit the Datagrid.’)
}
]]>
<mx:DataGrid id=”dataGrid”height=”100%” width=”100%”dataProvider=”{dataGridDataProvider}”editable=”true”itemEditEnd=”dataGridItemEditEndHandler(event)”><mx:columns>     <mx:DataGridColumn width=”40″    editable=”false”    paddingLeft=”10″     textAlign=”center”>       <mx:itemRenderer>         <mx:Component>           <mx:CheckBox/>         </mx:Component>       </mx:itemRenderer>     </mx:DataGridColumn>     <mx:DataGridColumn dataField=”name”   headerText=”Name”/>     <mx:DataGridColumn dataField=”description”   headerText=”Description”/>     </mx:columns></mx:DataGrid><mx:Button id=”addRowBtn”  label=”Add A Row”  click=”addRowBtnClickHandler(event)”/> 
 

Hope this helps some folks and thanks for any comments.
Sincerely,
Matt
 

Source:Setting the edit position on the Datagrid

admin Alagad

Presentation Files for Performance Tuning Coldfusion: Before the JVM from CFUnited

September 21st, 2009

For anyone who missed it, or wanted to get some of the program links or jvm.config settings, here you go!
Download it from here.

Source:Presentation Files for Performance Tuning Coldfusion: Before the JVM from CFUnited

admin Alagad

Using hprof with Coldfusion to troubleshoot slow code issues

September 21st, 2009

I’m sure everyone has run into an issue that is difficult to isolate on a given system.  Sometimes all the code looks fine, and none of the .cfm templates are really standing up and shouting "I’m your problem!"  What to do when you are stumped and not sure where else to look for your performance woes?
Enter HPROF.
 
HPROF is a java profiler that you can invoke by modifying your jvm.config file. On ColdFusion multi server, that config file lives by default at {coldFusion root}/bin/jvm.config. When you open it up, you will see a few configuration variables being set, such as java.home (this tells coldfusion which JVM to use when starting up), java.library.path (sets the location for shared libraries to be loaded), and more, but the one we are concerned with is java.args.  By default it will look something like this:
java.args=-server -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Dcoldfusion.rootDir={application.home}/
Once you modify your jvm.config file with the HPROF arguments (simply add the -agentlib:hprof=cpu=samples, or the sites argument, after the -server argument), you are instructing the JVM to gather the profiler information that you specify (in the hprof args), then once the JVM shuts down, dump that collected data to a file.  This file created, by default, is called java.hprof.txt, and will be located in your {coldfusion root}/bin folder.  So, to recap:

Modify your jvm.config file to add the -agentlib arguments as defined in bold below
Restart coldfusion with the modified config file
Run a good sample of your application (my preference is to run some jmeter testing)
Stop coldfusion (which triggers the generation of the java.hprof.txt file)

HPROF is a tool that is meant to be used locally for development, or on a test or staging server.  Running most of these arguments *WILL* impact performance of your application, so please do not run this on a production server unless all other avenues of investigation have been exhausted. HPROF has many different switches, but there are 2 that I have found to be the most useful so far.
-agentlib:hprof=cpu=samples
Adding this switch is asking the JVM to gether time data for each method call. The report that comes back will give you the java class that is consuming CPU the most, in a list that goes from highest consumer to lowest.  In the following output sample, this client has some database contention going on that is holding up other coldfusion threads, causing scalability issues.

rank
self
accum
count
trace
method

1
36.64%
36.64%
104470
300685
java.net.SocketInputStream.socketRead0

2
31.45%
68.08%
89676
301551
java.net.PlainDatagramSocketImpl.receive0

3
20.35%
88.43%
58023
300553
java.net.PlainSocketImpl.socketAccept

4
10.40%
98.83%
29655
301093
java.net.SocketInputStream.socketRead0

5
0.09%
98.92%
258
301720
com.rsa.jsafe.crypto.ap.a

As you can see, the report goes top down, from the most CPU time spent in a method, down to the least (not listed here for brevity). It gives you the count (number of times this method was invoked), the trace address (this refers to a stack trace ID, which is listed prior to this pretty list in the output file, and can be helpful in finding how these methods are called), and the method itself (which will quickly show you what exactly is being invoked). To find the associated stack trace, simply copy the trace number from this table, then search for it within the report.  With this sample output, all of the classes are java, but I have seen CFC’s in a stack trace show as large consumers of resources as well. This is a great investigative tool when you are not sure what is taking up so much CPU, or why your application is not running as quickly as it should.
-agentlib:hprof=heap=sites,depth=4
This jvm.args switch instructs hprof to provide an analysis of the contents of your heap memory at the time the application exits. The sites argument tells the JVM to group the output based on a stack trace of a specific depth.  The depth argument requests a specific depth of stack trace (each depth level will make your file take that much longer, and be that much larger, so only ask for stack traces of a minimal depth to figure out where the code is originating from).  This is a pretty poor sample, but if you have an object you are instantiating and its not going away, it will stand out very quickly when you view this output:

rank
self
accum
live bytes
live objs
alloc’ed bytes
alloc’ed objs
stack trace
class name

1
29.94%
29.94%
170401344
2812
172626464
3148
461666
byte[]

2
20.44%
50.38%
116307712
601
121153664
700
461595
byte[]

3
10.82%
61.20%
61554880
514
61554880
514
461600
byte[]

This output is telling you that 29% of the objects in heap are of a type byte[] (an array of bytes), that there are less bytes marked as live than there are allocated (some of the records have been marked by the garbage collector as ready to be collected), and that these byte[] objects were created with methods that are detailed in stack trace 461666. That stack trace looks like this:
TRACE 461666:
com.adobe.fontengine.font.FontByteArray.<init>(FontByteArray.java:56)
com.adobe.fontengine.font.FontByteArray.<init>(FontByteArray.java:63)
com.adobe.fontengine.font.opentype.FontFactory$TableToLoad.load(FontFactory.java:218)
com.adobe.fontengine.font.opentype.FontFactory$TableToLoad.load(FontFactory.java:259)
Sometimes these traces can be helpful in isolating the source of an issue, or at least giving you some direction from which you can base your investigation on.  When you have a stumper, sometimes a direction is all you need to get on the path to a resolution.

Source:Using hprof with Coldfusion to troubleshoot slow code issues

admin Alagad

A New Series: Hibernate & ColdFusion 9

September 21st, 2009

Recently I have been working on a project using Groovy and Hibernate amongst other technologies and while I have definitely missed ColdFusion, it is good to get out of your comfort zone on occasion.  The problem with using new technologies in a project setting is that most of your focus is on delivering the project and not on really learning the ins and outs of the technology.  So, with a few minutes of breathing room allotted before the next project, I wanted to delve a bit deeper into Hibernate, especially with its integration into the next major release of ColdFusion.
To do this, my plan is to work through the book “Java Persistence with Hibernate” which was recommended to me and not only look at some of the capabilities behind Hibernate, but also see how Hibernate’s capabilities are presented within ColdFusion 9. This series should also serve as a bit of a review for the book and whether I would really recommend it for the ColdFusion development community.  To answer one question before it comes up, my point here is not to say that Hibernate will solve the world’s problems and that every developer should use it.  My goal is to simply take a closer look at Hibernate and the tools that we will have at our disposal with the next release of ColdFusion.  It is up to you to decide if these capabilities are worth your time and effort to learn more about.
Now, on to the book.  In going through some of the introduction and preface, I came across this definition of what Hibernate is:

“Hibernate is an ambitious project that aims to be a complete solution to the problem of managing persistent data … It mediates the application’s interaction with a relational database, leaving the developer free to concentrate on the business problem at hand.”

At first glance, this sounds great for a developer – I get to focus on the application and its architecture while ignoring the whole concept of data persistence within the application.  Reality is jumping up and down in the back of my head though saying this is too good to be true, so we will find out.
The first chapter of the book talks in general about persistence, how it fits into our software model and how it works in an object oriented paradigm.  I know my very first web application dealt with storing and retrieving data from a little Microsoft Access database, so the concept of data persistence is nothing new to me and I assume it is not new to most developers. The chapter talks a bit about relational databases – databases like Microsoft SQL Server or MySQL if you are not familiar with the term – as well as briefly discussing SQL in terms of the language for writing queries and communicating with the database.  While it is a well written intro, none of this should really be new for the average developer.
The twist with data persistence comes into play with what the books calls the “paradigm mismatch”.  In other words, what happens when you start developing applications in an object oriented fashion and have to deal with persistence.  With an object oriented application, you have abstract concepts like a Person and an Address.  However, a relational database does not understand the concept of a Person or an Address.  It understands a simple string like a first name or a street name for example. So, how do you go about saving and retrieving a Person instance to a relational database?  While you can obviously introduce a data access layer to your application that handles this conversion( this is discussed in the persistence layers section ) , this is the problem that Hibernate is attempting to solve amongst others.
The sub-section entitled “The Paradigm Mismatch” is very good in explaining the different issues in mapping objects to a relational database including granularity, inheritance, polymorphism, and identities.  The only thing here is that you have to have some knowledge of object oriented development and terminology, but I think that would be expected when reading a book on Hibernate which is all about persistence of object models.
I will cut this off here although I have only touched on half of the first chapter.  The sections on persistence layers are equally as good and as such, I will leave something for you to read about yourself.  I will look a bit more at the section that provides an overview of object/relational mapping (ORM) in the next post in this series.

Source:A New Series: Hibernate & ColdFusion 9

admin Alagad

Where Oh Where Did My Bottleneck Come From?

June 29th, 2009

At one point in my career I thought I knew what performance tuning was… I would have described it as “writing tight code.” (Remember that phrase? “Tight code”?) And if I were to be tasked with fixing performance issues, I would have jumped on my computer, gotten a local copy of the app going, and started hitting pages to find the slow ones, then look at the code for ways to fix the issue. That, however, was before I knew what performance engineering really is.

Source:Where Oh Where Did My Bottleneck Come From?

admin Alagad

It's Probably Not The Code: Server Performance vs Application Performance

June 29th, 2009

I was recently confronted with an application that suffered from abysmal performance… and by "abysmal" I mean "really really bad". My task was simple: Make the website go fast! It was an interesting challenge, really, and it got me thinking about the difference between server performance and application performance. All tools and best practices aside, the thing that really hit home for me was the sheer number of places I found that needed fixing. Yes, the code was an issue, but before I even started looking at the code (and thru the judicious application of appropriate tools), I found at least 3 places that affected the server itself.So the difference between server performance and application performance can be summarized pretty much like this:

Source:It's Probably Not The Code: Server Performance vs Application Performance

admin Alagad

The G1 garbage collector

June 29th, 2009

The G1 garbage collector has been made available in the 1.6_14 release of Sun’s JDK. There was some controversy initially when this was released due to some wording in the license, but the wording has since been updated. Sun was trying to indicate that no support would be provided for the G1 garbage collector, yet it initially came across that you could not even use it unless you had a paid support contract (you can read more about the licensing changes here).

Source:The G1 garbage collector

admin Alagad

SearchMark Firefox Plugin Enters Wider Release

June 29th, 2009

A while back I announced SearchMark, a Firefox plugin which automatically creates a Google Custom search engines for you based on your browser history and bookmarks. At the time I was only distributing the plugin through searchmark.org. However, yesterday I published it to addons.mozilla.com. I personally think this plugin is really cool. (But I would, I wrote it..) The idea is this: I often visit a website I think has good information, but I either forget to bookmark it, or I bookmark it can can’t find it in my bookmark list later. I always wished there was someway to search the text of sites you’ve visited or the text of sites you’ve bookmarked to find these old pages. For example, I recently bought an iPhone adaptor for my car from a company called Grom. However, I needed some support on the installation and couldn’t find their website again. So, I searched through my history and found it again rather quickly. (It seems I was accidently searching on Gorm, which is something else entirely.)

Source:SearchMark Firefox Plugin Enters Wider Release

admin Alagad