Rob Gonda's Blog

Watch out for memory leaks!

I had a server constantly running out of memory and I just couldn't figure out what was wrong. The first thing I did, thanks to Steven Erat, was enable the jrun metrics to monitor threads, sessions, and jvm memory. You do this by editing the \runtime\servers\coldfusion\SERVER-INF\jrun.xml and set <attribute name="metricsEnabled">true</attribute>. I debugged my caching system, fixed some garbage collection issues, but it still did not completely fixed my problem.
A few days later, I got an insight: the onSessionStart and onSessionEnd functions.

I had the following functions defined:

    <!--- on Session Start --->
    <cffunction name="onSessionStart">
        <cfscript>
            application.com.objectFactory.getInstance('session').addSession(session);
        </cfscript>
    </cffunction>

   
    <!--- on Session End --->
    <cffunction name="onSessionEnd">
        <cfargument name="SessionScope" required="Yes" />
        <cfargument name="ApplicationScope" required="No" />
        <cfscript>
            ApplicationScope.com.objectFactory.getInstance('session').delSession(arguments.SessionScope.sessionId);
        </cfscript>
    </cffunction>


Well, guess what, it seems like even after removing the reference to the specific session, ColdFusion failed to destroy it. I would have assumed that ColdFusion would just destroy the session, and if I happen to still be pointing to it I would get the famous null pointer exception, but no, ColdFusion kept a copy of some sort draining all my memory. As soon as I removed the reference to the session, the jrun garbage collection did its job and memory because stable again.

I will try to look further into this behavior using the Scorpio Server Monitoring, which includes really nice tools to analyze what's using your precious RAM.

CFUnited 2007 Topics Online

CFUnited has posted topics for 2007 and the list looks even better than last year. They'll post about 20 more in the next couple of months, including new topics for Flex and Scorpio.

As a reminder, the 'very early registration' ends January 5th, so if you know for sure you are going, register early and save.

I'm giving a session called Embrace Factories:
Object Oriented Programming is still fairly new for ColdFusion developers. The community is learning the advantages of using objects, but once programs scale, they get out of control. Learn the best practices to organize and wire your objects together using proven design patterns such as object factories, service locators, and inversion of control. Attendees will see the evolution starting from a 20-lines simple factory, moving towards light-wire, and ending with ColdSpring.

I may also do a pre-confernce class like last year, not yet confirmed... I could do another Ajax Intensive, this time leveraging jQuery, YUI, and the new Scorpio Ajax built-in integration... I could also do one on Apollo ... which one would you rather take?

Better image manipulation quality with ASPJpeg

ColdFusion runs on top of Java and therefore can leverage of native Java classes such as BufferedImage and ImageIO. There are a few wrapper libraries that allow you to interact with them. The core relies on CreateObject("java", "java.awt.image.BufferedImage") and CreateObject("Java", "javax.imageio.ImageIO"), for the text manipulation you can use CreateObject("Java", "java.awt.Font"), and for reading and writing files you can use CreateObject("Java", "java.io.FileInputStream"). All this will be replaced with native image manipulation with the release of Scorpio (CFMX8).

However, I ran into image quality problems when resizing large images to smaller thumbnails... the resizing algorithm used by these native Java technologies is not optimal, therefore it really doesn't matter which wrapper you use, you will ultimately run into the same issues.

After much research, I chose to install a COM object used by ASP called ASPJpeg. As you probably know, ColdFusion can also leverage COM objects, and let me tell you, the quality of ASPJpeg is superb.

It really couldn't be any simpler. First initialize the COM Object:

<cfset myImage = createObject("COM","Persits.Jpeg") />


Then you may open an existing image:
<cfset myImage.Open("/path/to/original/file.ext") />


You may get the original width and height
<cfset orig_size_w = myImage.OriginalWidth() />
<cfset orig_size_h = myImage.OriginalHeight() />


Set new quality and resolution
<cfset myImage.ResolutionX(72) />
<cfset myImage.ResolutionY(72) />
<cfset myImage.Quality(80) />


Set a new width and height
<cfset myImage.Width(new_large_w) />
<cfset myImage.Height(new_large_h) />


Crop the image
<cfset myImage.Crop(crop_w, crop_h, starting_w, starting_y) />


and finally save the image to disk
<cfset myImage.Save("/path/to/original/file.ext") />


As you can see, it's extremely easy to leverage COM objects to read, resize, crop, modify quality ... ASPJpeg is capable of many other functions, but these should get you started.

Enjoy good quality!

AjaxCFC for jQuery Alpha Release

I finished today the implementation of AjaxCFC for jQuery. It's the same Ajax <-> CF integration you already know, but using the jQuery Ajax engine. It supports full JSON and WDDX serialization, has improved error handling, improved log4javascript integration, still supports named and unnamed arguments, and just so you can use it right away, it's back compatible with the DWR syntax. The only incompatibility is the change of the $() function, which you can actually override if you wish, but I didn't on my release.

This is great news folks, because jQuery is extensible and allows for easily dropping plugins into your code...
I will work in documenting it for beta release, but those of you who wish to use the bleeding edge version just add a comment and I'll send you the code. I'd appreciate comments and suggestions from those who wish to check it out.

Public Beta release should come sometime next week.

CFQuickDocs updated

The CFQuickDocs site was updated today. The only noticeable change is that now there's a single search box, combining tags and functions. If you need to search for a tag, you must include the CF prefix.

Here's my next request: add back, forward, and bookmarking support. I know bookmarking is already there by copying the 'link to this page' href, but modifying the URL state using the # hash would be much nicer. (I will try to release soon a new AjaxCFC/jQuery branch with built-in support for this).

Nevertheless, me, and my entire team use this site on a daily basis, so thanks a lot for it.

2.5h Ajax Presentation Marathon

Check out my 2h 17mins Ajax presentation recording. I presented Ajax in various flavors to the Scottish CFUG last week and I promised to post the slides and files.

You may check out the Adobe Connect Presentation, download the slides, and download the source code. Code includes examples for ajaxcfc, dojo, jquery, prototype, spry, and well as hand-coded XmlHttpRequest objects. AjaxCFC examples also include some using the Model-Glue and MachII frameworks, not included with this download.
Everything should run w/o any setup, there is no database, the only requirement if you run the Model-Glue and MachII examples is to drop this exact structure in your webroot, or create a mapping called CFUnited. Most of the examples are covered in the Connect Presentation.

Quick note re: jQuery. One of the examples I posted is using the $.post() function, which has been deprecated in the lastest 1.0.4 release that came out yesterday in favor of the $.ajax() function. I will update the examples shortly and update the same link.

Enjoy.

[digg this]

Ajax presentation for the Scottish CFUG

I'm speaking tomorrow for the Scottish CFUG, nevertheless, free and open to whoever wants to join us. It will be a Adobe Breeze, sorry, Adobe Connect presentation, very similar to the one I did for the Boston CFUG back in September, but I will slow down and explain more this time, since I pretty much have no time restriction.

The _official_ topic for the session is:
Ajax, Web 2.0, RIAs, single-page-applications are just a few buzzwords that every developer needs to know in 2006. Learn the history of Ajax, what it means to you, why you should pay attention, who is using it, what is available, and how to implement it. This session will get you up to speed with Ajax, compare the different existing frameworks, and provide you helpful tips of do's and do not's with Ajax.

However, I will show plenty of examples, use different frameworks, and respond to as many questions as possible.

Time: 8pm (GMT) / 3pm (EST)
URL: http://adobechats.adobe.acrobat.com/r21774523/

Scorpio on Adobe Labs

Scorpio is the code name for the next major release of ColdFusion from Adobe. They just added it to Labs, including brief information on 2007 events, wallpaper downloads, and faqs. Expect to see more there early 2007.

The public beta version is not available yet, but trust me, you will want to jump into it as soon as it's out.

Josh Adams on Ajax

Josh Adams from New Atlanta gave an Ajax presentation to the NCFUG a couple of days ago, covering most of the basics and a few frameworks -- Atlas, Spry, and AjaxCFC. The presentation is 1.5h long and it well worth it for people looking for a good intro / overview. John mentions he mostly uses AjaxCFC and asked a couple of questions I want to address, plus I have a few comments.
First, John asked about the second argument in the _execute function, yes ... that null, hehe. Like the docs say, it has no real use for ColdFusion, but the same JavaScript functions power DWR in the Java World and this argument indicates the class to be executed; the third argument indicates which method inside that class is to be run. The way I have AjaxCFC set up you don't really override any class, you just indicate which method on the CFC you wish to run.
Second, the new log4javascript integration was brought up. If you add debug:true to the config arguments when setting up AjaxCFC, you will enable log4javascript, which by default will pop up a new window and log every single Ajax request, including the responses and errors. As Aaron mentioned, this could eliminate the need for http sniffers to see what happens in the background, nonetheless, I would strongly suggest you use one. Aaron also mentioned other libraries at the end, like jQuery, which I hopefully cover this Thursday in my next breeze presso for the Scottish CFUG.

ORM: Transfer 0.6 Released

Mark just announced that Transfer 0.6 has been released. No major changes since the last 0.6 RC other than a few bug fixes; however, this is great news -- for me at least -- because now Mark can jump to the next few items on the road map, such as composite keys.
There are many methodologies in database design, and mines always end up with composite keys all over the place, which makes it a little more difficult to use Transfer, but no more! I'll be the first one to alpha test the new releases since I've been a major pain bugging for this enhancement.

Nicely done Mark!

More Entries

This blog is running version 5.9.003. Contact Blog Owner