| From: | Andres Freund <andres(at)anarazel(dot)de> |
|---|---|
| To: | Michael Paquier <michael(at)paquier(dot)xyz>, Melanie Plageman <melanieplageman(at)gmail(dot)com>, Lukas Fittl <lukas(at)fittl(dot)com> |
| Cc: | Bernd Reiß <bd_reiss(at)gmx(dot)at>, pgsql-hackers(at)lists(dot)postgresql(dot)org, gouda0x(at)gmail(dot)com |
| Subject: | Re: Use instr_time for pg_stat_database block read/write time counters |
| Date: | 2026-10-01 23:16:39 |
| Message-ID: | tuhmtk22xipzn6doizkbdpqictnu3ti3mkfvj3d6zgz6qpjgb2@a6ef2dojrxk7 |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On 2026-10-02 07:57:38 +0900, Michael Paquier wrote:
> On Mon, Sep 28, 2026 at 02:24:52PM +0200, Bernd Reiß wrote:
> > @@ -125,7 +125,7 @@ pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
> > {
> > if (io_op == IOOP_WRITE || io_op == IOOP_EXTEND)
> > {
> > - pgstat_count_buffer_write_time(INSTR_TIME_GET_MICROSEC(io_time));
> > + INSTR_TIME_ADD(pgStatBlockWriteTime, io_time);
> > if (io_object == IOOBJECT_RELATION)
> > INSTR_TIME_ADD(pgBufferUsage.shared_blk_write_time, io_time);
> > else if (io_object == IOOBJECT_TEMP_RELATION)
> > @@ -133,7 +133,7 @@ pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op,
> > }
> > else if (io_op == IOOP_READ)
> > {
> > - pgstat_count_buffer_read_time(INSTR_TIME_GET_MICROSEC(io_time));
> > + INSTR_TIME_ADD(pgStatBlockReadTime, io_time);
> > if (io_object == IOOBJECT_RELATION)
> > INSTR_TIME_ADD(pgBufferUsage.shared_blk_read_time, io_time);
> > else if (io_object == IOOBJECT_TEMP_RELATION)
>
> Hmm. This part of the patch touches a performance-sensitive area.
> This is exchanging one addition for another, which I doubt really
> matters, but who knows.. Andres, any thoughts perhaps?
I think it should actually be a measurable win, due to getting rid of
INSTR_TIME_GET_MICROSEC(). That's a nontrivial conversion removed from the hot
path.
Doing the conversion from instr_time ticks once per stats flush, instead of
once per measurement, is a lot better.
Of course it'd be even better if would be to stop counting the same stuff in
pgBufferUsage.{shared,local}_blk_{read,write}_time and
pgStatBlock{Read,Write}Time. That's pretty darn silly.
pgstat_update_dbstats() should just keep a pgBufferUsage snapshot from the
last report and add up the relevant pgBufferUsage fields. And vacuum & analyze
already diff, so they just would need to add the fields to get the same
results.
Greetings,
Andres Freund
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alberto Piai | 2026-10-01 23:30:35 | Re: Adding a stored generated column without long-lived locks |
| Previous Message | Tom Lane | 2026-10-01 23:07:37 | Re: Partial indexes on system catalogs |