Question

I've heard that CFHTTP calls that point to a local server can cause additional delays for the user. As this is a HTTP request, it seems to me that any delays would be negligible - though I don't know a whole lot about networking/systems and load-balancing.

Are there any downsides/cons to using CFHTTP to make local calls and if so, are there ways to mitigate those?

Was it helpful?

Solution

What is it that you're trying to do with these HTTP calls? If whatever you're fetching by HTTP is on the local file system, actually using the file system (fileRead(), include, etc) rather than the network to get them will be more expedient.

That said, if you do actually want to perform a request for whatever reason (which is completely legit in some situations), then I don't think the performance overhead would be something to worry about. Although I'd not want to be doing this sort of thing on every onRequestStart(), etc.

I think you need to elaborate on what it is you're setting out to achieve here.

OTHER TIPS

it seems to me that any delays would be negligible

Perhaps, it would depend on your traffic and any other latency problems you're having. I did a simple test that fetched 5 paragraphs of pre-generated Lorem Ipsum dummy text that was served from the same CF server. The result took between 15 to 47 milliseconds, which as I said, depends on you to decide if it is negligible. Personally I think it's a bit high but from a user perspective, it wouldn't be noticeable in my environment.

As far mitigation, if you're trying to re-use code I'd consider putting your authentication into a cfc. This is beneficial because you can use it in multiple local applications as well as a web service if needed (which is technically what you're trying to do by using cfhttp).

What is the problem with including the process in a cfinclude as you said you were doing before? testing proved including the same pre-generated Lorem Ipsum text took 0 MS every time.

<cfset start = getTickCount()>
<cfhttp url="http://myServer.com/test/lipsum.cfm" method="get" >
<cfset end = getTickCount()-start>
<cfoutput>it took #end# MS to get the Lipsum.</cfoutput><br />
<cfset start = getTickCount()>
    <!-- <cfinclude template="lipsum.cfm"> -->
<cfset end = getTickCount()-start>
<cfoutput>it took #end# MS to include the Lipsum.</cfoutput>

it took 43 MS to get the Lipsum.
it took 0 MS to include the Lipsum.

You don't specify whether you're calling back into the ColdFusion server itself or another service hosted locally. It might help to expand the question a little to provide a use-case.

The speed penalty of calling a local server will be relatively small and in some cases that may be fine, e.g. making a call to a local Solr server to get search results. It will however likely be much slower than calling a function locally within CF.

What I'd be concerned about would be calling back into the server you are executing the ColdFusion on. This is probably a sign that things could be better organised or arranged. I've done this in the past (as a cheap'n'cheerful way of running a background task), but wouldn't do it now that <cfthread> exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top