Friday, April 30, 2010

The State of My Farm

I'm pretty happy with the coverage I get with my current insurance carrier. I've never really been tempted to go looking around to save a few bucks. Granted I don't really know every detail about my coverage like some people do but it is so hard to be an expert at everything. It's nice to have someone whose job it is to make sure that you are taken care of, take care of it. I did compare life insurance policies though and found a better deal for my wife. It saved us a bunch of money but neither of the companies was the one that we use for car/home.

Tuesday, April 27, 2010

The Draft

Another year, another NFL Draft. I was actually pretty pleased with the Brown's draft choices. They addressed the areas that I felt they had the most need. Only time will tell if this draft will be the acneticin needed to wipe away the blemishes that have plagued this team for years but I'm optimistic for some reason.

I imagine it starts with having a credible president in Mike Holmgren. I'd love to see the Brown's win the Super Bowl but I'm ok with the logical next step of just fielding a competitive, credible team.

Here's to hoping.

Tuesday, April 20, 2010

Print?

I'm not a big business guy. I have never owned or even attempted to own my own business or even done stereotypical business work. I'm a programmer, and other than working for a business, I don't know that I could count myself among those that know much about business. Having said that, I imagine that there are a lot of people who use online printing services.

So do those types of businesses do really well? I'm sure they probably do, because who wouldn't need someone to handle the annoyances of document creation for them? Sounds like a good idea to me.

Thursday, April 01, 2010

Writing Out Very Large Files

I recently ran into an issue in which I need to write out a very large file (upwards of 250Mb) in Groovy (could just as easily have been Java). In researching ways to do this I discovered the java.nio package which includes FileChannels. If you haven't played around with these yet, I encourage you to give them a try. They are super fast, and if you are doing IO and handling a lot of data, there really isn't another option.

The challenge that I had, was dealing with the heap size. Even with a FileChannel, I still had no way to hold the entire file in memory. So I came up with a pretty cool solution. It's simple but it seems to have hit the sweet spot for processing between holding a large object in memory vs. the cost of writing it out. I needed to do this because I was writing across a mounted drive and the writes were costly. With a local drive it wouldn't have been an issue.

I needed to print out each record in order to a file based on it's contents. I found that using a BufferedOutputReader was DOG slow, and the FileChannel write for each record was really fast locally, but struggled over the mount. Ultimately I decided on an approach that used a StringBuffer to store up records in order and then write them out once the Buffer got large enough. The interesting thing was that there was a significant point in which no further gain in processing time seemed possible. Basically once the Buffer reached a length of 150,000 characters.

So I had a loop that looked like this:

StringBuffer good = new StringBuffer()
StringBuffer bad = new StringBuffer()

records.each { rec ->
if (good.length() > 150000) {
ByteBuffer buf = ByteBuffer.wrap(good.toString().getBytes());
goodChannel.write(buf)
good = new StringBuffer()
}

if (bad.length() > 150000) {
ByteBuffer buf = ByteBuffer.wrap(bad.toString().getBytes());
badChannel.write(buf)
bad = new StringBuffer()
}

//read the next record and do my processing

if (goodRecord) {
good.append(chunk)
} else {
bad.append(chunk)

}

//Then print out whatever is left in case the Buffers aren't empty
if (good.length() > 0) {
ByteBuffer buf = ByteBuffer.wrap(good.toString().getBytes());
goodChannel.write(buf)
}

if (bad.length() > 0) {
ByteBuffer buf = ByteBuffer.wrap(bad.toString().getBytes());
badChannel.write(buf)
}


This worked extremely well for large file processing, given that I had to contend with the heap size. I wouldn't do this for most IO problems but for very large files, this is really effective.

Next Year Already

I'm not very optimistic about the upcoming Browns season. As far as I can tell, they are rebuilding again. They will either draft a ton of new players or trade all their picks to get Sam Bradford, but either way, next year is not going to be "the year". So we can go ahead and start the funeral planning for the Brown's 2010-2011 season.

My guess is that it will be a small service with few attendees, but I think in time we will all be able to move on. There is always 2047 to look forward to.