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缓冲池的发费要少得差不多三倍。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值