|By Simon Horwith||
|October 20, 2004 12:00 AM EDT||
Beginning with the release of ColdFusion MX, the ColdFusion Application Server now runs on top of an underlying Java engine. Java, as we all know, is an object-oriented language. However, the question of whether CFML is an object-oriented language has been under debate since the ColdFusion Component (CFC) Framework was introduced in ColdFusion MX.
Too much energy has been spent bantering about whether CFML is object oriented, rather than exploring uses for the object-oriented features that CFCs brought to the language. Among these features were inheritance, support for the creation of Web services, the ability to encapsulate data and business logic in objects and to perform instance-based development, and metadata.
So many new features mean that the rules have changed for ColdFusion developers. We must now relearn and redefine best practices, which not only means changing the way we write code but also the way that we plan our applications. Fortunately, we can take advantage of a wealth of knowledge about what does and doesn't work. We can do this by studying the design patterns and development techniques that have been tried and tested by object-oriented developers, most notably Java developers, for more than a decade. Because of the very nature of Web-application development, J2EE design patterns are particularly applicable when architecting applications with ColdFusion.
Unfortunately, understanding design patterns is only the first step toward building CFML applications the right way. There still remains the challenge of not only selecting the right pattern for the job, but also knowing how to implement a pattern (or not) in your code.
No single article, or book for that matter, could ever hope to provide the magic answer to determining what pattern to use when, or even how to properly implement any one design pattern in CFML. There are some patterns that lend themselves to the language very well and others that do not, and most could be implemented in any one of several manners. It would take several months, or years even, to properly test and document it all. The purpose of this article is to shed some light on a general realm of design patterns. This article will also case study a recent implementation that allowed me to quickly help reduce overhead, boost performance, and add functionality to a client application. It is just one example of how knowledge of design patterns and creativity with CFML can allow you to achieve your goals quickly and efficiently.
Working as a consultant, I am often asked to advise on architectural decisions as well as troubleshoot existing architectures. A client of mine developed an application (a framework) with ColdFusion allowing rather inexperienced developers to quickly and easily create data entry and data display screens on the Web. The idea being that defining the database table with XML and adding a few lines of code to a display file and a CFC (which inherits from a parent "object" code base) is all it takes to create screens that have a uniform look and feel and reproduce the screens in a massive legacy application. The client hopes to move the entire legacy application onto the Web within two years.
My role for the past year has primarily been to assess risks, advise on the best course of action, and to come in and fix problems when all else has failed. As you can imagine, at any given moment I might be researching several issues at once. Just prior to a recent major release of the software, I was asked to look into two major issues. One was the replication of sessions when servers in our J2EE clusters failover and the other was application performance in general.
The first thing I did was tackle the session replication problem. As it turns out, this was right around the time that J-Run Updater 4 and the ColdFusion MX 6.1 Updater were both released to the public. Unfortunately even with both updaters installed, after all of my testing I was unable to consistently make ColdFusion session variables replicate to a server that was added to the cluster. Session replication and failover works pretty consistently - when you turn off a server everything fails over and replicates fine. However, when you add a server back into the cluster, the session doesn't always replicate onto the new server properly. The application server console always reports a J2EESessionScope error when a server rejoins the cluster. Sometimes ignoring this message appears to be okay, and sometimes it does not. It's also worth noting that sending requests while a server was in the process of rejoining the cluster seems to encourage session replication failure. All of my tests with "pure" Java, even simple JSP files, consistently worked. Sessions always replicated just fine. One of my rules of thumb is to never spend too much time on one error, so I put that problem on the back burner and focused on the other problem: performance. We'll revisit the question of session replication later.
There are a lot of things that can kill performance and a lot of things that can be done to speed things up in an application. Every developer has a mental list of the things they do on a page or in an application to make it efficient (use CFSCRIPT, avoid unnecessary looping/conditional logic/HTTP, cache things in memory, optimize and minimize database calls, etc.). The list can be huge but the last two points, taking advantage of the server's memory and minimizing/optimizing calls to the database, are the two most common ways developers speed up their applications. But what can you do to speed up an application that already has all of these things in place? Go line by line through the code looking for small tweaks here and there?
You could do that, but the performance gains would be minimal and it would take a long time in this case. The application I was working with already consisted of about 600 files including not only the framework, but also the screen definitions and accompanying logic as well. The application I was asked to optimize also already had a great deal of caching and code reuse in place, and all of the database access had been gone over with a fine-tooth comb. When faced with a situation like this, I find that it's a good strategy to take a step back and look at the big picture.
Looking at the entire application from a distance must be a lot like looking at Earth from outer space. There are no countries, no borders, and no politics. There's just water, land, and clouds all working together to create that delicate balance needed to sustain life. All of the minute details blur together, allowing you to concentrate on the system as a whole rather than trying to focus on all of the smaller parts, which in the big picture are insignificant. When I thought about how I would model this client's application and how all of the parts of the model interacted, I looked for problems. If I didn't find any, I'd take a step back. Eventually, a potential problem almost always presents itself. In this case, when I finally got to the point of blurring modules into single tiers that interact with one other, something dawned on me: tier communication patterns.
It had been some time since I'd thought about all of the design patterns I've studied in the past. But I remembered that there are a few patterns I'd read about that deal primarily with communication between tiers in an application, whether those tiers were the presentation and business logic tiers or business logic and database. The application I was optimizing had a terribly high number of CFC instances being passed around between the presentation layer and the business components, between Java and ColdFusion, and between business components and other business components. I hadn't thought about this as a problem because the individual CFC instantiations and method calls were taking very little time at all. Most of the CFCs were instantiated and cached in memory once and then reused throughout the application. Still, there is a certain amount of overhead in passing instances of complex objects around in memory as well as in persisting all of the instruction sets for dozens of components. Many of these were even cached in sessions (for justifiable reasons). A few patterns came to mind that might shed light on a possible solution: Data Transfer Objects, Lazy Load Pattern, and the IsDirty Pattern. So I went back to the books and brushed up on the intricacies of these three patterns and some of their related patterns.
After refreshing my memory about these patterns, it became clear that what I was looking for was something along the lines of the Data Transfer Hash Pattern (the other patterns I mentioned have qualities I'm looking for but are more specific to database interaction). The idea behind the Data Transfer Hash Pattern is that passing instances of objects around carries with it a lot of overhead, so hashmap representations are used instead. Think of a hashmap as the Java equivalent of a ColdFusion structure. It's much more lightweight moving a hashmap data structure around rather than a complex object that contains functionality (e.g., a CFC instance). The one downside is that there's no easy way to enforce the values within that hashmap. This is a problem more easily remedied in Java by using Objects, but all too familiar and not-so-easily remedied in ColdFusion, as our only option is to use a CFC with a constructor. The IsDirty Pattern, in a nutshell, is all about setting a Boolean flag in a data container so that database commands to manipulate data are executed only when data has actually changed. The Lazy Load Pattern is similar to IsDirty in that it reduces database connectivity overhead. However, it does so by not retrieving data until it's specifically requested. In implementing the Data Transfer Hash Pattern, I will also borrow from these ideas in that I will keep external object access to a minimum until it is required. But the solution is still in essence more of a Data Transfer Hash Pattern solution.
So how do I put this idea of only transferring simple data collections rather than object instances into practice? Ideally, I'd like a way to represent the data contained within a CFC instance as a structure. Furthermore, I want to do so in a way that's flexible, easy for the end users of the framework to implement, and doesn't break the existing code base. Fortunately, there are some features in CFML that I can take advantage of to make this work.
For one thing, we have inheritance. In my particular scenario I could easily modify component.cfc to offer this functionality within all CFCs. I described this technique in an article titled "component.cfc: The Mother of All Components" in the November 2003 issue of ColdFusion Developer's Journal. The code has to be very portable, which means that I don't want to rely on this technique. Fortunately for me, because my "fix" must be implemented in the context of a framework and all CFCs in that framework inherit from a "master" CFC, I can easily create a component and specify that the "parent" inherits from it (via the <CFCOMPONENT> tag "extends" attribute). It also occurred to me that until an elegant solution to my session replication woes is found, this pattern offers the added bonus of helping to address that problem as well. In ColdFusion MX (6.1 or prior) CFC instances are not serializable. This means that they cannot be replicated across servers in a cluster. I knew this and did advise my client that all CFC instances in the session scope had to be made nonpersistent. This resulted in two code bases. One we wanted to implement but couldn't until serialized CFC instances is supported (a feature rumored to be in Blackstone). The other one works around the issue by not keeping CFC instances in the session scope. If I could present a way to represent CFC instances as structures, not only would it reduce overhead, but it would also offer a means to persist CFCs and have them replicate. This could be accomplished by serializing and deserializing them as structures. Although I was having trouble making serialization work for ColdFusion, structures map to hashmaps (and vice versa) quite well. Plus I'd already proven that Java session information serializes just fine.
My solution took advantage of the metadata created for CFCs: metadata exposed with the getMetaData() function. I created three methods. One simply accepts a CFC instance and returns its metadata in a more "friendly" format. Another accepts a structure and the name (including full package) of a component and returns an instance of that component populated with the structure data. The third method accepts a CFC instance and returns a structure containing all of its properties. How could I guarantee that I retrieved all of the properties?
My requirements were simple, and fortunately the framework coding standards that were already in place assured me that the following conditions already exist. When serializing the data in a CFC within a structure, I look for any property defined with a <CFPROPERTY> tag. If a method exists with the name "get" plus the property name, the code calls that method to get the value. If a property is defined that doesn't have a "getter," I copy it directly from the component's public "this" scope if it exists. When creating a component instance from a structure, I create an instance of the component and look for an init() method. If a nonprivate init() method exists and the structure contains keys with names of any and all required parameters, I pass the parameters to the init() method. After calling the init() method, if it exists, the code then loops over the structure that was passed and calls any method named "set" plus the structure key name (passing it the structure key value). If no "setter" exists but a public property with the same name as the current key name exists, the code sets a variable in the component's "this" scope with the name-value pair from the structure. It's probably not the most robust or flexible solution in the world, but it does serve my purpose.
The rest of the implementation details are just a matter of persisting structures whenever possible if an object isn't likely to receive much activity and serializing that structure as a CFC instance in the event that an actual object is required in a certain scenario. It's worth noting that in a system in which the CFC instances receive frequent method calls that manipulate their data, the overhead serializing and deserializing to and from structures carries more performance hit than simply keeping a component instance in memory. However, often in other scenarios you can free up a significant amount of memory and other resources by not keeping so many objects in memory. This may result in better performance (it did in my scenario).
More and more it is becoming evident that it's necessary to have at least a basic understanding of design patterns. Coupled with the features in ColdFusion MX, this opens up the doors to a whole new realm of development solutions using CFML. Any of you who are interested in seeing the code I used to implement this solution, may download it from www.sys-con.com/coldfusion/sourcec.cfm or from www.horwith.com/downloads/dto.zip.
I encourage you to not just examine my code but (more important) think about alternative approaches to problems and creative methods for implementing the design patterns that already exist and are just waiting to be explored by ColdFusion developers. It's also worth noting that the technique I've outlined is what J2EE application servers already do to serialize sessions in a cluster. The application server itself is a very good place to look for inspiration when trying to determine how best to meet business requirements in your applications.
"My role is working with customers, helping them go through this digital transformation. I spend a lot of time talking to banks, big industries, manufacturers working through how they are integrating and transforming their IT platforms and moving them forward," explained William Morrish, General Manager Product Sales at Interoute, in this SYS-CON.tv interview at 18th Cloud Expo, held June 7-9, 2016, at the Javits Center in New York City, NY.
Aug. 23, 2016 09:00 PM EDT Reads: 2,939
Cloud computing is being adopted in one form or another by 94% of enterprises today. Tens of billions of new devices are being connected to The Internet of Things. And Big Data is driving this bus. An exponential increase is expected in the amount of information being processed, managed, analyzed, and acted upon by enterprise IT. This amazing is not part of some distant future - it is happening today. One report shows a 650% increase in enterprise data by 2020. Other estimates are even higher....
Aug. 23, 2016 09:00 PM EDT Reads: 2,743
Internet of @ThingsExpo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 19th International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world and ThingsExpo Silicon Valley Call for Papers is now open.
Aug. 23, 2016 08:45 PM EDT Reads: 3,726
Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more business becomes digital the more stakeholders are interested in this data including how it relates to business. Some of these people have never used a monitoring tool before. They have a question on their mind like “How is my application doing” but no id...
Aug. 23, 2016 08:15 PM EDT Reads: 1,617
The 19th International Cloud Expo has announced that its Call for Papers is open. Cloud Expo, to be held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, Big Data, Internet of Things, DevOps, Digital Transformation, Microservices and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportuni...
Aug. 23, 2016 07:00 PM EDT Reads: 3,781
19th Cloud Expo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Meanwhile, 94% of enterpri...
Aug. 23, 2016 05:00 PM EDT Reads: 2,873
Internet of @ThingsExpo, taking place November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 19th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devices - comp...
Aug. 23, 2016 04:00 PM EDT Reads: 3,475
SYS-CON Events announced today that Venafi, the Immune System for the Internet™ and the leading provider of Next Generation Trust Protection, will exhibit at @DevOpsSummit at 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Venafi is the Immune System for the Internet™ that protects the foundation of all cybersecurity – cryptographic keys and digital certificates – so they can’t be misused by bad guys in attacks...
Aug. 23, 2016 02:15 PM EDT Reads: 2,493
Smart Cities are here to stay, but for their promise to be delivered, the data they produce must not be put in new siloes. In his session at @ThingsExpo, Mathias Herberts, Co-founder and CTO of Cityzen Data, will deep dive into best practices that will ensure a successful smart city journey.
Aug. 23, 2016 01:45 PM EDT Reads: 1,399
SYS-CON Events announced today that 910Telecom will exhibit at the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. Housed in the classic Denver Gas & Electric Building, 910 15th St., 910Telecom is a carrier-neutral telecom hotel located in the heart of Denver. Adjacent to CenturyLink, AT&T, and Denver Main, 910Telecom offers connectivity to all major carriers, Internet service providers, Internet backbones and ...
Aug. 23, 2016 01:15 PM EDT Reads: 1,706
DevOps at Cloud Expo, taking place Nov 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 19th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait for long dev...
Aug. 23, 2016 12:00 PM EDT Reads: 1,995
In today's uber-connected, consumer-centric, cloud-enabled, insights-driven, multi-device, global world, the focus of solutions has shifted from the product that is sold to the person who is buying the product or service. Enterprises have rebranded their business around the consumers of their products. The buyer is the person and the focus is not on the offering. The person is connected through multiple devices, wearables, at home, on the road, and in multiple locations, sometimes simultaneously...
Aug. 23, 2016 09:30 AM EDT Reads: 2,214
For basic one-to-one voice or video calling solutions, WebRTC has proven to be a very powerful technology. Although WebRTC’s core functionality is to provide secure, real-time p2p media streaming, leveraging native platform features and server-side components brings up new communication capabilities for web and native mobile applications, allowing for advanced multi-user use cases such as video broadcasting, conferencing, and media recording.
Aug. 23, 2016 06:45 AM EDT Reads: 2,024
Data is the fuel that drives the machine learning algorithmic engines and ultimately provides the business value. In his session at Cloud Expo, Ed Featherston, a director and senior enterprise architect at Collaborative Consulting, will discuss the key considerations around quality, volume, timeliness, and pedigree that must be dealt with in order to properly fuel that engine.
Aug. 23, 2016 06:45 AM EDT Reads: 1,619
Akana has announced the availability of version 8 of its API Management solution. The Akana Platform provides an end-to-end API Management solution for designing, implementing, securing, managing, monitoring, and publishing APIs. It is available as a SaaS platform, on-premises, and as a hybrid deployment. Version 8 introduces a lot of new functionality, all aimed at offering customers the richest API Management capabilities in a way that is easier than ever for API and app developers to use.
Aug. 23, 2016 03:30 AM EDT Reads: 1,367
Personalization has long been the holy grail of marketing. Simply stated, communicate the most relevant offer to the right person and you will increase sales. To achieve this, you must understand the individual. Consequently, digital marketers developed many ways to gather and leverage customer information to deliver targeted experiences. In his session at @ThingsExpo, Lou Casal, Founder and Principal Consultant at Practicala, discussed how the Internet of Things (IoT) has accelerated our abil...
Aug. 23, 2016 01:30 AM EDT Reads: 1,798
With so much going on in this space you could be forgiven for thinking you were always working with yesterday’s technologies. So much change, so quickly. What do you do if you have to build a solution from the ground up that is expected to live in the field for at least 5-10 years? This is the challenge we faced when we looked to refresh our existing 10-year-old custom hardware stack to measure the fullness of trash cans and compactors.
Aug. 23, 2016 12:45 AM EDT Reads: 1,566
The emerging Internet of Everything creates tremendous new opportunities for customer engagement and business model innovation. However, enterprises must overcome a number of critical challenges to bring these new solutions to market. In his session at @ThingsExpo, Michael Martin, CTO/CIO at nfrastructure, outlined these key challenges and recommended approaches for overcoming them to achieve speed and agility in the design, development and implementation of Internet of Everything solutions wi...
Aug. 23, 2016 12:15 AM EDT Reads: 1,791
SYS-CON Events announced today that CDS Global Cloud, an Infrastructure as a Service provider, will exhibit at the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. CDS Global Cloud is an IaaS (Infrastructure as a Service) provider specializing in solutions for e-commerce, internet gaming, online education and other internet applications. With a growing number of data centers and network points around the world, ...
Aug. 22, 2016 01:30 PM EDT Reads: 2,142
SYS-CON Events announced today that LeaseWeb USA, a cloud Infrastructure-as-a-Service (IaaS) provider, will exhibit at the 19th International Cloud Expo, which will take place on November 1–3, 2016, at the Santa Clara Convention Center in Santa Clara, CA. LeaseWeb is one of the world's largest hosting brands. The company helps customers define, develop and deploy IT infrastructure tailored to their exact business needs, by combining various kinds cloud solutions.
Aug. 22, 2016 12:30 PM EDT Reads: 2,502