Sybase數據庫中數據高速緩存配置詳解

主要配置存儲過程sp_cacheconfig
語法:sp_cacheconfig cache_name, "size[P|K|M|G]" [,mixed|logonly] [,strict|relaxed] [,"cache_partition=[1|2|4|8|16|32|64]"]
緩存大小最小爲512K
緩衝池大小分爲三種:2K,4K,16K
緩存使用功能上分爲:缺省數據高速緩存(2K,16K),User_Table_Cache(2K,16K),Log_Cache(2K,4Kw)
常用的命令:
sp_cacheconfig 創建或刪除命名緩衝區,改變緩衝區的大小或類型
sp_poolconfig 創建或刪除I/O緩衝池,並改變其大小
sp_bindcache 將數據庫或數據庫對象捆綁到緩衝區
sp_unbindcache 從一個緩衝區中取消對指定對象或數據庫的捆綁
sp_unbindcache_all 從一個緩衝區中取消所有對象的捆綁
sp_helpcache 報告有關數據緩衝區的小結信息,並顯示捆綁於緩衝區的數據庫和對象
sp_cachestrategy 報告有關爲表,索引設置的緩衝區策略,禁止或重新允許先提或M
SYBASE內存和緩衝區管理(rekcah0):
sp_logiosize 爲日誌改變默認的I/O大小
sp_spaceused 估計表和索引大小或有關數據庫使用的空間量的信息
sp_estspace 估計表和索引的大小,給出表包含的行的數目
sp_help 報告表將捆綁於哪個緩衝區
sp_helpindex 報告索引將捆綁於哪個緩衝區
sp_helpdb 報告數據庫將捆綁於哪個緩衝區
setshowplanon 報告有關用於查詢的I/O大小和緩衝區的應用策略
setstatisticsioon 報告爲查詢進行的讀操作數量
setprefetch on/off 允許或禁止某個會話的預先提取


具體配置操作:
給默認高速緩存配置緩存大小:sp_cacheconfig "default data cache","20M"
分配緩衝池,默認是分配在2K緩衝池:sp_poolconfig "default data cache" , "10M","16K"
創建新的高速緩存並分配大小,缺省爲mixed:sp_cacheconfig "test_data_cache","8M"
16K緩衝池清洗區配置:sp_poolconfig "test_data_cache" ,"16K" , "wash=720K"


set fmtonly off
sp_cacheconfig查看緩存信息:
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
default data cache             Active    Default      20.00 Mb     20.00 Mb
test_data_cache                     Active    Mixed         8.00 Mb      8.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb   2048 Kb      0.00 Mb     10.00 Mb     10     
   16 Kb   2048 Kb     10.00 Mb     10.00 Mb     10     


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb   1638 Kb      0.00 Mb      8.00 Mb     10  
其中Type有三種值:Default,Mixed,Logonly


分配3M給4K緩衝池:sp_poolconfig "test_data_cache","3M","4K"
分配3M給16K緩衝池:sp_poolconfig "test_data_cache","3M","16K"
sp_cacheconfig "test_data_cache" 查看緩存信息:
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
test_data_cache                     Active    Mixed         8.00 Mb      8.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb    408 Kb      0.00 Mb      2.00 Mb     10     
    4 Kb    612 Kb      3.00 Mb      3.00 Mb     10     
   16 Kb    608 Kb      3.00 Mb      3.00 Mb     10
  
清除4K緩衝池分配的空間:sp_poolconfig "test_data_cache", "0", "4K"
sp_cacheconfig "test_data_cache" 查看緩存信息:
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
test_data_cache                Active    Mixed         8.00 Mb      8.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb   1024 Kb      0.00 Mb      5.00 Mb     10     
   16 Kb    608 Kb      3.00 Mb      3.00 Mb     10 
  
清除16K緩衝池分配的空間:sp_poolconfig "test_data_cache", "0", "16K"
sp_cacheconfig "test_data_cache" 查看緩存信息:
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
test_data_cache                Active    Mixed         8.00 Mb      8.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb   1638 Kb      0.00 Mb      8.00 Mb     10     


清除2K緩衝池分配的空間不可行的,默認的清除不掉,而刪除test_data_cache高速緩存可用命令:
sp_cacheconfig "test_data_cache","0"
再用sp_cacheconfig查看時沒有test_data_cache高速緩存了。      


創建新的日誌高速緩存並分配大小:sp_cacheconfig "test_log_cache","6M",logonly
日誌緩存大小不能大於最大內存大小,否則報錯:
Server Message:  Number  5861, Severity  16
Procedure 'sp_cacheconfig', Line 1087:
The current 'max memory' value '33792', is not sufficient to change the parameter 'User Defined Cache' to '0'. 'max memory' should be greater than 'total logical memory' '34987' required for the configuration.
用sp_cacheconfig "test_log_cache" 查看緩存信息:
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
test_log_cache                 Active    Log Only      6.00 Mb      6.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb   1228 Kb      0.00 Mb      6.00 Mb     10     




將數據庫或數據庫對象捆綁到緩衝區:
sp_bindcache 可以將數據庫,表,索引,text對象或Image對象綁定到數據緩存。只有系統管理員才能執行。
sp_bindcache "test_data_cache" , "dbname"
解除綁定在Master庫中執行:sp_unbindcache "test_data_cache" , "dbname"
查看緩存綁定信息:sp_helpcache
Cache Name                Config Size     Run Size       Overhead
------------------------ -------------   ----------     ----------  
The sort for Worktable1 is done in Serial  
default data cache         20.00 Mb       20.00 Mb        1.48 Mb
test_data_cache            10.00 Mb       10.00 Mb        0.75 Mb


Memory Available For      Memory Configured
Named Caches              To Named Caches
--------------------       ----------------
  30.01 Mb                    30.00 Mb


------------------ Cache Binding Information: ------------------


Cache Name           Entity Name                Type               Index Name                    Status
----------           -----------                ----               ----------                    ------
test_data_cache      dbname                     database                                           V
其中,Status爲V——有效,爲I——無效


一般情況下,將高速緩存空間分配部分給16K緩衝池,在執行SQL時在速度上得到很大提升。在事務密集型環境中,事務日誌配置4K緩衝池時性能最佳。


查看日誌高速緩存的日誌IO大小:值可以爲2,4,8,16K
sp_logiosize
The transaction log for database 'DBNAME' will use I/O size of 2 Kbytes.


改爲16K的日誌IO大小:sp_logiosize "16"
Log I/O size is set to 16 Kbytes.
The transaction log for database 'DBNAME' will use I/O size of 16 Kbytes.




數據高速緩存查詢比較:
在兩個ASE 12.5.4版本數據庫Sybase-A和Sybase-B下測試select count(*) from table1記錄條數爲6859650
set showplan on
set fmtonly off
sp_cacheconfig
--Sybase-A
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
default data cache             Active    Default    1500.00 Mb   1500.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb 122880 Kb      0.00 Mb   1500.00 Mb     10     




--Sybase-B
Cache Name                     Status    Type     Config Value Run Value   
----------                     ------    ----     ------------ ---------   
default data cache             Active    Default     900.00 Mb    900.00 Mb


IO Size  Wash Size Config Size  Run Size     APF Percent
-------  --------- -----------  --------     -----------
    2 Kb 143360 Kb      0.00 Mb    700.00 Mb     10     
   16 Kb  40960 Kb    200.00 Mb    200.00 Mb     10     


--Sybase-A
set showplan on
set statistics io on
set statistics time on
select count(*) from  table1


Using I/O Size 2 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.


第一次執行:
Parse and Compile Time 0.
SQL Server cpu time: 0 ms.
Table: table1 scan count 1, logical reads: (regular=20688 apf=0 total=20688), physical reads: (regular=20183 apf=482 total=20665), apf IOs used=479
Total writes for this command: 36


Execution Time 51.
SQL Server cpu time: 5100 ms.  SQL Server elapsed time: 4373 ms.
(1 row affected)


第二次執行:
Parse and Compile Time 0.
SQL Server cpu time: 0 ms.
Table: table1 scan count 1, logical reads: (regular=20688 apf=0 total=20688), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0


Execution Time 38.
SQL Server cpu time: 3800 ms.  SQL Server elapsed time: 3300 ms.
(1 row affected)


--Sybase-B
set showplan on
set statistics io on
set statistics time on
select count(*) from  table1


Using I/O Size 16 Kbytes for index leaf pages.
With LRU Buffer Replacement Strategy for index leaf pages.


第一次執行:
Parse and Compile Time 0.
SQL Server cpu time: 0 ms.
Table: table1 scan count 1, logical reads: (regular=30248 apf=0 total=30248), physical reads: (regular=6017 apf=0 total=6017), apf IOs used=0
Total writes for this command: 0


Execution Time 14.
SQL Server cpu time: 1400 ms.  SQL Server elapsed time: 1416 ms.
(1 row affected)
第二次執行:
Parse and Compile Time 0.
SQL Server cpu time: 0 ms.
Table: table1 scan count 1, logical reads: (regular=30248 apf=0 total=30248), physical reads: (regular=0 apf=0 total=0), apf IOs used=0
Total writes for this command: 0


Execution Time 10.
SQL Server cpu time: 1000 ms.  SQL Server elapsed time: 1076 ms.
(1 row affected)


可以看出:兩庫使用的緩衝池大小不一樣,高速緩存替換策略都LRU(最先使用),配置16K的緩衝池大小的在第一次執行時physical reads次數比2K的要少一倍以上,而logical reads次數比2K的要多一些,但總體查詢時間16K緩衝池的發費要少得差不多三倍。

 

 

 

https://blog.csdn.net/huranxiong/article/details/9175129

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章