skinniestman

Syndicate content
Where a Nerd can be a Nerd
Updated: 1 hour 30 min ago

Visual Studio 2008 Cheat Sheet

Tue, 2008-09-02 13:02 -

For all you C# fans out there, I came across this excellent keyboard cheat sheet today. One of Visual Studio’s best-kept secrets is its excellent keyboarding support.  And for all you VIM ninjas, get even more kb love with ViEmu.

Random

Magic of the Mod

Wed, 2008-08-27 21:11 -

Mathematics is full of weird and wonderful constructs that you can use to leap buildings in a single bound. If you examine even a small string of mathematical symbols, you’ll discover a complex dance of interrelated algorithms. Even the humble “plus” and “minus” operators reveal a fair number of mathematical principles and properties.

One of my favorite operators is modulo, or simply mod. This thing is pure magic. For example, suppose I needed to keep track of whether I was on an odd or even row in a table. People do this all the time to color alternating rows, making the information more readable. I could write some code like this:

  1. is_even = false
  2. rows.each do |row|
  3.   if is_even
  4.     color = :even
  5.   else
  6.     color = :odd
  7.   end
  8.  
  9.   is_even = !is_even
  10. end

Using the magic of the mod, I can simplify my life a little:

  1. rows.each_with_index do |row, i|
  2.   if (i % 2) == 0
  3.     color = :even
  4.   else
  5.     color = :odd
  6.   end
  7. end

Now, that was OK, but not really all that magical. But lets take this idea one step further. Suppose you were providing a web service and you had a bunch of clients connecting to your servers. In order to distribute the load, you could use some kind of proxy or load balancer. Each client would then connect to one IP address and the proxy would divvy up the requests among your servers. The problem with this is you have a potential bottleneck in your system; you can only respond to requests as fast as your proxy can process the traffic.

One alternative is to harness the magic of the mod. The first thing you need is some kind of unique ID for each client. This could be a username, a GUID, or whatever. The second thing you need is to give each client a list of servers it can connect to.

Now, the client will need to figure out all by itself which server in your cluster is its buddy for life. Its soul mate. The client does this by first taking it’s ID and hashing it into a number. The hash algorithm should have as even a distribution as possible (i.e., two IDs that are similar should hash to totally different numbers). Can you tell why this is important? Now, once the client has that fancy number in hand, it is time to invoke the magic of the mod. Simply mod the ID hash by the number of servers, and the number you get is the index of the server you should send your requests to.

If you are, well, paranoid, and want to ensure that a rogue piece of software isn’t sending everything to a single server, regardless of the client ID, you will need some way of looking up the ID for each request and then doing the same hash-lookup procedure on the server side that the client is supposed to do. If the result is kosher (i.e., the server receiving the request is the one the client should be talking to), the server processes the request. Otherwise, the server returns a big fat error. As big and fat as possible.

What is your favorite use for the mod?

Random

100% Is Not Efficient

Wed, 2008-08-13 23:06 -

The System z10 Enterprise Class—equivalent to approximately 1500 Intel x86 servers

IT people like to hang out at Starbucks discussing things that really matter, such as what Russia is doing in Georgia, or what the utilization numbers look like for the company’s servers. The sad reality is that most servers are provisioned with way more hardware than they need for the job. They may see occasional usage spikes, but the CPU is usually just chillin’ out, havin’ a bud. This is mostly due to the secret desire of every nerd to own the baddest, most awe-inspiring box on the planet. This is second only to their fascination with robots.

Now, there are really only a few ways you can justify all that muscle (without actually disclosing the real purpose):

  1. Slap a database on it. It’s a well-known fact that the average database needs at least 8 cores and 32 GB of RAM.
  2. Use it to run Ruby on Rails. Or Twitter.
  3. Sell the extra capacity, kind of like what Amazon does.
  4. Find more users. Unfortunately, this would require more work and less time playing WoW.

But should you even care that your systems are underutilized? Jeffrey Birnbaum, CTO at Merrill Lynch, has spoken out about better datacenter utilization. However, he warns against using more than about 80% of your resources, saying that this would leave your system unprepared for “unexpected circumstances”. This is good advice.

So, if striving for 100% efficiency is a bad thing for servers, what makes business managers think that it is somehow a good thing for people? Any real business has customers. And customers are the very definition of unexpected circumstances. Not to mention what your competitors might pull out of the hat. Organizations need to chill out a bit, just like their servers. There is no other way to remain agile and flexible.

When was the last time you heard some business leader say they wanted their organizations to be slower and less innovative? That they would rather not respond effectively to changing markets, thank you very much. Oh yes, and could my competition please come kick the crap out of me, please?

Forget about it. Stop stressing about keeping everyone working 100% of the time, and you may just find that people actually have more time to think about better ways of doing things. They won’t burn out. They might actually get some sleep once in a while and stop relying on worthless energy sodas to stay awake.

And, ironically, they may just get more work done.

Random

P.S. - For further reading on the subject, I highly recommend the books The Goal and Slack: Getting Past Burnout, Busywork, and the Myth of Total Efficiency

Who Killed the Electric Car?

Tue, 2008-08-05 09:16 -

A fuel cell car, powered by hydrogen made with electricity, uses three to four times more energy than a car powered by batteries.

Everyone should see this movie. The good news is that GM is finally getting their act together. Unfortunately, it looks like inexpensive electric vehicles for the common man are still at least 5 years away.

Random

Invent Stuff, Not War

Mon, 2008-08-04 12:45 -

Memo to Bush & Company: the best way to change the world is to innovate and invent, not blow it up. Work from the inside-out, like Ghandi. Too bad the world didn’t listen to his advice on how to deal with the Nazis.

Random

Tips for using the ASP.NET cache to store SQL Server DataSets

Mon, 2008-07-28 15:18 -

In my new job I’ve been not-so-gently introduced to the world of ASP.NET. Coming from a Ruby on Rails background, ASP.NET is like a slap in the face. Ouch! I ran into some major gotchas today while adding caching to an RSS feed (generally a good idea, BTW), via the ASP.NET global cache, datasets, and SqlCacheDependency. I thought I would share them with you in case you are in the same boat:

  • What in the world is SqlCacheDependency? See this article.
  • Most of the tutorials for caching on MSDN deal with output caching. You can’t do output caching with a generic web handler (among other things, these were used to provide RESTful interfaces in ASP.NET before WCF came along to save the day). So you will have to build up your output string on your own and cache it with a dependency on your model.
  • Make sure you are using SQL Server 2005 or later. Anything earlier requires lots of obligatory sit-ups to get things working, and uses polling behind the scenes (so it is much less efficient).
  • Make sure you use a unique key when adding items to the cache that includes query parameters and anything else you are referencing when you query your model to build the response.
  • If you are doing multiple queries, you will need to cache each one. If one query depends on a previous querie’s results, you need to use AggregateCacheDependency to make your cache expire not only when the main query’s results change, but also when the dependent query’s results change.
  • You can’t create a SqlCacheDependency object in isolation. You must use the one that was associated with the exact same SqlCommand object you used to load up your dataset.
  • You must create the SqlCacheDependency object before executing the command.
  • SqlCacheDependency does not work on views! But, you can still load a “view” into a typed dataset by opening the view in you designer and copying the TSQL into the query string in you code.

Random