09 Mar
Posted by: Brandon Harper in: A Day In The Life Of, ColdFusion
Lately at work I’ve been doing a performance analysis of a product which has been in development for quite some time. Well, quite some time by ColdFusion standards at least. The particular piece I developed which I’m testing uses the ColdFusion 7 event gateway to essentially fire off threads which each run individual long running processes. As an aside, one thing that I absolutely love about the Event Gateway feature is the ability to control the number of running threads for a given gateway instance, as well as the ability to queue events beyond the number of active threads. This is a very nice feature and keeps me from having to somehow manually manage that which would be quite the conundrum.
Anyhow, during said testing, I’ve uncovered several instances of thread unsafe code which to me is no surprise given the rather large code base this product currently occupies. Surprisingly to me a couple of the instances of thread unsafe code were commonly distributed UDF’s from CFLib from well known people in the CF community. I went to check the UDF’s in question out again on CFLib and they been updated and fixed, so there is no reason for me to really point out anything specific (and I’m not that sort of person anyhow.. I’d contact them in private about it). In reality the versions of UDF’s contained in the code base I’m working with could of been up to a couple of years old. That said, if you have some UDF’s in your code base that you didn’t write yourself, you might want to see if they’ve been updated since adding them in.
This testing process which has uncovered thread unsafe code before actually doing a formal load test analysis has certainly had me thinking though. Using the Event Gateway feature seems like a really good way to perhaps implement automated thread safe unit testing through something such as CFCUnit, without needing to do a full load test to uncover thread unsafe code. For instance this would be especially advantageous if your organization depends on some sort of 3rd party to do load testing; it would be a good idea to take care of any code upfront which was not thread safe. Anyhow, just a fleeting thought really; unfortunately I don’t have the time at the moment to pursue this to see how feasible it is.
5 Responses
Jake
09|Mar|2005 1How exactly did you discover which chunks of code weren’t thread safe? Did the testing help you track it down somehow or did you just notice “something wrong”?
Brandon
09|Mar|2005 2The way I’ve come across code which is unsafe via running it through Event Gateways so far has mostly been counter variables which were not properly var’ed. When a counter is in a shared scope because it has not been var’ed, and is also using the same instance of a component (such as something which has been cached in the server scope), the various threads processing the same type of event will step on each other by incrementing the same counter. So say the function you’re using loops through a list– since all of the threads are incrementing the same counter variable, you’ll end up getting an error such as “In function ListGetAt(list, index [, delimiters]), the value of index, 6, is not a valid as the first argument (this list has 5 elements). Valid indexes are in the range 1 through the number of elements in the list.”
However this only covers counter variables and not actually checking to make sure that the data returned from a method is not getting hosed-up by thread unsafe coding– you’d need a way to manually look at each output of a given thread as well as know ahead of time what the expected output from each thread was. This is where potentially using CFCUnit along with a proper test plan would help out.
Though every time I run across a counter problem, I also look through the rest of the code in a given method to see if I can find any other no-no’s as well.
Brandon
09|Mar|2005 3I forgot to mention, the way I initially stumble across these isssues is because a given thread doesn’t complete successfully, and/or there are errors in the server error log each time I fire off these events.
Jake
09|Mar|2005 4But as far as actually tracking down teh offending method, I assume it’s just a matter of where/when the thread fails and then just combing through code…?
Brandon
09|Mar|2005 5Yep, pretty much. It doesn’t always fail though it will leave exceptions in the error log.
Leave a reply
Search
Categories
Archives
Links
Calendar
A design creation of Design Disease
devnulled is a personal blog and reflects the ideas and opinions of brandon harper and not his employer, dog, shoes, or stapler.
All content copyright © 2002-9002 brandon harper. All rights reserved.
devnulled is powered by FreeBSD, WordPress and the combustion of dead dinosaurs. It has also been made magically delicious by the pfm module.