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

單數(shù)據(jù)庫vs多數(shù)據(jù)庫,單實(shí)例vs多實(shí)例 效率測(cè)試

運(yùn)維 數(shù)據(jù)庫運(yùn)維 SQL Server
目前壓力測(cè)試發(fā)現(xiàn)數(shù)據(jù)庫服務(wù)器壓力還不夠大,Web服務(wù)器壓力也不是很大的情況下,前臺(tái)頁面訪問卻很慢,看有沒有辦法充分利用數(shù)據(jù)庫服務(wù)器的性能,于是做了一個(gè)單數(shù)據(jù)庫,多數(shù)據(jù)庫,單實(shí)例,多實(shí)例不同情況下的數(shù)據(jù)訪問效率測(cè)試。

最近公司的項(xiàng)目準(zhǔn)備優(yōu)化一下系統(tǒng)的性能,希望在數(shù)據(jù)庫方面看有沒有提升的空間,目前壓力測(cè)試發(fā)現(xiàn)數(shù)據(jù)庫服務(wù)器壓力還不夠大,Web服務(wù)器壓力也不是很大的情況下,前臺(tái)頁面訪問卻很慢,看有沒有辦法充分利用數(shù)據(jù)庫服務(wù)器的性能,于是做了一個(gè)單數(shù)據(jù)庫,多數(shù)據(jù)庫,單實(shí)例,多實(shí)例不同情況下的數(shù)據(jù)訪問效率測(cè)試。

測(cè)試環(huán)境:

  • CPU:Inter Core2 Quad,Q8300,2.50GHz;
  • 內(nèi)存:4.00GB
  • 系統(tǒng):Windows 7 32位系統(tǒng)
  • 數(shù)據(jù)庫系統(tǒng):SqlServer 2008,有兩個(gè)實(shí)例,一個(gè)是默認(rèn)實(shí)例,一個(gè)是命名實(shí)例QE2 

測(cè)試數(shù)據(jù):

67萬真實(shí)的基金收益數(shù)據(jù),將這個(gè)表的數(shù)據(jù)放到了3個(gè)數(shù)據(jù)庫中,詳細(xì)內(nèi)容見下面的連接字符串配置:

  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"/>  

測(cè)試內(nèi)容:

首先篩選出表中所有的基金代碼,然后統(tǒng)計(jì)每只基金的最新收益率日期,對(duì)應(yīng)的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())  

直接執(zhí)行這個(gè)T-SQL腳本,在數(shù)據(jù)庫表沒有索引的情況下,耗費(fèi)的時(shí)間是: 

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

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

  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,區(qū)別不大  
  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#

下面是測(cè)試結(jié)果:

第一次,數(shù)據(jù)庫沒有創(chuàng)建索引,進(jìn)行全表掃描:

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

第二次,數(shù)據(jù)庫響應(yīng)的字段創(chuàng)建索引,下面是測(cè)試結(jié)果:

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

測(cè)試結(jié)論:

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

單線程訪問:

  • 在同一個(gè)數(shù)據(jù)庫實(shí)例上,雙數(shù)據(jù)庫沒有體現(xiàn)出優(yōu)勢(shì),甚至單數(shù)據(jù)庫稍微優(yōu)勝于多數(shù)據(jù)庫;
  • 在兩個(gè)數(shù)據(jù)庫實(shí)例上,雙實(shí)例雙實(shí)例要落后于單實(shí)例單數(shù)據(jù)庫;

多線程訪問:

  • 雙數(shù)據(jù)庫實(shí)例稍微落后于單數(shù)據(jù)庫實(shí)例;

綜合結(jié)論,看來不論是雙數(shù)據(jù)庫還是雙實(shí)例,對(duì)比與單實(shí)例或者單數(shù)據(jù)庫,都沒有體現(xiàn)出優(yōu)勢(shì),看來前者的優(yōu)勢(shì)不在于訪問效率,一位朋友說,數(shù)據(jù)庫實(shí)例是不同的服務(wù),控制粒度更小,維護(hù)影響比較低。但我想,雙數(shù)據(jù)庫實(shí)例,雙數(shù)據(jù)庫,多核CPU,應(yīng)該跟兩臺(tái)數(shù)據(jù)庫服務(wù)器差不多的性能吧,怎么沒有體現(xiàn)優(yōu)勢(shì)呢?也許是我的測(cè)試機(jī)器僅僅有一個(gè)磁盤,這里磁盤IO成了瓶頸。

這個(gè)測(cè)試有沒有意義,或者這個(gè)結(jié)果的原因,還請(qǐng)大牛們多多指教!

意外發(fā)現(xiàn):

1,有人說頻繁的查詢?cè)谕耆珨?shù)據(jù)庫中進(jìn)行效率最高,測(cè)試發(fā)現(xiàn),在查詢分析器上直接運(yùn)行上面的那個(gè)T-SQL腳本,跟程序從數(shù)據(jù)庫取出數(shù)據(jù),再加工計(jì)算查詢,效率上沒有明顯的區(qū)別,所以哪些支持“將復(fù)雜的業(yè)務(wù)邏輯寫在存儲(chǔ)過程中效率最高的觀點(diǎn)是站不住腳的!”  ,ADO.NET從數(shù)據(jù)庫來回操作數(shù)據(jù)一樣有效率,如果加上復(fù)雜的字符函數(shù)計(jì)算和大批量的循環(huán)操作,存儲(chǔ)過程的效率不一定高。

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

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

注釋掉這些語句,在被調(diào)用的方法中使用自己的連接對(duì)象,與取消注釋,全部使用一個(gè)連接對(duì)象,效率上沒有任何區(qū)別!

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

后續(xù)測(cè)試

在真正的服務(wù)器上進(jìn)行測(cè)試,發(fā)現(xiàn)測(cè)試結(jié)論又不一樣,我們有服務(wù)器A,擁有16個(gè)核,32G內(nèi)存,另外一臺(tái)服務(wù)器B,擁有8個(gè)核,16G內(nèi)存。在服務(wù)器A上有一個(gè)SqlServer實(shí)例,兩個(gè)一樣的數(shù)據(jù)庫;在在服務(wù)器B上有一個(gè)SqlServer實(shí)例,一個(gè)數(shù)據(jù)庫,下面是測(cè)試結(jié)果:

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

可以看到,同一實(shí)例,多數(shù)據(jù)庫,還是有明顯的優(yōu)勢(shì),而多線程優(yōu)勢(shì)更大;由于兩臺(tái)服務(wù)器性能差距較大,雙實(shí)例測(cè)試沒有顯示出優(yōu)勢(shì),但多線程下還是比單實(shí)例單數(shù)據(jù)庫好!

為什么PC機(jī)跟服務(wù)器測(cè)試的結(jié)論不一致?也許還是跟計(jì)算能力相關(guān),PC機(jī)的計(jì)算負(fù)載太大,已經(jīng)失去了測(cè)試的意義。

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

【編輯推薦】

  1. 說說Top子句對(duì)查詢計(jì)劃的影響
  2. SQL Server復(fù)災(zāi) 你懂了嗎?
  3. SQL Server管理 這些你懂嗎?
  4. 手把手教你建立SQL數(shù)據(jù)庫的表分區(qū)
  5. 如何設(shè)計(jì)合理的多表關(guān)聯(lián)的表分區(qū)
責(zé)任編輯:艾婧 來源: 博客園
相關(guān)推薦

2011-08-04 09:08:09

Vertica多數(shù)據(jù)庫實(shí)例端口

2019-10-12 16:15:13

MySQL數(shù)據(jù)庫多實(shí)例

2020-11-19 07:11:13

數(shù)據(jù)庫專用數(shù)據(jù)庫多模數(shù)據(jù)庫

2011-04-01 12:58:46

ASPACCESS數(shù)據(jù)庫

2010-11-29 11:47:26

連接Sybase數(shù)據(jù)庫

2010-04-01 09:45:38

NoSQL

2011-05-19 13:25:14

Oracle數(shù)據(jù)庫

2011-06-21 15:11:04

QT 數(shù)據(jù)庫

2021-09-09 09:28:08

面向列數(shù)據(jù)庫面向行

2011-07-05 10:16:16

Qt 數(shù)據(jù)庫 SQLite

2010-04-06 11:30:09

Oracle 數(shù)據(jù)庫

2010-05-12 18:41:34

MySQL數(shù)據(jù)庫

2011-03-29 10:47:49

ORACLE數(shù)據(jù)庫

2011-07-05 14:46:34

2010-04-13 10:55:35

Oracle數(shù)據(jù)庫

2021-02-17 13:52:35

數(shù)據(jù)庫group byMySQL

2010-06-09 17:36:45

MySQL數(shù)據(jù)庫同步

2011-07-05 16:08:10

2011-07-12 16:41:14

mysql處理異常

2011-06-27 13:49:43

Qt 數(shù)據(jù)庫 QSqlQueryM
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 欧美一区二区三区高清视频 | 天天操天天干天天透 | 激情91 | 亚洲人成在线播放 | 热久久999| 中文字幕男人的天堂 | 日韩精品在线播放 | 国产成人免费视频网站视频社区 | 久久人体 | 激情一区二区三区 | 国产97在线视频 | 一级片免费视频 | 亚洲国产一区二区三区, | 亚洲视频在线观看一区二区三区 | 国产精品成人一区二区三区 | 伊人狼人影院 | 夜久久 | 国产成人免费视频网站视频社区 | 日本免费一区二区三区视频 | 久久在线视频 | 污书屋 | 国产黄色一级电影 | 亚洲精品久久久久久一区二区 | 午夜av电影| 天堂久久久久久久 | 国产精品亚洲一区二区三区在线观看 | 97精品超碰一区二区三区 | 久久精品中文字幕 | 一区在线观看 | 中文字幕日韩欧美一区二区三区 | 免费一级黄 | 99久久久久久 | 四虎影院美女 | 日韩电影中文字幕 | 男人av的天堂 | 黄a免费网络 | 日韩在线资源 | 91久久精品视频 | 99久久婷婷国产综合精品电影 | 久久久精品一区二区三区 | 国产精品日韩一区二区 |