Concurrent access to BlogEngine.NET

Topics: ASP.NET 2.0, Business Logic Layer, Controls
Apr 1, 2014 at 2:28 PM
Dear developers:
I am currently using BlogEngine.NET (version 2.8). After deploying on my local computer, I tested it with high load (about 25 threads to access the website simultaneously) and encountered HTTP 500 error. There always existed two types of exceptions:

1 – exception trace (see attachment), and the code snippet
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
Line 122: {
Line 123: ul.RenderControl(hw);
Line 124: blogsHtml[blogId] = sw.ToString();
Line 125: }
Line 126: }
Source File: d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\App_Code\Controls\CategoryList.cs Line: 124


2 – exception trace (see attachment), and the code snippet
Exception Details: System.ArgumentException: An item with the same key has already been added.
Source Error:
Line 155:
Line 156: if (!profiles.ContainsKey(Blog.CurrentInstance.Id))
Line 157: profiles.Add(Blog.CurrentInstance.Id, BlogService.FillProfiles());
Line 158:
Line 159: return profiles[Blog.CurrentInstance.Id];
Source File: D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\AuthorProfile.cs Line: 157

Meanwhile, the page access time significantly grow when the exceptions start to appear. The CPU usage in the server can easily reach 100% when the number of user exceeds 25.
We checked the corresponding source code, and tried to add locks to the two code snippets, specifically, we add a lock for line 124 in exception 1 and line 156-157 in exception 2 respectively. After that, we ran the test again. The exceptions disappeared and no more httpstatus500 occurred.

So hope you can help answer 2 questions
1 – What is the maximum supported number of concurrent access in BlogEngine.NET? Why did such exception happen?
2 – Are there any risks when we add the lock in the source code? Since in the latest version 2.9, there is still no lock on the corresponding code.

Thanks a lot for your help!

Martin


The stack trace:
Exception 1:

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Collections.Generic.Dictionary2.Resize(Int32 newSize, Boolean forceNewHashCodes) +3931186
System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add) +665
System.Collections.Generic.Dictionary2.set_Item(TKey key, TValue value) +34
App_Code.Controls.CategoryList.get_Html() in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\App_Code\Controls\CategoryList.cs:124
App_Code.Controls.CategoryList.RenderControl(HtmlTextWriter writer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\App_Code\Controls\CategoryList.cs:145
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
App_Code.Controls.WidgetBase.Render(HtmlTextWriter writer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\App_Code\Controls\WidgetBase.cs:118
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
ASP.themes_standard_widgetcontainer_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\WidgetContainer.ascx:8
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
App_Code.Controls.WidgetZone.Render(HtmlTextWriter writer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\App_Code\Controls\WidgetZone.cs:266
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
ASP.themes_standard_site_master.__Render__control9(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master:43
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +151
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +49
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
ASP.themes_standard_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master:18
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
StandardSite.Render(HtmlTextWriter writer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master.cs:47
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.Page.Render(HtmlTextWriter writer) +40
BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) in D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\Web\Controls\BlogBasePage.cs:243
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5363


Exception 2:

[ArgumentException: An item with the same key has already been added.]
System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add) +13911685
System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +34
BlogEngine.Core.AuthorProfile.get_Profiles() in D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\AuthorProfile.cs:157
BlogEngine.Core.AuthorProfile.GetProfile(String username) in D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\AuthorProfile.cs:467
BlogEngine.Core.Post.get_AuthorProfile() in D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\Post.cs:365
ASP.themes_standard_postview_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\PostView.ascx:9
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +49
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
ASP.themes_standard_site_master.__Render__control9(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master:43
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +151
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +49
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
ASP.themes_standard_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master:18
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131
StandardSite.Render(HtmlTextWriter writer) in d:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.NET\themes\Standard\site.master.cs:47
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246
System.Web.UI.Page.Render(HtmlTextWriter writer) +40
BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) in D:\BlogEngine.NET 2.8 (source)\Source\BlogEngine\BlogEngine.Core\Web\Controls\BlogBasePage.cs:243
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5363
Aug 7, 2014 at 6:33 AM
Same issue here - https://blogengine.codeplex.com/discussions/550585

do you have this issue on version 3.0 ?