pgpool2.git / summary / log / commit / refs

commit    7986ffa5ed14f3b1bf668baa44bc76d9e28ac5bb
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Sun Dec 06 07:46:57 2009 +0000

    Optimization when num_init_children == 1. In this case we don't need
    to wait for master returning a response before sending a query to the
    other nodes.


pool_proto_modules.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pool_proto_modules.c b/pool_proto_modules.c index 332865723..52955e4da 100644 --- a/pool_proto_modules.c +++ b/pool_proto_modules.c @@ -557,6 +557,56 @@ POOL_STATUS NotificationResponse(POOL_CONNECTION *frontend, } + /* + * Optimization effort: If there's only one session, we do + * not need to wait for the master node's response, and + * could execute a query concurrently. + */ + if (pool_config->num_init_children == 1) + { + /* Send query to DB nodes */ + for (i=0;i<NUM_BACKENDS;i++) + { + if (!VALID_BACKEND(i)) + continue; + + per_node_statement_log(backend, i, string); + + if (send_simplequery_message(CONNECTION(backend, i), len, string, MAJOR(backend)) != POOL_CONTINUE) + { + free_parser(); + return POOL_END; + } + } + + /* Wait for response from DB nodes */ + for (i=0;i<NUM_BACKENDS;i++) + { + if (!VALID_BACKEND(i)) + continue; + + if (wait_for_query_response(frontend, CONNECTION(backend, i), string, 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); + + free_parser(); + return POOL_END; + } + } + if (commit) + { + TSTATE(backend) = 'I'; + } + free_parser(); + return POOL_CONTINUE; + } + /* Send the query to master node */ per_node_statement_log(backend, MASTER_NODE_ID, string); [parent: d0b17681de64]