成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

單數據庫vs多數據庫,單實例vs多實例 效率測試

運維 數據庫運維 SQL Server
目前壓力測試發現數據庫服務器壓力還不夠大,Web服務器壓力也不是很大的情況下,前臺頁面訪問卻很慢,看有沒有辦法充分利用數據庫服務器的性能,于是做了一個單數據庫,多數據庫,單實例,多實例不同情況下的數據訪問效率測試。

最近公司的項目準備優化一下系統的性能,希望在數據庫方面看有沒有提升的空間,目前壓力測試發現數據庫服務器壓力還不夠大,Web服務器壓力也不是很大的情況下,前臺頁面訪問卻很慢,看有沒有辦法充分利用數據庫服務器的性能,于是做了一個單數據庫,多數據庫,單實例,多實例不同情況下的數據訪問效率測試。

測試環境:

  • CPU:Inter Core2 Quad,Q8300,2.50GHz;
  • 內存:4.00GB
  • 系統:Windows 7 32位系統
  • 數據庫系統:SqlServer 2008,有兩個實例,一個是默認實例,一個是命名實例QE2 

測試數據:

67萬真實的基金收益數據,將這個表的數據放到了3個數據庫中,詳細內容見下面的連接字符串配置:

  1. <add name ="Ins1_DB1" connectionString ="Data Source=.;Initial Catalog=TestDB;Integrated Security=True"/>  
  2. <add name ="Ins1_DB2" connectionString ="Data Source=.;Initial Catalog=LocalDB;Integrated Security=True"/>  
  3. <add name ="Ins2_DB" connectionString ="Data Source=.\QE2;Initial Catalog=TestDB;Integrated Security=True"/>  

測試內容:

首先篩選出表中所有的基金代碼,然后統計每只基金的最新收益率日期,對應的T-SQL代碼如下:

  1.   declare @max_fsrq datetime  
  2.   declare @currJJDM varchar(10)  
  3.   declare @temp table (jjdm2 varchar(10))  
  4.   declare @useTime datetime  
  5.   set @useTime =GETDATE ();  
  6.     
  7.   insert into @temp(jjdm2)  
  8.    select jjdm from [FundYield] group by jjdm order by jjdm asc 
  9.      
  10.   while EXISTS (select jjdm2 from @temp)  
  11.   begin 
  12.     set @currJJDM=(select top 1 jjdm2 from @temp)  
  13.     select @max_fsrq = MAX(fsrq) from [FundYield] where jjdm=@currJJDM  
  14.     delete from @temp where jjdm2 =@currJJDM   
  15.     print @max_fsrq  
  16.   end 
  17.     
  18.  
  19. print 'T-SQL Execute Times(ms):'    
  20.  print datediff(ms,@useTime,getdate())  

直接執行這個T-SQL腳本,在數據庫表沒有索引的情況下,耗費的時間是: 

  1. T-SQL Execute Times(ms):  
  2. 58796 

根據這個功能,寫了一個.net控制臺程序來測試,測試程序沒有使用任何數據訪問框架,直接使用ADO.NET,下面是多線程測試的代碼,其它代碼略:

  1. public static void Test2(string connName1,string connName2)  
  2.        {  
  3.            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();  
  4.            watch.Start();  
  5.            string allJjdmList = "";  
  6.            string connString = getConnectionString();  
  7.            //SqlConnection conn = new SqlConnection(connString);  
  8.            //conn.Open();  
  9.  
  10.            string sql = "select jjdm from [FundYield] group by jjdm order by jjdm asc";  
  11.            DataSet ds = getData(connString, sql);  
  12.            int allCount = ds.Tables[0].Rows.Count;  
  13.            int p = (int)(allCount * 0.5);  
  14.  
  15.            System.Threading.Thread t1=new System.Threading.Thread (new System.Threading.ParameterizedThreadStart (tp1=>  
  16.                {  
  17.                    for (int i = 0; i < p; i++)  
  18.                    {  
  19.                        string jjdm = ds.Tables[0].Rows[i][0].ToString();  
  20.  
  21.                        object result = getSclar(ConfigurationManager.ConnectionStrings[connName1].ConnectionString,  
  22.                       string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));  
  23.                        if (result != DBNull.Value)  
  24.                        {  
  25.                            DateTime dt = Convert.ToDateTime(result);  
  26.                            //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);  
  27.                        }  
  28.  
  29.                        allJjdmList = allJjdmList + "," + jjdm;  
  30.                    }  
  31.  
  32.                    Console.WriteLine("Tread 1 used all time is(ms):{0}", watch.ElapsedMilliseconds);  
  33.                }  
  34.            ));  
  35.  
  36.            System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(tp2 =>  
  37.            {  
  38.                for (int i = p; i < allCount; i++)  
  39.                {  
  40.                    string jjdm = ds.Tables[0].Rows[i][0].ToString();  
  41.                    //這里不論使用default還是express,區別不大  
  42.                    object result = getSclar(ConfigurationManager.ConnectionStrings[connName2].ConnectionString,  
  43.                        string.Format("select MAX(fsrq) from [FundYield] where jjdm='{0}'", jjdm));  
  44.                    if (result != DBNull.Value)  
  45.                    {  
  46.                        DateTime dt = Convert.ToDateTime(result);  
  47.                        //Console.WriteLine("Thread 2 No {0} ,jjdm[{1}] last FSRQ is:{2}", i, jjdm, dt);  
  48.                    }  
  49.                      
  50.                    allJjdmList = allJjdmList + "," + jjdm;  
  51.                }  
  52.  
  53.                Console.WriteLine("Tread 2 used all time is(ms):{0}", watch.ElapsedMilliseconds);  
  54.            }  
  55.            ));  
  56.  
  57.            t1.Start();  
  58.            t2.Start();  
  59.            t1.Join();  
  60.            t2.Join();  
  61.  
  62.            Console.WriteLine("====All thread completed!========");  
  63.  
  64.        } 

#p#

下面是測試結果:

第一次,數據庫沒有創建索引,進行全表掃描:

  1. ------單數據庫,單線程測試---------  
  2. used all time is(ms):59916  
  3. ------同一實例,雙數據庫,單線程測試---------  
  4. used all time is(ms):59150  
  5. ------同一實例,雙數據庫,多線程測試---------  
  6. Tread 2 used all time is(ms):51223  
  7. Tread 1 used all time is(ms):58175  
  8. ====All thread completed!========  
  9. ------雙實例,雙數據庫,單線程測試---------  
  10. used all time is(ms):58230  
  11. ------雙實例,雙數據庫,多線程測試---------  
  12. Tread 2 used all time is(ms):52705  
  13. Tread 1 used all time is(ms):58293  
  14. ====All thread completed!======== 

第二次,數據庫響應的字段創建索引,下面是測試結果:

  1. ------單數據庫,單線程測試---------  
  2. used all time is(ms):1721  
  3. ------同一實例,雙數據庫,單線程測試---------  
  4. used all time is(ms):1737  
  5. ------同一實例,雙數據庫,多線程測試---------  
  6. Tread 2 used all time is(ms):1684  
  7. Tread 1 used all time is(ms):1714  
  8. ====All thread completed!========  
  9. ------雙實例,雙數據庫,單線程測試---------  
  10. used all time is(ms):1874  
  11.  
  12.  
  13. ------單數據庫,單線程測試---------  
  14. used all time is(ms):1699  
  15. ------同一實例,雙數據庫,單線程測試---------  
  16. used all time is(ms):1754  
  17. ------同一實例,雙數據庫,多線程測試---------  
  18. Tread 1 used all time is(ms):1043  
  19. Tread 2 used all time is(ms):1103  
  20. ====All thread completed!========  
  21. ------雙實例,雙數據庫,單線程測試---------  
  22. used all time is(ms):1838  
  23. ------雙實例,雙數據庫,多線程測試---------  
  24. Tread 1 used all time is(ms):1072  
  25. Tread 2 used all time is(ms):1139  
  26. ====All thread completed!======== 

測試結論:

綜合全表掃描訪問和有索引方式的訪問,

單線程訪問:

  • 在同一個數據庫實例上,雙數據庫沒有體現出優勢,甚至單數據庫稍微優勝于多數據庫;
  • 在兩個數據庫實例上,雙實例雙實例要落后于單實例單數據庫;

多線程訪問:

  • 雙數據庫實例稍微落后于單數據庫實例;

綜合結論,看來不論是雙數據庫還是雙實例,對比與單實例或者單數據庫,都沒有體現出優勢,看來前者的優勢不在于訪問效率,一位朋友說,數據庫實例是不同的服務,控制粒度更小,維護影響比較低。但我想,雙數據庫實例,雙數據庫,多核CPU,應該跟兩臺數據庫服務器差不多的性能吧,怎么沒有體現優勢呢?也許是我的測試機器僅僅有一個磁盤,這里磁盤IO成了瓶頸。

這個測試有沒有意義,或者這個結果的原因,還請大牛們多多指教!

意外發現:

1,有人說頻繁的查詢在完全數據庫中進行效率最高,測試發現,在查詢分析器上直接運行上面的那個T-SQL腳本,跟程序從數據庫取出數據,再加工計算查詢,效率上沒有明顯的區別,所以哪些支持“將復雜的業務邏輯寫在存儲過程中效率最高的觀點是站不住腳的!”  ,ADO.NET從數據庫來回操作數據一樣有效率,如果加上復雜的字符函數計算和大批量的循環操作,存儲過程的效率不一定高。

2,在使用程序進行頻繁的數據庫操作的時候,使用一個連接對象還是在每個方法中使用新的連接對象,一直是很糾結的問題,心想頻繁的數據操作還是用一個連接對象快吧?在本文給出的測試代碼中,有下列語句:

  1. //SqlConnection conn = new SqlConnection(connString);  
  2.             //conn.Open(); 

注釋掉這些語句,在被調用的方法中使用自己的連接對象,與取消注釋,全部使用一個連接對象,效率上沒有任何區別!

究其原因,可能是ADO.NET自動使用了連接池,實際上程序在不同的情況下,使用的都是一個連接,所以操作上效率沒有區別。

后續測試

在真正的服務器上進行測試,發現測試結論又不一樣,我們有服務器A,擁有16個核,32G內存,另外一臺服務器B,擁有8個核,16G內存。在服務器A上有一個SqlServer實例,兩個一樣的數據庫;在在服務器B上有一個SqlServer實例,一個數據庫,下面是測試結果:

  1. ------單數據庫,單線程測試---------  
  2. used all time is(ms):650  
  3. ------同一實例,雙數據庫,單線程測試---------  
  4. used all time is(ms):418  
  5. ------同一實例,雙數據庫,多線程測試---------  
  6. Tread 2 used all time is(ms):221  
  7. Tread 1 used all time is(ms):223  
  8. ====All thread completed!========  
  9. ------雙實例,雙數據庫,單線程測試---------  
  10. used all time is(ms):1283  
  11. ------雙實例,雙數據庫,多線程測試---------  
  12. Tread 1 used all time is(ms):228  
  13. Tread 2 used all time is(ms):542  
  14. ====All thread completed!======== 

可以看到,同一實例,多數據庫,還是有明顯的優勢,而多線程優勢更大;由于兩臺服務器性能差距較大,雙實例測試沒有顯示出優勢,但多線程下還是比單實例單數據庫好!

為什么PC機跟服務器測試的結論不一致?也許還是跟計算能力相關,PC機的計算負載太大,已經失去了測試的意義。

原文鏈接:http://www.cnblogs.com/bluedoctor/archive/2011/06/28/2092113.html

【編輯推薦】

  1. 說說Top子句對查詢計劃的影響
  2. SQL Server復災 你懂了嗎?
  3. SQL Server管理 這些你懂嗎?
  4. 手把手教你建立SQL數據庫的表分區
  5. 如何設計合理的多表關聯的表分區
責任編輯:艾婧 來源: 博客園
相關推薦

2011-08-04 09:08:09

Vertica多數據庫實例端口

2019-10-12 16:15:13

MySQL數據庫多實例

2020-11-19 07:11:13

數據庫專用數據庫多模數據庫

2011-04-01 12:58:46

ASPACCESS數據庫

2010-11-29 11:47:26

連接Sybase數據庫

2010-04-01 09:45:38

NoSQL

2011-06-21 15:11:04

QT 數據庫

2011-05-19 13:25:14

Oracle數據庫

2011-07-05 10:16:16

Qt 數據庫 SQLite

2021-09-09 09:28:08

面向列數據庫面向行

2010-04-06 11:30:09

Oracle 數據庫

2010-04-13 10:55:35

Oracle數據庫

2010-05-12 18:41:34

MySQL數據庫

2011-03-29 10:47:49

ORACLE數據庫

2011-07-05 14:46:34

2011-03-07 09:52:49

PSQL MySQL 開源數據庫

2011-08-02 16:08:52

NoSQLMongoDBCassandra

2021-02-17 13:52:35

數據庫group byMySQL

2010-04-14 15:45:49

Oracle 數據庫

2010-06-09 17:36:45

MySQL數據庫同步
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 九九精品在线 | 在线中文字幕亚洲 | 免费看一区二区三区 | 91视频观看 | 永久免费av| 欧美乱大交xxxxx另类电影 | 亚洲大片一区 | 一区二区三区视频 | 久久久精品 | www.久久| 国产黑丝av | 亚洲美女网站 | 日本中出视频 | 亚洲v区 | 精品久久久久久中文字幕 | 免费观看一级特黄欧美大片 | 久久毛片 | 国产第一页在线观看 | 国产韩国精品一区二区三区 | 国产一区二区三区网站 | 精品国产一区二区三区四区在线 | 色婷婷影院| 人人人人爽 | 亚洲社区在线 | 成人精品视频在线观看 | 国产精品日韩一区二区 | 成人免费观看视频 | 国产一区二区久久久 | 久久伊人亚洲 | 欧产日产国产精品视频 | 香蕉一区二区 | 亚洲成人午夜在线 | 91欧美激情一区二区三区成人 | 欧美色影院 | 精品一区二区三区在线播放 | 国产精品免费高清 | 亚洲天堂中文字幕 | 日本不卡一区二区 | 在线观看三级av | 欧美一级观看 | a毛片|