How CFThread Can Help OR Hurt Performance
I am working on a performance analysis for a client, some page requests need to do a cfhttp call, I had the thought to use
cfthread for the http call, so that other processing could happen in parallel.
Curious about this, I wrote some simple scripts to test, first my control script:
<cfhttp url="http://google.com/robots.txt" method="get"></cfhttp> <cfdbinfo datasource="cfdocexamples" name="tables" type="tables"> <cfoutput query="tables"> <cfif Left(tables.table_name, 3) IS NOT "SYS"> <cfquery datasource="cfdocexamples"> SELECT * FROM #tables.table_name# </cfquery> </cfif> </cfoutput>
Next my threaded script:
<cfthread name="doit"> <cfhttp url="http://google.com/robots.txt" method="get"></cfhttp> </cfthread> <cfdbinfo datasource="cfdocexamples" name="tables" type="tables"> <cfoutput query="tables"> <cfif Left(tables.table_name, 3) IS NOT "SYS"> <cfquery datasource="cfdocexamples"> SELECT * FROM #tables.table_name# </cfquery> </cfif> </cfoutput> <!--- make sure thread is done processing ---> <cfthread action="join" name="doit" />
I then used Apache Bench to create some concurrent load on the scripts:
|Test||Avg Execution Time|
|Control (10 concurrent requests)||143ms|
|Control (15 concurrent requests)||221ms|
|Control (20 concurrent requests)||290ms|
|Threaded (maxthreads=10, 10 concurrent requests)||119ms|
|Threaded (maxthreads=5, 10 concurrent requests)||247ms|
|Threaded (maxthreads=2, 10 concurrent requests)||727ms|
|Threaded (maxthreads=10, 15 concurrent requests)||195ms|
|Threaded (maxthreads=10, 20 concurrent requests)||248ms|
As you can see when you limit the number of threads that can be created you create a bottle neck in your application (this is why I wrote an entry when CF8 came out titled CFThread Don't Abuse It. You might wonder why I choose maxthreads=2 for one of the tests... If you are running Standard Edition that is the most concurrent threads you are allowed to create with
cfthread, for a situation like this it can really hamper performance.
This test also illustrates how using threads (with the correct settings) can increase performance.
- CFThread - Don't Abuse It - August 7, 2007
- OutOfMemoryError - GC overhead limit exceeded - March 25, 2010
- Cache Template in Request Setting Explained - February 25, 2010
- ColdFusion 9 Performance Brief from Adobe - February 24, 2010
- Docker Container exited with code 137
- Why is my cron.daily script not running?
- Announcing FuseGuard Version 3
- CFSummit 2017
- Java Unlimited Strength Crypto Policy for Java 9 or 1.8.0_151
- Java 9 Security Enhancements
- Upcoming CFML Conferences in April 2017
- CFSummit 2016 Slides