本文主要是介绍pgpool分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
应用
http://mengqingyu.javaeye.com/blog/463666
http://zauc.wordpress.com/2010/01/23/%E4%BD%BF%E7%94%A8pgpool-ii%E8%BF%9B%E8%A1%8Cpostgresql%E7%9A%84replication/
http://blog.csdn.net/xtlog/archive/2009/05/27/4219353.aspx
http://blog.chinaunix.net/u2/66215/showart_2109484.html
http://bbs.linuxtone.org/archiver/tid-2701.html
全是根据英文翻译的,有一些不全,英文的在下面
http://pgpool.projects.postgresql.org/pgpool-II/doc/tutorial-en.html
http://pgpool.projects.postgresql.org/pgpool-II/doc/pgpool-en.html
load balance函数(在child.c中),可以看出是随机选择的,先把所有backend的weight加起来,然后随机一个数在加起来和的中间,就取这个backend,这个函数源码还有些问题,应改一改
int select_load_balancing_node(void)
{
double total_weight,r;
int i;
/* choose a backend in random manner with weight */
selected_slot = MASTER_NODE_ID;
total_weight = 0.0;
for (i=0;i<NUM_BACKENDS;i++)
{
if (VALID_BACKEND(i))
{
total_weight += BACKEND_INFO(i).backend_weight;
}
}
r = (((double)random())/RAND_MAX) * total_weight;
total_weight = 0.0;
for (i=0;i<NUM_BACKENDS;i++)
{
if (VALID_BACKEND(i) && BACKEND_INFO(i).backend_weight > 0.0)
{
if(r >= total_weight)
selected_slot = i;
else
break; //这还有一些问题,应在if下面吧
total_weight += BACKEND_INFO(i).backend_weight;
}
}
pool_debug("select_load_balancing_node: selected backend id is %d", selected_slot);
return selected_slot;
}
这篇关于pgpool分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!