pgpool-II 的health_check_period 和 health_check_timeout

简介:
对 health_check_period与healht_check_timeout,官方解释如下:

health_check_period
This parameter specifies the interval between the health checks in seconds. Default is 0, which means health check is disabled. You need to reload pgpool.conf if you change health_check_period.
复制代码
health_check_timeout
pgpool-II periodically tries to connect to the backends to detect any error on the servers or networks. This error check procedure is called "health check". If an error is detected, pgpool-II tries to perform failover or degeneration. This parameter serves to prevent the health check from waiting for a long time in a case such as un unplugged network cable. The timeout value is in seconds. Default value is 20. 0 disables timeout (waits until TCP/IP timeout). This health check requires one extra connection to each backend, so max_connections in the postgresql.conf needs to be incremented as needed. You need to reload pgpool.conf if you change this value.
复制代码
两者到底是怎样的关系?

看看代码就可以知晓:

复制代码
int main(int argc, char **argv)                                        
{                                        
    ……                                    
    /*                                    
     * This is the main loop                                    
     */                                    
    for (;;)                                    
    {                                    
        CHECK_REQUEST;                 
        /* do we need health checking for PostgreSQL? */  
        if (pool_config->health_check_period > 0)                                
        {                                
            ……                            
            if (pool_config->health_check_timeout > 0)                            
            {                            
                /*                        
                 * set health checker timeout. we want to detect  
                 * communication path failure much earlier before 
                 * TCP/IP stack detects it.                        
                 */                        
                pool_signal(SIGALRM, health_check_timer_handler);                        
                alarm(pool_config->health_check_timeout);                        
            }                            
                                        
            /*                            
             * do actual health check. trying to connect to the backend 
             */                            
            errno = 0;                            
            health_check_timer_expired = 0;                            
            POOL_SETMASK(&UnBlockSig);                            
            sts = health_check();                            
            POOL_SETMASK(&BlockSig);                            
            if (pool_config->parallel_mode || pool_config->enable_query_cache)                            
                sys_sts = system_db_health_check();                        
                                        
            /** 着里面有根据结果进行failover处理的逻辑,省略*/                           
            if ((sts > 0 || sys_sts < 0) 
               && (errno != EINTR || 
                 (errno == EINTR && health_check_timer_expired)))                  
            {                            
                ……                        
            }                            
                                        
            if (pool_config->health_check_timeout > 0)                            
            {                            
                /* seems ok. cancel health check timer */                        
                pool_signal(SIGALRM, SIG_IGN);                        
            }                            
             
            /** 请注意这里的sleep处理 */                           
            sleep_time = pool_config->health_check_period; 
            pool_sleep(sleep_time);                            
        }                                
        else                                
        {                                
            for (;;)                            
            {                            
                int r;                        
                struct timeval t = {3, 0};                        
                                        
                POOL_SETMASK(&UnBlockSig);                        
                r = pool_pause(&t);                        
                POOL_SETMASK(&BlockSig);                        
                if (r > 0)                        
                    break;                    
            }                            
        }                                
    }                                    
                                        
    pool_shmem_exit(0);                                    
}                                        
                                        
复制代码
也就是说首先,health_check是否发生,要看 health_check_period是否大于0。

在这个前提下,如果health_check_timeout也大于零,就埋下一个定时器,
到达health_check_timeout的秒数时,从定时器激活 healht_check函数。

与此同时,

在主循环中进行了 health_check处理后,如果结果OK,那么进行一番整理后,要开始睡眠一段时间,睡眠的时间间隔就是: health_check_period。睡醒了,再回到循环起始处,继续循环。










本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/08/02/2620070.html,如需转载请自行联系原作者

目录
相关文章
|
消息中间件 运维 监控
深入解析Kafka中Replica的妙用
深入解析Kafka中Replica的妙用
624 0
|
SQL 关系型数据库 调度
pgpool-recovery扩展分析
Pgpool-II的故障转移功能需要用到pgpool-recovery扩展,提供了pgpool_recovery、pgpool_remote_start、pgpool_pgctl、pgpool_switch_xlog等几个用C语言实现的自定义函数,用于辅助online recovery工作。
|
NoSQL Redis 数据安全/隐私保护
Redis 6.0 新特性详解
艺术致敬! 一、众多新模块(modules)API   Redis 6中模块API开发进展非常大,因为Redis Labs为了开发复杂的功能,从一开始就用上Redis模块。Redis可以变成一个框架,利用Modules来构建不同系统,而不需要从头开始写然后还要BSD许可。
9608 0
|
Ubuntu 数据安全/隐私保护
Ubuntu下/etc/sudoers的设置和sudo免密码执行及设置无效的原因
Ubuntu下免密码执行sudo及设置无效的原因
3712 0
|
11月前
|
安全 应用服务中间件 网络安全
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
602 60
|
网络安全 容器
SSH——ssh: rejected: administratively prohibited (open failed)
SSH——ssh: rejected: administratively prohibited (open failed)
494 0
阿里云 Aliplayer高级功能介绍
Aliplayer除了一些基本功能,还有一些高级的功能,可能需要云端配合才可以使用,或者播放器本身需要做更多的配置,希望写一些文件介绍如何使用和介绍一下简单的实现原来,让用户了解这些功能,更好的使用播放器,文章不仅介绍内置的功能,还会包含通过插件写的其他功能。
38124 0
|
SQL 关系型数据库 MySQL
Flink问题之中文有乱码如何解决
Apache Flink是由Apache软件基金会开发的开源流处理框架,其核心是用Java和Scala编写的分布式流数据流引擎。本合集提供有关Apache Flink相关技术、使用技巧和最佳实践的资源。
368 0
|
决策智能
ortools求解非线性问题
ortools求解非线性问题
1046 0
ortools求解非线性问题
|
缓存 负载均衡 Unix
Nginx深入详解之upstream分配方式
Nginx深入详解之upstream分配方式
980 0