Steven Erat's Blog Steven Erat Photography
 
 
Viewing By Entry
 
 

TalkingTree  How ColdFusion Receives and Processes Requests.

 

Here's another post I made to the internal forum for my class on Database Design where I describe how requests are handled by ColdFusion and how the webserver connector works in general. Reposting here in case anyone finds it useful.

--

A question was asked in yesterday's class regarding the difference between making requests to the Apache port versus the ColdFusion port.

Effectively, the answer is that there is no difference for the purpose of this class.

ColdFusion MX has a built-in webserver that can be used in lieu of an external, production-quality webserver like Apache, Iplanet, or IIS. The default for this built-in webserver is port 8500, 8501, or 8300 depending on the type of installation and CF version, and that port is configurable.

This built-in webserver, also known as a Java Web Server or JWS, is not intended to be used in production but only in development since it is not tested or maintained to be as robust and secure as production-quality webserver. So, if your career is resting on this decision, use ColdFusion with Apache or IIS. It turns out, however, that the Macromedia website (macromedia.com) receives incoming traffic on clusters of Apache webservers and Apache then proxies the request to CF/JWS in turn using mod_proxy. The web architect found that configuration better than using Apache alone for their particular environment.

The way ColdFusion works with Apache or any other external webserver is ColdFusion will install what is known as a stub or connector, built in C++, and that connector will be loaded into the webserver process. In Apache, the connector runs as dynamic module called mod_jrun20.so. Apache is built from a core server and dynamically loads modules at runtime that extend Apache's functionality.

When a HTTP Request is sent from a browser to a website, a webserver like Apache receives the Request. The Request is filtered by the modules loaded into Apache. The ColdFusion connector module will have a chance to review the Request information and if the Request matches certain patterns that are to be associated with the ColdFusion server, then the connector will handle the request by passing it on the ColdFusion server. Certain file extensions are handled by the connector including *.cfm, *.cfc, and more as well as servlet mappings such as /flashservices/gateway.

The way the connector hands off the Request to ColdFusion is that it opens a TCP connection to the ColdFusion server and sends the associated Request information such as the HTTP Headers and Data. ColdFusion receives the request and attaches it a thread responsible for executing that Request. Part of the Request is the page name such as /some/path/to/hello.cfm along with Cookies, Form or URL data such as ?action=dosomething &dosomething=update ¶m1=1 ¶m2=2 for example as a list of name value pairs that have semantic meaning to the ColdFusion application code.

ColdFusion is both a server and a language. The language is CFML and CFML is parsed, compiled, and executed by ColdFusion the server. In fact, ColdFusion *IS* Java actually. The ColdFusion server itself runs on an underlying J2EE (Java 2 Enterprise Edition) server, which in most cases is an embedded version of Macromedia JRun. Other well known J2EE servers include WebSphere, WebLogic, and Tomcat.

When ColdFusion receives this HTTP Request it will look in a corresponding location on the file system for the file hello.cfm in this case and read the source CFML code. The source CFML is actually converted to Java much in the same way JSP code is converted to Java, and then compiled to a Java class file. The resultant Java class file is most often written to disk and stored (optional) and is in turn compiled to bytecode that is held in memory.

In that last paragraph, I fibbed a little bit to make the process clearer. That is how ColdFusion MX 6.0 worked. In ColdFusion MX 6.1 and 7 the CFML source code is converted directly into bytecode in memory, skipping the whole Java source and Java class file process using a bytecode emitter that's wicked fast, without ever having to write the Java source file or class file to disk.

That bytecode in memory is executed as a program that takes into consideration all the information about the Request including HTTP Headers, Data, and URL/FORM data. The code executes the CFML that you the developer have written, including your queries and everything else. Most often the result of running a CFML code page is that HTML will be generated and is intended to be sent back to the browser (although its sometimes the case for no data to be returned because the page may have performed some task which requires no response to the browser). So while the program is running, the generated HTML is collected in a buffer, and at the end of program execution the HTML result is returned via TCP back to the connector stub.

The connector stub then hands the data back to Apache, and Apache sends an officious HTTP Response back to the browser.

Since the communication between the connector/Apache and ColdFusion is over TCP, then ColdFusion server can reside either on the same machine or possibly on a remote machine somewhere inside your DMZ or intranet.

Its quite common that a company will use firewalls not only between their DMZ and the public internet, but will use them within their intranet as well. Linux in particular usually runs its own firewall iptables and will filter requests on localhost. This is usually what troubles administrators that attempt to connect Apache to ColdFusion, that a firewall is running on the system and is interefering with the TCP communication required during the installation of the connector and the running of the connector.

Hopefully this helps to clear up the mystery behind what goes on inside ColdFusion.

 


Comments

Hi Steven,

I hope your classmates realize just how lucky they are to have someone like you in in their class. This has been an excellent series of posts so far. Please keep them up!


And all this time I thouhgt it worked automagically...great post!


Thanks Rob and Scott. Normally I spend all my time working with people who are at an intermediate to advanced level of ColdFusion skills. Its really interesting to see how people who are otherwise technologically proficient approach ColdFusion for the first time or because they use ColdFusion as a preferred intermediate to work with a database but haven't previously been so interested in the details of ColdFusion internals.


Great post... I'm going to forward it through to some coworkers in other areas.

T


Steven, you mentioned that the way bytecode is created in CFMX 7 results in faster performance (for initial page loads).

"In ColdFusion MX 7 the CFML source code is converted directly into bytecode in memory, skipping the whole Java source and Java class file process using a bytecode emitter that's wicked fast, without ever having to write the Java source file or class file to disk."

I haven't seen this reported or documented in the release notes. I'm not doubting you, but are you saying that initial compile times for pages are significantly faster in CFMX 7 than in CFMX 6? I would expect that once compiled to bytecode, the version of CFMX would not matter in regards to performance.


Damon,

In CFMX 6.l ColdFusion stopped using the JIKES compiler, which was responsible for the very noticible compile times in CFMX 6.0, and started using BCEL instead which is much faster. CFMX 7.0 still uses BCEL, but I'm not exactly sure when the bytecode emitter was introduced, but I think it may have been with 6.1. I was generalizing some points in this topic so as to not overwhelm.

BCEL is mentioned in some documentation, but its not highlighted as a feature anywhere. Tom Jordahl of Macromedia ColdFusion Development explained to me how the bytecode emitter is so fast, converting from cfm source to bytecode, that the difference in time between compiling the source to bytecode vs reading the stored class file and then converting to bytecode is virtually negligible. Tom's recommendation was to actually not turn on the option to save class files since writing the class file will actually things down a tiny fraction.


Excellent article! I have this archived.


Just echoing many of the comments above Steven; great article and you are covering things here which are almost totally absent from typical CF Training but yet are vital to know, in my opinion.


Thanks to the team at ColdFusionPodcast for reminding me that the direct step from CFM Source to Java Bytecode occurred in CFMX 6.1 not CFMX 7. I've modified the post to be more accurate.


In what kind of application environment would it be advantageous to separate your CF and Web Server? Seems like a server dedicated to just shipping off CF requests would have alot of idle time.


Usually sites that have a paranoid level of security concerns, i.e. banks, like to configure in distributed mode.


Another reason to separate the web server and the CF server is to reduce the load on the CF server. Images and static files can be served directly from the web server, and only CF requests get passed to the CF server. For a typical web page, there are many times more requests for images, stylesheets, javascript files, and so forth than for CF pages.


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search This Site

 
This is an exact search only

topics

 
adobe blogging coldfusion computer technology events flex java learning linux mac os x macromedia meetup new england odds & ends outdoors personal photos photoshop science travel video

About This Site

 
Adobe Alumni & Community Professional. Expert in ColdFusion, Flex, LCDS, Photoshop, Lightroom. Linux RHCE. Follow Me!. For my photography check out Boston Portrait Photographer.

Speaker at CF.Objective(): Automated UI Testing with CFSelenium, MXUnit, ANT, and JenkinsCI

Adobe Community Professional (ACP)
Red Hat Linux Certified Engineer

Recent Entries

 
Automated System Testing for ..
Could not find ColdFusion com..
No April Fools: Selenium Ship..

Recent Comments

 
Posted By Steven Erat:
Jim, and anyone else that may attend, if you would like the full slide deck and my demo project files BEFORE the conference, please reply as a comment ...

Posted By Jim Priest:
Can't wait for this one!!

Posted By iPhone Repair:
It appears there are so many people have issue with their iPhone & iPod Touch screens dropped and cracked. It happened to me also when u haven't got a ...

recently played

 
Mr. Brightside
by The Killers
on Hot Fuss
Get Hot Fuss by The Killers on Amazon

now playing, a plug-in for itunes

Categories

 
RSS Adobe (34)
RSS Bicycling (9)
RSS Blogging (39)
RSS Books (13)
RSS Breeze (13)
RSS CFMX Podcasts (10)
RSS ColdFusion (437)
RSS Computer Technology (51)
RSS Events (26)
RSS Flex (20)
RSS Gadgets (11)
RSS HiTech Industry (16)
RSS Java (26)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (23)
RSS Macromedia (27)
RSS Meetup (35)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photos (111)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Twitter (10)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

RSS

 


Add to Google
Add to My Yahoo!

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2012 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer