An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

Entries for month: May 2005

Erich Gamma on Design Patterns

May 31, 2005 ·

Artima has a great interview of Erich Gamma by Bill Venners. Erich is one of the "Gang of Four" that brought us the Design Patterns book (a decade ago!). The interview covers Erich's thoughts on how design patterns should be applied. My favorite quote from the interview:
"One comment I saw in a news group just after patterns started to become more popular was someone claiming that in a particular program they tried to use all 23 GoF patterns. They said they had failed, because they were only able to use 20. They hoped the client would call them again to come back again so maybe they could squeeze in the other 3."

Tags: architecture

Tiger: a week in the wild

May 31, 2005 ·

Well, I've been using Tiger for about a week now so I figured I'd post some more thoughts now that I've gotten used to it. I don't hate Mail 2.0 but it sure takes some getting used to. The handshaking between Mail and iCal regarding events is pretty slick (although you no longer seem to have the option to not send a response email for each invite). For events that were imported from Panther, I've had to ask the originator to cancel and then re-invite me to some events because the old imported events were readonly and I couldn't detach and move events (some people move their regularly scheduled meetings around a lot!). Spotlight is proving useful about once every day or two. Dashboard is subtly useful too. I used the flight tracker for the first time today. Nice. My widget for displaying active CFMX instances is useful... one day I might expend the effort to make it have buttons to stop / start instances etc. Once again, I've changed my working practices somewhat. For some reason, the size / shape of Mail made me want to change the size / shape of several other apps so now I'm mostly using untabbed windows and relying on Exposé more than I was. Eclipse is running fine on Java 5 although I have to switch the default JVM back to 1.4.2 if I want to start BlueDragon 6.2 since that does not support Java 5. CFMX / JRun automatically selects the 1.4.2 JVM so having Java 5 as the default doesn't bother CFMX / JRun. I'm still not very excited about Tiger but it's not a bad upgrade.

Tags: osx

Tiger's iCal and WebDAV

May 31, 2005 ·

After upgrading to Tiger and the new iCal, I noticed that the calendar files are no longer in the same place. In fact, I haven't actually found where the new iCal stores the calendars. That was kind of a pain because I used to push my .ics files up to my ISP so that my wife could subscribe to my calendars (a cron job runs on her iMac to push her calendar to my ISP and a cron job runs on my PB to push my calendars to my ISP). I figured I could publish my calendars to get at the .ics files. iCal publishing supports .Mac and WebDAV. My ISP does not offer WebDAV. Hmm. Guess I could enable WebDAV on my local Apache and publish to that, then use my old cron job to push the files from the webroot up to my ISP... I found these articles about WebDAV on O'Reilly and WebDAV.org that helped me figure out most of it. I added a .htaccess file to Limit the WebDAV operations but couldn't write to the new WebDAV setup. Finder could connect, even prompting for the right credentials, but the folder was mounted readonly. Eventually I realized that the DAVLockDB directory path I'd specified didn't fully exist. A quick mkdir and a chmod and everything started working! Now iCal happily publishes to my local Apache setup, my cron job pushes the files to my ISP and my wife can, once again, see what I'm doing. It's the first time I've used WebDAV. It's pretty neat!

Tags: apache · osx

Asynchronous Development - How Much Parallelism?

May 30, 2005 ·

ColdFusion MX 7 makes it so easy to run code in parallel that you're probably going to go mad with it once you start. If you're using my Concurrency library, it can be very tempting to run many of your methods concurrently. You'll do it the name of performance, to make a request run faster. When I started this series of blog entries, I mentioned that you don't want too many simultaneous requests to be processed by ColdFusion because it can cause two much contention for CPU resources and you can end up thrashing your server as it constantly switches from request to request trying to give each some CPU time. That's why the "3-5 requests per CPU" rule of thumb is useful. The same consideration is true of your event gateways. If you try to run everything in parallel, you may well end up thrashing your server as it spends more time switching between threads than actually getting any work done. The default setting for the number of event gateway threads is 10. You might think that setting this higher will mean better performance but you probably don't want it set higher than 5 times the number of CPUs you have if your event gateway tasks are CPU intensive. If your event gateway tasks are I/O-bound, or are mostly waiting for external systems (e.g., running a slow web service call in the background), then you can afford to have more of them executing at once and you can set the number of event gateway threads higher. We had a 4 CPU server and someone had pushed the number of threads up to 40. The result was that under load, all the threads were active and the server started thrashing. We cut the number of threads back to 20 and the performance improved dramatically. We are actually still able to thrash the server under load so we are going to throttle the parallelism a little more at some point. Oh, the load test scenario we'd forgotten? If you've read all three of these Asynchronous Development entries, you've probably guessed by now: we did not test the scenario where we have a lot of data queued up, ready to be consumed, and you start all of the event gateways at the same time. We had too much parallelism and too many automatically started gateways - when we brought up ColdFusion, it immediately started consuming data and overwhelmed the server. We now know how much of a backlog of data we can consume without causing a problem and we have also tested a process for consuming larger backlogs: starting and stopping the event gateway to let it process part of the backlog each time. One very useful thing to note about the event gateways: if you ask them to stop, they do so gracefully, accepting no more entries on the queue but waiting for active threads to complete before actually stopping.

Tags: coldfusion

Asynchronous Development - Manual or Automatic Startup?

May 30, 2005 ·

Should you set your event gateway to start up automatically or manually? Well, it depends on what the gateway does (amongst other concerns). If you have a gateway that starts consuming and processing data as soon as it starts up, such as a JMS subscriber, then you probably ought to set it to startup manually. If your gateway is passive, such as an asynchronous CFML gateway or a JMS publisher, then it is safe to set it to startup automatically. Why does it matter at all? What happens when you want to perform maintenance on your server? You need ColdFusion running so you can access the CF Administrator but you may not want it to process data while you're doing maintenance work. If you're dealing with a lot of event gateways and they are set to automatic startup, then when you restart your ColdFusion server, it's going to be very busy when it starts up: all those event gateways will start consuming data and they will all be competing with each other for CPU resources. If you set them to startup manually, then you can bring them online in a controlled manner, perhaps one at a time, to avoid swamping the server, letting each gateway clear its backlog and "settle down" before starting up the next gateway. We have servers with several event gateway instances defined. We have the passive gateways set to automatic startup since they don't do anything until they are asked to. We have the active gateways (data consumers) set to manual startup. This allows us to control how the server behaves after a restart to ensure that we don't overwhelm the CPU during that initial backlog processing. Note that our passive gateways are often used as services by our active gateways - another reason to have the former on automatic startup and the latter on manual startup: that avoids the situation where an active gateway starts up but the passive gateway it depends on (for background processing or data publishing) has not fully started up yet.

Tags: coldfusion

Asynchronous Development - Things to Consider

May 30, 2005 ·

When I posted about the infrastructure project launch, I mentioned that we had missed an interesting test scenario and that I'd talk about it in a future post. This is not that future post but I'm going to set some background for that issue first. Prior to ColdFusion MX, developers didn't have to think much about multithreaded execution of their code: they locked all shared scope access and that was it. With CFMX, or at least with CFMX 6.1, developers now had to face the issue of thread safety far more directly if they were writing CFCs: if you forget to var declare a local variable and that CFC is stored in a shared scope, you could get some very unpredictable results under load because multiple requests would overwrite your shared scope data. Much has been written about the necessity of vardeclaring all your local variables so I'm not going to belabor that point. Now CFMX 7 brings the ability to write code that executes in response to events and protocols other than HTTP requests. It has an explicit event queue and an explicit thread pool. The CFCs you write for event gateways can be executed by many requests at once so if you use shared scopes, you need to exercise the same level of care about var declaring all local variables. Using the asynchronous CFML gateway is very easy: store your parameters in a struct, call sendGatewayMessage() and off it goes, to be executed in parallel, while your code continues on. Your event gateways can be set to start up automatically when CFMX starts up, or they can be set to require manual startup. I'm going to write a blog entry shortly that should help you decide which is the best choice for a given event gateway. The other thing to consider is how much parallelism you need. Bear in mind that each event gateway thread is effectively a simultaneous request for CFMX to execute and, for performance reasons, you'll see that the number of simultaneous requests that CFMX can handle should be limited so that the server is not overwhelmed (3-5 per CPU is the rough guide). I'm going to write a blog entry about how this concern also applies to the event gateways.

Tags: coldfusion

Localizing ColdFusion MX 7

May 30, 2005 ·

Radek Gruchalski has published a tutorial on his Polish ColdFusion web site showing how you can localize the ColdFusion Administrator and all the messages that ColdFusion outputs, as well as the debugger and the component browser. The article is in both Polish and English - the link above should take you to the beginning of the English version.

Tags: coldfusion

Tartan - Getting it running on BlueDragon

May 27, 2005 ·

I spent several hours over the last couple of nights trying to get Tartan running on BlueDragon 6.2. I found several bugs in BlueDragon in the process. The first stumbling block is that BlueDragon does not support WEB-INF.cftags.component as the universal base class for all components. It's mentioned several times in the CFMX documentation so this is at best a compatibility issue that New Atlanta should document and at worst a bug they should fix. Workaround: change WEB-INF.cftags.component to any. The second stumbling block I hit was that the pseudo-constructor of a derived CFC could not access variables set in the pseudo-constructor of the base CFC. New Atlanta just released a Hot Fix that fixes this bug. You'll need it to get Tartan running. Then I tripped over <cfbreak/>. BlueDragon thinks that's an illegal tag. Add a space and it's happy: <cfbreak />. I found the same problem with <cfrethrow/>. Changing it to <cfrethrow /> made BlueDragon happy. Finally, BlueDragon does not allow derived CFCs to call private methods in the base CFC via super. Since private methods are accessible to derived CFCs (because CFML's private really means protected), this should definitely be valid. Workaround: change ServiceFactory.getServiceArgs() to be access="public". At this point my sample application (for my frameworks talk) runs on BlueDragon in all seven variants. Oh, and this exercise did highlight a bug in my code! My Tartan configuration file did not have a <parameters> tag around my DAO factory parameters which caused them to be ignored. This meant that my queries were being run with username="" password="". On CFMX, blank credentials are ignored and the values in the data source (in the CF Admin) are used. On BlueDragon, the blank credentials are used (so the queries failed).

Tags: bluedragon · coldfusion · tartan

Code OOverhead?

May 27, 2005 ·

A common complaint about OO from people who are new to it is that it seems like a lot of work and a lot of extra code just to get stuff done. Joe Rinehart talks about why he thinks OO makes you write less code rather than more.

Tags: coldfusion

A Bit of ColdFusion History

May 27, 2005 ·

I meant to blog this the other day. I think Steven Erat has done a great job in pulling together some interesting milestones in ColdFusion's history based on Allaire's website through the years. Three floppy disks. Wow!

Tags: coldfusion