[pgpool-hackers: 4472] Re: Eliminate unnecessary memory allocation

Tatsuo Ishii ishii at sraoss.co.jp
Wed Jun 12 17:23:12 JST 2024


> Currently when Pgpool-II runs in extended query mode in streaming
> replication (and logical replication mode), it adds info on target
> PostgreSQL node ids and query context etc., to the "pending messages
> list" when parse, bin, describe, execute and close message are
> arrived. Later on, PostgreSQL sends respond message like parse
> complete message to Pgpool-II. The info in the list is used to decide
> from which PostgreSQL node to be read.
> 
> When pending messages are created, Pgpool-II does like:
> 
> pmsg = pool_pending_message_create();	/* create a pending message */
> pool_pending_message_dest_set(pmsg, query_context)	/* set PostgreSQL node ids to be sent */
> pool_pending_message_query_set(pmsg, query_context);	/* add query context */
> pool_pending_message_add(pmsg);		/* add the pending message to the list */
> pool_pending_message_free_pending_message(pmsg);	/* free memory allocated by pool_pending_message_create();
> 
> The reason why pool_pending_message_free_pending_message(pmsg) is
> called here is, pool_pending_message_add() creates a copy of the
> pending message then add it to the list. Thus pmsg is not necessary
> any more. But is it really needed? I think we can eliminate copying
> the pending message and instead add the pending message to the list
> directory. Since the pending message is frequently created and
> discarded while processing extended query protocol, this should reduce
> memory footprint and CPU cycle.
> 
> Attached is the patch to implement this. After applying the patch I
> observe slight performance enhancement (less than 1%).
> (I ran pgbench: pgbench -M extended -S -p 11000 -T 300 -c 4 test)
> 
> I am not sure if this is just a noise or not. But I am sure the patch
> reduce memory usage and CPU cycle.
> 
> Comments/suggestions are welcome.

Since there's no objection, I have pushed the patch to the master branch.

Best reagards,
--
Tatsuo Ishii
SRA OSS LLC
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp


More information about the pgpool-hackers mailing list