RoBlog - Refactoring reality

Friday, November 19, 2004

Straight in at number one!

Current Status: Amber

I am not someone who pretends to understand the vagaries of search engine optimisation or how to hype a site. However, I have just noticed that, after one week of having any content in my blog, I am straight in at number one on Google.

Just a straight query on "Rob Levine" puts me at the top. You don't even have to add "Bristol" or "UK".

Now that is something of a result! I'll be interested to see how long I hold the position.

Monday, November 15, 2004

Frustrating http connection behaviour in .Net (C#)

Current Status: Red

I seem to be having a bit of a frustrating time with http connections in .Net at the moment.
Basically I am working on a project in which many subsystems use http to communicate with eachother. Once in a while, my .Net client will fail with a "System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server." exception.
The remote server can be an IIS server or a Jetty server running on Linux - I see the same problem with both.

To try and reproduce this problem I wrote a very simple client app that requests a single static page from a web server. It loops round making the request repeatedly, up to 100000 times.
Here is the static Main method from my console application:

static void Main(string[] args)
int i = 0;
for (i = 0; i < 10000; i++)

HttpWebRequest req = (HttpWebRequest)
using (HttpWebResponse resp =
byte[] buffer = new byte[1024*1024];
int read = 0;
Stream stream = resp.GetResponseStream();
read = stream.Read(buffer, 0, 1024*1024);
while (read !=0);
req = null;

if (i % 1000 == 0)
catch (Exception ex)
Console.WriteLine("Exception at iteration " + i);
Console.WriteLine( ex.ToString());


For this example I created a very small html file to put on my server - only 50 bytes.
I see some extremely peculiar behaviour when I run this application; generally the first time it runs, it will process many thousands of iterations before falling over with the aforementioned exception. Once it has failed, if I attempt to run it again straight away the application fails in a matter of a few 10's or 100's of iterations. Why?
It makes no difference to the overall behaviour if I swap my HttpWebRequest stuff for a System.Net.WebClient.
It makes no difference if I insert a GC.Collect() in the loop.
What is going on here and what is 'remembering' the fact that the client has previously failed?

I have to admit to being stumped for the time being.
Does anyone else see this behaviour?

Saturday, November 13, 2004

Overflowing Integers

Well - this is my first real blog entry. I wasn't sure how to get myself started, or what to talk about, so I created several dummy blog entries to test the system. The first of these was a few months back, but it wasn't until today that I created a couple more. Subsequently I deleted the two new ones.

After playing around with a little more I noticed that on my profile stats page the 'average posts per week' statistic showed a figure of 2147483647. Now I had hoped to be fairly prolific as a blogger, but this surpassed all my expectations - over 3,500 blogs per second!

Unfortunately I couldn't help but notice that this number is just one short of the point at which an signed integer would overflow.

(2^32)/2 = 2147483648

So appears to think my average blog rate is -1 blogs per week. An interesting concept I thought.