ColdFusion CFQuery BlockFactor Is Not Impressing Me

Posted October 11, 2006 at 6:09 PM by Ben Nadel

Tags: ColdFusion, SQL

I have never used the ColdFusion CFQuery blockfactor attribute before. I have heard about it, but never payed much attention. I came across it in an article the other day, so I thought I'd give it a spin to see how it performs... and I have to say, I am not really seeing any great results. To test it, I am doing a simple query that returns the union repeated union of the largest table I have in the database.

Here is the standard CFQuery tag, no blockfactor in use:

  • <!--- Test the speed of the query. --->
  • <cftimer label="Standard Query" type="outline">
  •  
  • <cfquery name="qHit" datasource="...">
  • SELECT
  • t.id
  • FROM
  • (
  • (
  • SELECT
  • id
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 100)
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 1000)
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 10000)
  • FROM
  • web_stats_hit
  • )
  • ) AS t
  • ORDER BY
  • t.id ASC
  • </cfquery>
  •  
  •  
  • <p>
  • #NumberFormat( qHit.RecordCount, "," )# web hits found
  • </p>
  •  
  • </cftimer>

This returns 210,868 records in about a 800 ms (on average). That's a pretty good record set I think. Now, let's throw in the blockfactor attribute. In ColdFusion, this can be between 1 and 100 and stands for the number of records that the SQL server can return at a given time.

  • <!--- Test the speed of the query with BlockFactor. --->
  • <cftimer label="BlockFactor Query" type="outline">
  •  
  • <cfquery name="qHit" blockfactor="100" datasource="...">
  • SELECT
  • t.id
  • FROM
  • (
  • (
  • SELECT
  • id
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 100)
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 1000)
  • FROM
  • web_stats_hit
  • )
  •  
  • UNION ALL
  •  
  • (
  • SELECT
  • (id * 10000)
  • FROM
  • web_stats_hit
  • )
  • ) AS t
  • ORDER BY
  • t.id ASC
  • </cfquery>
  •  
  •  
  • <p>
  • #NumberFormat( qHit.RecordCount, "," )# web hits found
  • </p>
  •  
  • </cftimer>

Again, this returns 210,868 records. This ran in about 900 ms on average. That's 100 ms SLOWER than the same query with no blockfactor. I tried adjusting the size of the blockfactor, but none of the numbers I used seemed to make a difference.

I understand that not all databases understand the blockfactor. But, I'm using Microsoft SQL Server. I don't know, but I am guessing that it understand blockfactor as it is like THE sql server out there (not intending to stir up conflict here).

So, operating under the assumption that MS SQL Server does indeed work with blockfactor, my testing shows (repeatedly) that the CFQuery that uses blockfactor performs slower than the non-blockfactor CFQuery. What gives? Is there something here that I am totally not getting? Is 211,000 records not enough for the blockfactor to make a dent? Why is the blockfactor running slower?



Reader Comments

Oct 11, 2006 at 7:24 PM // reply »
14 Comments

Ben,

It's been a while, but as I remember it, blockfactor seemed to work best with oracle databases.


Oct 11, 2006 at 10:25 PM // reply »
11,246 Comments

Damn you Oracle... Damn you :) Thanks for tip Rob.


Oct 12, 2006 at 12:25 PM // reply »
8 Comments

A couple of things I've noticed over the years about blockfactor. First off, in Oracle they can make a HUGE difference. For very intense queries, where without the processing time could be 40,000+ milliseconds without blockfactor, I've seen them drop to 1,000+. Quite a difference.

Another thing, I think I remember about them, it isn't that MS SQL Server doesn't know how to use them, it might be that the driver you are using to connect to the database doesn't use them.

Last but not least, you don't always see the speed difference in a query if you only run it once. Sometimes you have to run it several time to see that there is in fact a difference.

Just my two cents, hope it sheds some light...


Oct 12, 2006 at 12:28 PM // reply »
11,246 Comments

Demian,

I appreciate the comment. I never thought about the actual driver having anything to do with it. I am a bit removed from all of that stuff. I also live in a MS SQL Server-centric universe :) Good to know though. Thanks.


Oct 13, 2006 at 10:30 AM // reply »
11 Comments

One thing I remember about blockfactor that may be of large importance to you is that the blockfactor is not the NUMBER OF ROWS that the database should return in a single packet, but the SIZE OF THE DATA it should return in a single transfer packet.

You may find this quote from MM's coding guidlines useful:

BEGIN QUOTE

Use blockFactor to increase query performance:
Adding blockFactor to a query can significantly improve performance. To add blockFactor, examine the data that is being returned. Determine the maximum size (in bytes) of each row. Take that size and determine how many times that number would divide into 32k. That number is your blockFactor, but be aware that the max blockFactor is 100. So, if for example you were getting 200 bytes per row, you could easily fit over 100 rows into the 32k buffer that CF 'grabs' at one time.

If you know at runtime that you will have less then 100 rows returned, for example you're writing a query that either returns 0 or 1 rows, do not bother adding the blockFactor attribute.

http://livedocs.macromedia.com/wtg/public/coding_standards/performance.html

END QUOTE

I have seen this attribute make a big difference when used correctly. Also consider how fast the network between your database and CF server are (did you mention where your DB is relative to your CF Server?)...on a faster network, the benefit may not show up until larger amounts of data are being passed or the complexity of the work blockFactor adds to the process is less than the benefit it provides to the data transfer process.

Anyway, I would suggest some more playing around on this, not that the CF Docs really give an accurate depiction of the blockFactor attribute in the first place.

Mike.


Oct 13, 2006 at 10:57 AM // reply »
11,246 Comments

Mike,

Thanks for the good comment. Our local DB is on a different machine than our CF server. Same network... same shelf :) I will do some more playing around, but at over 200,000 records in my example, I was very suprised to only see no advantage, but to actually see a disadvantage to using blockfactor.


Jun 5, 2009 at 12:34 PM // reply »
1 Comments

Working on a large query using the blockfactor tag attribute did make a difference in the return of the data. Using a data source connecting to a MS SQL Server 2005.

Thank you for the awesome site...


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 24, 2013 at 5:39 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam Oops! My mistake! I hadn't gotten that far in my testing - I'm still baby stepping my way through the process. ... read »
May 24, 2013 at 5:13 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
Hi Jason, Thanks for checking up on that, but I still stand firm on my position. :) There are actually two listLast()'s in use, and you're right that the one using a space as a delimiter is fine. ... read »
May 24, 2013 at 4:45 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Ben I have been lurking your site for quite some time, and haven't stepped up to comment until today. Thanks for all the great info - keep it up! @Adam I believe you are mistaken... as the commen ... read »
May 24, 2013 at 11:21 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, Ha ha, let's us never speak of justifying "##" notation again :P ... read »
May 24, 2013 at 11:18 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Ah, so it was indeed how I vaguely remembered it to be: A direct assignment value = users.id[ i ] causes value to retain the sticky datatype of the query column. Although unnecessary in ... read »
May 24, 2013 at 9:11 AM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Brandon, Hi, No, I haven't been able to do that. I have just kept it as it is. ... read »
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools