Ben Forta in New York City Tonight

Tonight, Tuesday, May 15, 2007 at 6:30 PM Ben Forta will present a "Sneak Peek at Scorpio" to the NYCFUG. Detail can be found here.

Ben and the rest of the Adobe team have slowly been releasing more and more details about Scorpio with each stop of the tour. So lets hope tonight is full of juicy Scorpio tidbits!!! I'll be a blogging tomorrow about any newly announced features.

Also, if anyone has a question or a topic that they want me to grill Ben about, just leave a comment. Lets see if we can get Ben to spill the beans :)

Anyway, hope to see lots of NYC CF'ers there tonight!

Using Custom Debugging Template to Track What Templates Execute

So here's my solution to the problem I described last time. In summary, you're the new CF guy at a company with a large application. All in all, the application is great, but like all "mature" applications, it could probably use some pruning. But how do you know what can be safely cut out, and what is a vital piece of the application. In other words: So What Templates are executing anyway?

My solution... custom debugging templates. Thanks to Ray Camden and Adam Podolnick and their awesome work on ColdFire, custom debugging templates were on my mind lately. So how does the ColdFusion debugger help solve my problem?

Well as we all know, the underlying debugging service keeps track of all templates executed during a request. So I wrote a simple debugging page that looks at this and stores the templates executed in the server scope of the machine. My custom page has no output so the users see nothing. There is obviously some overhead running the debugger on a production server. So you'll have to decide for yourself if you can afford adding the extra time to the request.

I've been running my templateTracker.cfm custom debugging template for about a week now. Out of 1486 *.cfm and *.cfc's on the file system, users have executed 837 of them. When that number stops going up, I know I'll have my list of orphaned files. Let the pruning begin!!!

Oh yeah, here is my code for templateTracker.cfm custom debugging template. Nothing fancy, but gets the job done.

<cfsilent>

<cfset qEvents = "" />

<!--- Lets get the debugging data --->
<cftry>
   <cfobject action="CREATE" type="JAVA" class="coldfusion.server.ServiceFactory" name="factory">
   <cfset cfdebugger = factory.getDebuggingService()>
   <cfset qEvents = cfdebugger.getDebugger().getData()>
   <cfcatch type="Any"></cfcatch>
</cftry>

<!--- If we got the data, lets store it in an array in the server scope --->
<cfif isQuery(qEvents)>
   
   <!--- lets create the array if it doesn't exist yet --->
   <cfif not structKeyExists(server,"templateTracker")>
   <cfset server.templateTracker = arrayNew(1) />
   </cfif>
   
   
   <!--- QofQ to get ride of duplicates --->
   <cfquery name="qEvents" dbtype="query">
   SELECT DISTINCT template
   FROM qEvents
   </cfquery>
   
   
   <cfloop query="qEvents">
      
      <cfif findNoCase("CFC[",template)>
      <cfset tamplate = trim(listLast(listFirst(template,"|"),"[")) /><!--- I'm a cfc, and this is my path --->
      <cfelse>
      <cfset tamplate = template /><!--- I'm a cfm, and this is my path --->
      </cfif>
      
      
      <cfif server.templateTracker.indexof(tamplate) EQ -1><!--- Use Java's indexof to see if this template already exists in our array --->
         
         <cflock name="templateTracker" type="readonly" timeout="5">
         
            <cfif server.templateTracker.indexof(tamplate) EQ -1>
               <cfset arrayAppend(server.templateTracker,tamplate)><!--- I'm a new template. Add me to the array --->
            </cfif>
         
         </cflock>
         
      </cfif>
      
   </cfloop>

</cfif>

</cfsilent>

So what templates are executing anyway???

I came across an interesting brainteaser at work the other day, and I figured I blog about it. A few months back, I started at a new job as the Senior CF developer after their previous developer left. The site I now develop and maintain is a relatively large site, but not huge. There are somewhere in the neighborhood of 1500 .cfm and .cfc files. After a few months, I'm becoming familiar with most of the major parts of the site. So I started digging through some of the code trying to figure out what's going on in some of the darker corners of the application.

As time went on, I became more and more convinced that there are entire directories of files that are never used anymore. It's very possible. Some of the code is many years old, and there have been quite a few developers over the years. I'd love to clean this up a bit so that the next developer that joins the team doesn't have to waste their time looking at files that are never used. So, this led me to the question of the week. How do I figure out which files are actually being used, and which files are long forgotten orphans?

I tried a few different approaches before I came up with my current solution. It seems to be working fairly well, but I wanted to see if anyone else has any interesting thoughts on how to solve this problem. I'll blog my solution in the next few days.

In the mean time, what are your solutions to find orphaned ColdFusion templates?

Jrun, Multiple ColdFusion Instances, Apache, and Virtual Hosts

One of my first tasks at my new job was to set up the new development and staging environment for our web site. We have two Linux boxes with ColdFusion Enterprise running. These two boxes sit behind hardware load balancer. Pretty cool setup and sure beats the one windows box that also ran SQL Server and about 5 other department apps that I used to be responsible for.

For the staging setup, I have one CF instance running on each server. The load balancer sits in front doing round robin with sticky sessions turned on. That set up was relatively strait forward.

But for the development environment, it got a little more complicated. On one of the servers, we wanted to be able to deploy additional CF instances, one for each developer. There are about 8 instances in all. Originally, we were just going to use the JRun Web Server (JWS) to server the development instances. But that got ugly for a few different reasons.

First, configuring the webroot, aliases and other settings for the JWS is done in a messy set of XML files. Each instance has its own xml file, so the same configuration had to happen multiple times. Not very DYR. Second, each new instance was served over a different port, 8300,8301,8302, etc. I was constantly getting confused as to which port belong to which developer. Finally, it just felt wrong to have one web server in development, and another in production. I think it goes without saying that development should match as closely as possible the production environment.

So for all these reasons, I wanted to get apache all wired up to be the single webserver for all of these CF instances. In the end, everything I needed to know could be found on one of these sites:

Configuring ColdFusion Multiple Instances with Apache Virtual Hosts... Again
Web server configuration for application isolation
Installing and Configuring ColdFusion MX 6.1 Multiple Instances with IIS and Apache Virtual Hosts

There was one step the tripped me up, and lead to almost an entire day wasted. It had to do with the proxy port that each instance would be listening to allowing Apache to talk to it. This proxy service is set up by default when you create an new instance using ColdFusion Enterprise manager. After I created each instance, I checked the Jrun management console to verify that the proxy service was configured and running. Every time, everything looked great. roxy port configured and running. So what was the problem???

It seems you MUST EDIT the jrun.xml file. In this file, there is a line true that must be set to false. Even though Jrun said the proxy serves was up and running, it still would not work until I edited this file. Once set deactivated to false and restarted everything, I was good to go.

So now, each developer has his own DNS, tim.server.com, bob.server.com, etc. Each DNS goes through apache. All web server configuration is done in one place, and common aliases only need to be configured once. All in all, this is a pretty nice setup. For someone that has never had the pleasure of using CF Enterprise, I must say I'm liking multiple instances!

But one lesson learned, dont forget the jrun.xml file and the magic "deactivated" line.

Nice Programming Reference

I saw this over at digg today. Its a really nice interface. And best of all it includes ColdFusion!!! Nice to see CF alongside Java, Ruby, and PHP.

A Lurker No More

So I admit it. I read the ColdFusion People post and yup... I'm a lurker. I go to CFUG meetings. I visit all the blogs. I comment occasionally. But till now, I've just been taking from the community.

I've been *meaning* to get more involved in some way, but just never seem to fond the time. There's always a reason not to: I have a new baby, I'm busy training for the NYC marathon.

But then there was the challenge . And I accept. So I got my self a hosting account, and set up blogCFC (Thanks Ray).

Now I just have to see if there is anything interesting I can talk about that. But I guess thats for tomorrow. For now... one post down! w00t!!!!!

Copyright © 2006, Tim Elsner. This is a personal weblog. The opinions expressed here represent my own and not those of my employer.
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.