lgwr的两种模式(post/wait和polling)

11.2之前,oracle的lgwr写入模式为post/wait

11.2之后新增了polling模式,可以与post/wait模式自动切换

通过隐藏参数 _use_adaptive_log_file_sync 参数来控制

查看该隐藏参数的方法:

select x.ksppinm name, y.ksppstvl value, x.ksppdesc describ
  from sys.x$ksppi x, sys.x$ksppcv y
where x.indx = y.indx
  and x.ksppinm like '%_use_adaptive_log_file_sync%';

当参数设置为false时,lgwr还是采用post/wait方式将日志从buffer写入磁盘

当参数设置为true是,lgwr写入方式会自动在post/wait和polling模式之间进行切换,可能会造成比较严重的log file sync (当使用polling模式时)

建议关闭此参数:

alter system set “_use_adaptive_log_file_sync”=false;

 

模式切换时,lgwr的trace中会记录类似如下的信息:

racdb1_lgwr_27890.trc-6094-warning: log write elapsed time 649ms, size 11252kb racdb1_lgwr_27890.trc-6095- racdb1_lgwr_27890.trc-6096-*** 2016-05-10 13:28:41.481 racdb1_lgwr_27890.trc-6097-warning: log write elapsed time 654ms, size 16877kb racdb1_lgwr_27890.trc:6098:kcrfw_update_adaptive_sync_mode: post->poll long#=2 sync#=9 sync=1031 poll=1961 rw=574 ack=0 min_sleep=1961 — racdb1_lgwr_27890.trc-6115-warning: log write elapsed time 532ms, size 16479kb racdb1_lgwr_27890.trc-6116- racdb1_lgwr_27890.trc-6117-*** 2016-05-10 18:22:14.255 racdb1_lgwr_27890.trc-6118-warning: log write elapsed time 781ms, size 316kb racdb1_lgwr_27890.trc:6119:kcrfw_update_adaptive_sync_mode: poll->post current_sched_delay=0 switch_sched_delay=1 current_sync_count_delta=2 switch_sync_count_delta=9 — racdb1_lgwr_27890.trc-6168-warning: log write elapsed time 855ms, size 9153kb racdb1_lgwr_27890.trc-6169- racdb1_lgwr_27890.trc-6170-*** 2016-05-11 06:29:28.814 racdb1_lgwr_27890.trc-6171-warning: log write elapsed time 568ms, size 10345kb racdb1_lgwr_27890.trc:6172:kcrfw_update_adaptive_sync_mode: post->poll long#=2 sync#=7 sync=964 poll=1961 rw=969 ack=0 min_sleep=1961

 

 

两种模式的理解:(两种模式主体都是前台进程,post/wait是等待lgwr通知,polling是主动轮序lgwr)

post/wait:用户会话被动等待lgwr通知redo写入到log file完毕,这种方式响应速度比较快。若cpu空闲时采用这种方式可以体验到更好的响应时间。
polling:用户会话主动轮询lgwr,观测是否完成写入(轮询的间隔是10ms)。这种方式比post/wait方式响应速度慢,但lgwr不直接把完成的消息通知到很多用户会话,可以节约cpu资源。若cpu繁忙时采用这种方式可以降低cpu资源的消耗。

 

官方对两种模式的解释:

adaptive log file sync was introduced in 11.2. the feature is exactly enabled since release 11.2.0.3 , it’s enabled through an underscore parameter called _use_adaptive_log_file_sync and the description of this parameter is: adaptively switch between post/wait and polling.

oracle can switches between the 2 methods:
post/wait, traditional method for posting completion of writes to redo log

lgwr explicitly posts all processes waiting for the commit to complete.

the advantage of the post/wait method is that sessions should find out almost immediately when the redo has been flushed to disk.

polling, a new method where the foreground process checks if the lgwr has completed the write.

foreground processes sleep and poll to see if the commit is complete. the advantage of this new method is to free lgwr from having to inform many processes waiting on commit to complete thereby freeing high cpu usage by the lgwr.if post/wait is ed and the foreground processes fail to receive a post from lgwr, an incident is recorded.diagnostic traces are performed, and polling is used instead of post/wait.

oracle uses semaphores extensively, if you look for references to “commit” in the oracle docs, you’ll find the word “post” everywhere when they talk about communication between the foreground processes and lgwr. now, remember that a commit has two options: first, immediate or batch and second, wait or nowait. it looks like this to me:

immediate: fg process will post to lgwr, triggering i/o (default)
batch: fg process will not post lgwr
wait: lgwr will post fg process when i/o is complete (default)
nowait: lgwr will not post fg process when i/o is complete

参考:https://blog.csdn.net/rgb_rgb/article/details/72804143

 

(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐