Tuesday, November 25, 2008

Oceans Ten Times More Acidic Than Thought

http://www.morguefile.com/archive/?display=98154
National Geographic has a curious article entitled, Oceans Ten Times More Acidic Than Thought" that contains so many errors it's difficult to know where to begin. For starters, the title implies that the ocean is ten times more acidic that previously thought, like it slipped from 6.5 to 5.5pH, catching researchers off guard. In reality, it's the increase in acidity that is ten times higher than some climate model predicted. Perhaps a better title would have been, "Global Warming Model Incorrect By an Order of Magnitude".

The word "Oceans" in the title implies many of our oceans have increased acidity, but the article cleanly states the research applies to the ocean around one island (or perhaps "Oceans" in the title needs a possessive apostrophe).

A whale of a contradiction in the article is "...carbon dioxide dissolves in the oceans it forms carbonic acid, which in turn has a negative impact on marine life.", but later the article claims, "Larger mussels and barnacles suffered, leaving smaller barnacles and some calcium-based seaweeds better off."
Increased acidity doesn't have a negative impact on all marine life. Under almost any change in environment, some species will do better and other will flounder.

The article ends with a stinging quote: "This is typical of so many climate studies—almost without exception things are turning out to be worse than we originally thought." This clearly is a call to the readers to do something about the tsunami of impending climate change. Although it could be argued from the article that there's something fishy with these climate models which can't make accurate predictions.

The whole article should be taken with a grain of salt.

Friday, November 21, 2008

C# OutOfMemoryException and StringBuilder

We had an interesting OutOfMemoryException this week. When creating really long strings and adding them to a StringBuilder, we get the OutOfMemoryException way before we really run out of memory. Come to find out, StringBuilder is searching for contiguous memory and may not find that long before you run out of real memory.

To help find your upper limit of memory use, .Net provides the friendly MemoryFailPoint as shown below:


using System;
using System.Runtime;
using System.Text;
namespace PlayingAround {
class Memory {
private static void Main() {
MemoryFailPoint memFailPoint;
StringBuilder sb = new StringBuilder("1234567890");

for (int i = 0; i < 100; i++) {
Console.Out.WriteLine("");
try
{
int aboutToGetMemoryInBytes = sb.Length*5;
Console.Out.WriteLine("aboutToGetMemoryInBytes = " + aboutToGetMemoryInBytes.ToString("#,##0"));
int aboutToGetMemoryInMegaBytes = (int)(1 + (aboutToGetMemoryInBytes >> 20)); //round up to the next megabyte
Console.Out.WriteLine("aboutToGetMemoryInMegaBytes = " + aboutToGetMemoryInMegaBytes.ToString("#,##0"));
using (memFailPoint = new MemoryFailPoint(aboutToGetMemoryInMegaBytes)) {
Console.Out.WriteLine("GC.GetTotalMemory(true) = " + GC.GetTotalMemory(true).ToString("#,##0"));
Console.Out.WriteLine("sb.Length = " + sb.Length.ToString("#,##0"));
//Console.Out.WriteLine(System.Environment.WorkingSet.ToString());
sb.Append(sb.ToString());
}
}
catch (InsufficientMemoryException) {
Console.Out.WriteLine("InsufficientMemoryException.");
var maxMem = GC.GetTotalMemory(true);
Console.Out.WriteLine("maxMem = " + maxMem);
break;
} catch (OutOfMemoryException) {
Console.Out.WriteLine("OutOfMemoryException.");
break;
}
}
Console.Out.Write("press return to exit.");
Console.In.ReadLine();
}
}
}

Wednesday, November 12, 2008

DataTable.Compute considered harmful

Our team has been investigating a particularly obscure bug in our .Net 3.5 application. During load and performance testing we crashed the application on our Windows Server 2003 test farm. IE7 would not render the page, Firefox crashed the application pool. We got three basic errors:
1. application pool had been abandoned.
2. "aspnet_wp.exe (PID: 2536) stopped unexpectedly."
3. a stack overflow error.
Oddly the application ran fine on our Windows XP boxes used for development. After much searching and testing the problem was with
DataTable.Compute(string expression, string filter) 

We had a large filter string which exhausted the memory on the machine since the filter was used in a recursive manner. It did not help that the stack size in IIS for Server 2003 was reduced to 256K from 1MB in 2000. (In retrospect this was a good thing since it exposed an error earlier in testing and not later in production).
We will rewrite the code calling Compute() and do it iteratively in our C# code. Not all uses of Compute() are bad, but be careful about using large filters.

Monday, October 20, 2008

Syntax Highlighting via Javascript with SHJS




After doing my own code syntax highlighting for the web by injecting span tags into code snippets using lisp functions inside emacs, I realized it's not the way to go. The right way to do this would be a javascript function that would decorate the code after it's been sent to the browser. I ran across SHJS, Syntax Highlighting in JavaScript on sourceforge. SHJS is very easy to set up and gives great results in many languages.
I've attached two graphics, one using Watir in Ruby and the other a little C#.
If you publish code on the internet you should use SHJS or something like it. It's just too easy not to use and it leaves your HTML very clean.
You can see my results for Ruby, C#, Java, Perl, JavaScript.


Monday, October 13, 2008

TV shows now on Youtube




Youtube has just announced a major deal to start showing full-length TV shows like StarTrek with commercials. This puts Youtube in direct competition with Hulu, Joost, imdb, and a host of others showing tv shows over the web. Although Youtube's initial lineup is paltry, it shows a lot of promise.
The most exciting angle is the Tivo one. TiVo can access Youtube videos right now if the TiVo is connected to the internet. Since TiVo sits right next to my TV I don't have that PC-to-TV 10-yard gap. So, instead of taking up space on my TiVo, I can use Youtube's storage to host my old tv shows. But since I don't really watch old tv series, it doesn't mean a lot to me at the moment, but I can foresee in the not too distant future that first run shows are on Youtube which makes it interesting. It would help if TiVo could also access Hulu.com content.
What if all first run shows were available on Youtube?
1. I won't need a terabyte TiVo. In fact, I wouldn't need any disk space at all. Tivo will just get the shows on demand.
2. What is a TV network then? Independent producers could just make shows to go directly on Youtube without a network exec saying, "That will never work.". With production costs dropping, it's easier than ever to make your own tv shows and sell them on youtube.
3. Google, the owner of Youtube, would shake up the tv advertising market. Google would disintermediate a lot of advertising firms that specialize in buying/selling tv ad time. Companies could just bid for slots on tv shows just like they do for adwords. Also Google could target specific audiences on the fly with just-in-time advertising. Google can estimate your age (from your gmail account, past searches, etc) which would help, but they would be able to deduce your zip code, which tells a lot about you.
With a TiVo, Youtube tv on demand, and a fast internet connection, the world will be an interesting place. I can just envision Dr. McCoy leaning over the prone body of network tv, turning to Kirk and saying, "He's dead Jim.".

Friday, October 10, 2008

Time Warner Tuning Adapters now available for preorder in Austin TX!!


Oh happy day!
I've been waiting for 6 months for the Tuning Adapters from TimeWarner Austin so my Tivo can pick up all the Switched Digital Video (SDV) signals. Many of the high-def stations on TimeWarner are delivered via SDV which one-way cable cards, like the one in my TiVo, can't see. SDV channels are only sent to your home when requested, unlike regular channels which are always being broadcast to everyone. When a viewer requests an SDV channel the set-top box sends a message to a TimeWarner computer saying, "Send me History International", and the computer will say, "OK, I sending that to you on channel 3423". The set-top box then tunes to channel 3423, which just seconds ago was empty. In theory, this frees bandwidth for more channels.
You can now pre-order your free Tuning Adapter at http://www.timewarnercable.com/centraltx/Products/Cable/sdv/default.html.
It's a happy thing - trust me.

Wednesday, October 08, 2008

Agile Austin's Meeting Tuesday Night


book

The Agile Austin user group had sixty-seven people attend a great talk given by John Heinz of gistlabs.com entitled "Test Automation: The Big Picture". John started with a slide saying, "Testing is hard, coding is fun." which was a good start to talk about testing automation.
He reiterated some of the Toyota Production System mantras: Eliminate waste, only work on valuable products for your customer; optimize the whole, not the parts; build quality in, don't test for quality.

He also made it a point to say you shouldn't test everything, because testing is expensive. Testing does have a point of diminishing returns.
John recommended Implementing Lean Software Development by Mary Poppendieck and Tom Poppendieck.

John also recommended the Simian project to detect duplicate code.