Thread: Per query FDW network stat collection

Per query FDW network stat collection

From
Ilya Gladyshev
Date:
Hello,

I have implemented per query network stat collection for FDW. It is done 
in a similar way to how buffer and WAL stats are collected and it can be 
seen with a new NETWORK option for explain command:

explain (analyze, network) insert into itrtest values (2, 'blah');

                                           QUERY PLAN
-----------------------------------------------------------------------------------------------
  Insert on itrtest  (cost=0.00..0.01 rows=0 width=0) (actual 
time=0.544..0.544 rows=0 loops=1)
    Network: FDW bytes sent=197 received=72, wait_time=0.689
    ->  Result  (cost=0.00..0.01 rows=1 width=36) (actual 
time=0.003..0.003 rows=1 loops=1)
  Planning Time: 0.025 ms
  Execution Time: 0.701 ms
(5 rows)

I am yet to add corresponding columns to pg_stat_statements, write tests 
and documentation, but before I go ahead with that, I would like to know 
what the community thinks about the patch.

Regards,

Ilya Gladyshev



Attachment

Re: Per query FDW network stat collection

From
Julien Rouhaud
Date:
On Tue, Aug 24, 2021 at 5:12 PM Ilya Gladyshev
<i.gladyshev@postgrespro.ru> wrote:
>
> I have implemented per query network stat collection for FDW. It is done
> in a similar way to how buffer and WAL stats are collected and it can be
> seen with a new NETWORK option for explain command:
>
> explain (analyze, network) insert into itrtest values (2, 'blah');
>
>                                            QUERY PLAN
> -----------------------------------------------------------------------------------------------
>   Insert on itrtest  (cost=0.00..0.01 rows=0 width=0) (actual
> time=0.544..0.544 rows=0 loops=1)
>     Network: FDW bytes sent=197 received=72, wait_time=0.689
> [...]

It sound like a really useful metric to have.

However I'm not sure that having a new "network" option is the best
way for that.  It seems confusing as IIUC it won't be catching all
network activity (like fe/be activity, or network disk...) but only
FDW activity.  I think it would be better to have those information
retrieved when using the verbose option rather than a new one.
Similarly, I'm afraid that INSTRUMENT_NETWORK could be misleading,
although I don't have any better proposal right now.



Re: Per query FDW network stat collection

From
Ilya Gladyshev
Date:
On 24.08.2021 12:19, Julien Rouhaud wrote:
> However I'm not sure that having a new "network" option is the best
> way for that.  It seems confusing as IIUC it won't be catching all
> network activity (like fe/be activity, or network disk...) but only
> FDW activity.  I think it would be better to have those information
> retrieved when using the verbose option rather than a new one.
> Similarly, I'm afraid that INSTRUMENT_NETWORK could be misleading,
> although I don't have any better proposal right now.

I am also doubtful about this naming. Initially, I wanted to add fe/be 
activity as one of the metrics, but then decided to restrict myself to 
FDW for now. However, I decided to leave "network" as it is, because to 
me it makes sense to have all the network-related metrics under a single 
explain option (and a single instrumentation flag perhaps), in case more 
are added later. The struct fields used for collection internally tell 
explicitly that they are meant to be used only for FDW stats and the 
explain output also mentions that the displayed stats are for FDW 
network activity.