ASP.NET, Ninject 및 MVC : 성능 부하 문제
-
21-08-2019 - |
문제
문제 설명 :이 모델은 한 번에 한 명의 사용자와 잘 작동합니다. 여러 사용자를 한 번에 얻 자마자 SQLDATAREADER를 닫지 않는 것과 관련하여 심각한 오류가 발생합니다. 다음과 같이 게으른로드를 끄면 :
persistencemodel.conventions.onetomanyconvention = (prop => prop.setattribute ( "lazy", "false"));
괜찮지 만 성능은 느립니다. 이것은 MVC 베타 1을 사용합니다
이견있는 사람?
아래에는 내 글로벌 ASAX의 스 니펫과 SessionFactory inialization 코드가 있습니다.
*********** 이것은 내 Global.asax에 있습니다 ********
public class MvcApplication : NinjectHttpApplication
{
public static IKernel Kernel { get; set; }
protected override void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes.IgnoreRoute("WebServices/*.asmx");
routes.MapRoute("CreateCategoryJson", "Admin/CreateCategoryJson/{categoryName}");
routes.MapRoute("User", "Admin/User/{username}", new { controller="Admin", action="user" });
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Session_Start(object sender, EventArgs e)
{
if (Session["rSkillsContext"] == null)
{
string logonName = this.User.Identity.Name.Replace("NUSOFTCORP\\", string.Empty);
rSkillsContext context = new rSkillsContext(logonName);
Session.Add("rSkillsContext", context);
}
}
protected override IKernel CreateKernel()
{
log4net.Config.XmlConfigurator.Configure();
Kernel = new StandardKernel(new RepositoryModule(), new AutoControllerModule(Assembly.GetExecutingAssembly()), new Log4netModule());
return Kernel;
}
}
***** 이것은 나의 nhibernatehelper.cs ******입니다.
private ISessionFactory CreateSessionFactory()
{
var configuration = MsSqlConfiguration
.MsSql2005
.ConnectionString.FromConnectionStringWithKey("ConnectionString")
.ShowSql()
.Raw("current_session_context_class", "web")
.ConfigureProperties(new Configuration());
var persistenceModel = new PersistenceModel();
persistenceModel.Conventions.GetForeignKeyName = (prop => prop.Name + "ID");
persistenceModel.Conventions.GetForeignKeyNameOfParent = (prop => prop.Name + "ID");
// HACK: changed lazy loading
persistenceModel.Conventions.OneToManyConvention = (prop => prop.SetAttribute("lazy", "false"));
persistenceModel.addMappingsFromAssembly(Assembly.Load(Assembly.GetExecutingAssembly().FullName));
persistenceModel.Configure(configuration);
return configuration.BuildSessionFactory();
}
해결책
세션을 올바르게 처분하지 않은 것 같습니다 (한 달 전에 Ninject 및 Nhibernate와 동일한 오류가있었습니다). 요청이 시작될 때 시작해야하며 마지막에 배치해야합니다. nhibernate 세션을 시작하고 처분하는 코드를 제공 해 주시겠습니까?
제휴하지 않습니다 StackOverflow