Tag timeouts in HostMySite shared hosting

I recently moved a client to HostMySite.com and I am for the most part happy with their service. I have used them in the past and have recommended others to use them. One of their policies in the CF shared hosting plan is that page requests that are longer than 50 seconds are timed out. This is a good policy and to be quite blunt I think 50 seconds is much to long for the average web application. Anything that requires page request that are longer than 50 seconds deserves a dedicated (or virtual) server. I however encountered a problem with this particular policy since my client's site kept timing out during the checkout process. I built the application and was quite upset that the pages were taking that long. I looked at everything and it seemed that all was in working order. It worked randomly though which is always a good reason to pull your hair out! I couldn't replicate the problem on any other box and I still am not sure why this is a problem on HMS specifically. But to outline the problem and the solution:

The Problem:

The shopping cart uses the Data Access Object pattern for all data access. When a shopper makes an order, the contents of the basket are placed in an Orders_Items table which logs each item. These items are tied together by an Orders table. For each item added to the Orders_Items table a new object is instantiated and destroyed. I understand that this could be a problem but for one item, one would not think that it would take 50 secs to instantiate. These objects are in the variables scope so they exist only for the duration of the page. Apparently this is where the problem existed. During all the object instantiations it caused the page to time out.

The Solution:

Move all object instantiation to a persistent scope (Application or Session). If you are using the DAO pattern you should have an init() function handy that would initialise your component so use this instead of creating a new instance of the object.

This solution cut page times down from (sometimes) greater than 50 seconds to around 40 milliseconds. I always tried not to place too many objects in the Session or Application scopes because of scaling issues, however if object instantiation and persistence is carefully planned it can reduce execution times and increase efficiency in your applications.

Happy Coding!

Related Posts

This entry was posted in ColdFusion and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.