Search In
Greetings!
Please let me know if this should go into a different forum, or if this needs to be posted to the issues list in codeplex. Thank you in advance for your time in reading and helping me with this. This is a major issue that we are having, affecting the performance of our production web site (we've had to turn Umbraco caching completely off, and can sometimes get thousands of requests per hour).
I'm hoping I'm an idiot and there's one setting I'm forgetting to set that will fix all of this!
We are using Umbraco for a fairly busy website, and we are encountering problems when caching is enabled on our macros - specifically on macros that are .NET user controls. The short version of the problem is: When the website is under moderately heavy load (20+ users at the same time reloading the same page), the content that is cached gets messed up. Sometimes it doesn't load at all, so all of areas in the page where the macros are supposed to be are blank; sometimes the macro content seems to overwrite itself - we'll see data repeated in the same control.
We are using a fairly-heavily customized installation of Umbraco 4.0.3, using ASP.NET 3.5. We have about 50 user controls (almost all of them pull data from a DB) that we use at many places within the site. I was concerned that maybe we broke this when customizing it, or maybe our user controls were doing something out of the ordinary, but I was able to recreate the problem using a stock installation of Umbraco (installed via Web Installer), and a project with a single user control that just queries the Northwind database (Orders table) and writes the data to the page. Of course, the macro that is this user control has caching enabled. Changing any of the cache settings (time, cache by page/personalized) does not seem to change the outcome.
To simulate the load, I'm using a load test within Visual Studio Team Edition. If I set the number of concurrent users at 20 or more hitting a page that only contains a single macro/user control (the one that queries the Northwind database) with caching enabled, I see this issue. I don't see the issue if I just try to hit the page as hard as I can (by hitting refresh in the browser repeatedly, or by opening a bunch of browser windows and refreshing them).
Our best guess is that the problem is concurrency issues storing content in the cache - normal multi-threaded types of issues. For example:
Some more details:
Here is the code for the simple data user control that we are using to recreate the problem:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestDataUserControl2.ascx.cs" Inherits="TestUmbracoUserControlsCache.TestDataUserControl2" %> <asp:PlaceHolder ID="phContent" runat="server"></asp:PlaceHolder>
TestDataUserControl2.ascx.cs
using System; using System.Data.SqlClient; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace TestUmbracoUserControlsCache { public partial class TestDataUserControl2 : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { RenderControls(); } private void RenderControls() { try { SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand("SELECT top 120 * FROM [Orders] ORDER BY [OrderDate]", conn); //SqlCommand cmd = new SqlCommand("SELECT top 5 * FROM [Orders] ORDER BY [OrderDate]", conn); conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { Literal lit = new Literal(); lit.Text = reader[i].ToString(); phContent.Controls.Add(lit); } phContent.Controls.Add(new Literal { Text = "\n<br />" }); } reader.Close(); conn.Close(); } catch (Exception ex) { Response.Write("<br />XXX Exception: " + ex.ToString() + "<br />"); //throw; } } } }
x
I forgot to add one possibly important point:
I've tried running the Application Pool in Classic and Integrated mode, and it doesn't seem to change the outcome (i.e., we still have the problem). And I'm using the IIS7/ASP.NET 3.5 -specific web.config file that was provided.
I am seeing similar issues except that I have pages that return 500s sometimes. Also, there are performance spikes where a page will have a 50ms response time, then every few seconds a batch of request will have 200ms-300ms response times. I have not gotten into turning off macro caching. I looked at the source code and there are no locks around the cache sections like you say. This can cause all types of issues. I am concerned as well. Please let me know if you would like to talk direct.
I opened up the Umbraco core and fixed this cache race condition. Source code is checked in here.
umbraco.codeplex.com/.../65950
I have the same problem. Cached macros randomly doesn't show under heavy load. It's easily replicable by running apache ab tool and refreshing browser - some cached macros are not rendered. AB tool reports failed requests too. I've tried Tommy's solution, but it doesn't seem to work for me . Maybe there are some configuration issues because not many people reports this problem.
You should be closing your reader and connection to the database in a finally statement, otherwise they wont be closed when an exception is thrown.
I don't think that reader is the problem in this particular situation. I've just recreated this behaviour in V4.5 (latest post relates to V4.0.4). After clean installation with runway module I cached top navigation, ran ab tool and refreshed browser. In about 5-10% of requests navigation doesn't appear and ab shows errors. No cache no problems .
Hello guys, does anyone has find the solution for this issue ?, currenty I'm running a website but it's extremadly slow but when I activate the cache this increase response time up to 50%, but I'm still experiencing this bugs.
Having a similar issue, where cached macros do not always appear. The load is not especially heavy, but it's on IIS7. Our local dev IIS6 site doesn't have the issues. Maybe it's an IIS7 thing?
Please upvote the issue on Codeplex if you are experiencing this too.
umbraco.codeplex.com/.../27610