<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Nhibernate學習之性能改善1

      1.學習目標
          通過幾天來大家對Nhiberate的反映,很多人對它的性能非常的擔心,本文便著手從最直觀的角度和方法中逐步改善nhiberate的性能。改善性能是需要做出很多分析和測試的,本文試圖從最表層的對象入手,以后逐漸增加其他方面的性能分析。希望各位看官莫要著急。
       2. 分析:
          ISession和ISessionFactory對象的產生,使用,和銷毀對性能的影響。 
          ISessionFactory對象是線程安全的,它可以被程序的任意線程所適用,但是創建它的性能開銷是比較大的。所以不要頻繁創建ISessionFactroy對象
          ISession對象是非線程安全的,創建它的開銷比較小 
          創建一個ISessionFactory對象的主要流程有:
            
       這期間,包括對多個xml文件的解析和格式驗證,驗證的過程還包括對對象的反射。這些對性能損失非常大。用dottrace跟蹤程序執行,如下
       
      在web應用程序里面,將ISessionFactory對象放到預緩存里面,可以避免頻繁創建ISessionFactory對象。如
      using System;
      using System.Data;
      using System.Configuration;
      using System.Web;
      using System.Web.Security;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;
      using System.Web.UI.HtmlControls;
      using NHibernate;
      using NHibernate.Cfg;


      namespace WebApp
      {
          
      public sealed class NHibernateHelper
          
      {
              
      private const string CurrentSessionKey = "nhibernate.current_session";
              
      private static readonly ISessionFactory sessionFactory;

              
      static NHibernateHelper()
              
      {
                  
      string cfgPath = @"E:\my project\nhibernate study\simle 1\NHibernateStudy1\NhibernateSample1\hibernate.cfg.xml";
                  sessionFactory 
      = new NHibernate.Cfg.Configuration().Configure(cfgPath).BuildSessionFactory();
              }


              
      public static ISession GetCurrentSession()
              
      {
                  HttpContext context 
      = HttpContext.Current;
                  ISession currentSession 
      = context.Items[CurrentSessionKey] as ISession;

                  
      if (currentSession == null)
                  
      {
                      currentSession 
      = sessionFactory.OpenSession();
                      context.Items[CurrentSessionKey] 
      = currentSession;
                  }


                  
      return currentSession;
              }


              
      public static void CloseSession()
              
      {
                  HttpContext context 
      = HttpContext.Current;
                  ISession currentSession 
      = context.Items[CurrentSessionKey] as ISession;

                  
      if (currentSession == null)
                  
      {
                      
      // No current session
                      return;
                  }


                  currentSession.Close();
                  context.Items.Remove(CurrentSessionKey);
              }


              
      public static void CloseSessionFactory()
              
      {
                  
      if (sessionFactory != null)
                  
      {
                      sessionFactory.Close();
                  }

              }

          }


      }


      用dottrace跟蹤結果為:

      從執行時間來看
          System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                  sw.Start();
                  ISession session 
      = NHibernateHelper.GetCurrentSession();
                  session.Close();
                  sw.Stop();
                  Response.Write(sw.ElapsedTicks
      +"<br>");
                  sw.Reset();
                  sw.Start();
                  session 
      = NHibernateHelper.GetCurrentSession();
                  session.Close();
                  sw.Stop();
                  Response.Write(sw.ElapsedTicks 
      + "<br>");
                  sw.Reset();
                  sw.Start();
                  session 
      = NHibernateHelper.GetCurrentSession();
                  session.Close();
                  sw.Stop();
                  Response.Write(sw.ElapsedTicks 
      + "<br>");
      執行結果為:


      posted @ 2007-04-01 17:11  Robin Zhang  閱讀(5394)  評論(4)    收藏  舉報
      主站蜘蛛池模板: 日本高清一区免费中文视频| 99久久婷婷国产综合精品青草漫画| 四虎永久免费很黄的视频| 国产特色一区二区三区视频 | 成人国产精品免费网站| 99久久久国产精品免费无卡顿| 亚洲青青草视频在线播放| 国产果冻豆传媒麻婆精东 | 蜜桃av多人一区二区三区| 日本三级理论久久人妻电影| 国产不卡一区不卡二区| 东京热无码国产精品| 永久国产盗摄一区二区色欲| 久操热在线视频免费观看| 亚欧美闷骚院| 四虎国产精品免费久久| 沾化县| 久久亚洲av成人一二三区| 在线精品国产中文字幕| 国产成人无码A区在线观| 色av专区无码影音先锋| 一个色的导航| 2020国产欧洲精品网站| 亚洲中文字幕av无码区| 大香蕉av一区二区三区| 男女激情一区二区三区| 又大又黄又粗高潮免费| 国产成人亚洲精品成人区| 男女18禁啪啪无遮挡激烈网站| 国产日韩综合av在线| 成人免费精品网站在线观看影片| 欧美成人精品手机在线| 日韩在线一区二区每天更新| 日日猛噜噜狠狠扒开双腿小说| 久久无码中文字幕免费影院蜜桃| 迁安市| 四虎网址| 日韩亚洲国产综合高清| 内射中出无码护士在线| 国产精品午夜福利91| 国产午夜精品一区二区三区不卡|