接上文 pgpool-II的性能缺陷:
前文已经说到,pgpool-II在replication mode状态下,是顺次而非并行执行SQL文给各个DB节点。
从Source的角度,可以看到:

/*
* Send simple query and wait for response
* send_type:
* -1: do not send this node_id
* 0: send to all nodes
* >0: send to this node_id
*/
POOL_STATUS pool_send_and_wait(POOL_QUERY_CONTEXT *query_context,
int send_type, int node_id)
{
……
/* Send query */
for (i=0;i<NUM_BACKENDS;i++){
……
per_node_statement_log(backend, i, string);
if ( send_simplequery_message(CONNECTION(backend, i),
len, string, MAJOR(backend)) != POOL_CONTINUE) {
return POOL_END;
}
}
/* Wait for response */
……
if (wait_for_query_response(frontend, CONNECTION(backend, i),
MAJOR(backend)) != POOL_CONTINUE){
/* Cancel current transaction */
CancelPacket cancel_packet;
cancel_packet.protoVersion = htonl(PROTO_CANCEL);
cancel_packet.pid = MASTER_CONNECTION(backend)->pid;
cancel_packet.key= MASTER_CONNECTION(backend)->key;
cancel_request(&cancel_packet);
return POOL_CONTINUE;
}

经过对程序的进一步分析和试验,可以得出以下的结论:
在 Master Node 和其他各Node之间,对SQL文的执行是串行的。
在 Master Node以外的其他各Node之间,是并行执行的。其实是
至于为何 pgpool-II把对 Master Node和 其他Node的执行分开,也许有特殊考虑,也许是为了保证Master Node的正确性。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/08/09/2630172.html,如需转载请自行联系原作者