Tuesday, July 08, 2008

A bad design with a webservice call.

We noticed at work the other day that a web service seemed to have a strangely high number of hits to it. I started looking into it the logs and found that the same user would hit the web service over and over. I could easily see that it was more than 40 times within the same second. This was curious. The developer who worked on this is not here any longer and nobody was sure why it would need so many hits.

I was off, searching through code trying to find the place where the web service was being pounded and the reason for it.

I found it.


public static string GetInfo()
{
   ArrayList u = new ArrayList();
   for(int x=1; x<100; x++)
   {
      u = WebServiceCall();
      if(u ==null)
      {
         z=1;
      }
   }
   return u;
}


If you are like me you looked at this code and went "Huh?"

Sadly though, there is no notation anywhere that states what the original problem was. I doubt that this crazy loop was only put here for the heck of it, something strange was probably happening and this was only part of the debugging method used to find the issue, but it was never removed and it was not documented. I am left with an application that hits the same web service 100 times and ignores the results of the first 99 attempts. This causes tens of thousands of unnecessary hits to the web service daily.

I have two suggestions for you. First, if you ever put something crazy like this into your code, add a comment explaining the craziness. Second, if you are really ignoring the first 99 results, then most likely this is some kind of business decision, you are trying to wait a certain amount of time for something. Put that business logic into the back end where it belongs.

No comments: