Re: Inefficiency in SLRU stats collection

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: tomas(dot)vondra(at)2ndquadrant(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Inefficiency in SLRU stats collection
Date: 2020-05-13 12:21:50
Message-ID: 036e4c48-c09b-9105-d4ce-27bf3bc58476@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020/05/13 11:26, Kyotaro Horiguchi wrote:
> At Tue, 12 May 2020 15:50:35 -0400, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote in
>> I happened to come across this code added by 28cac71bd:
>>
>> static PgStat_MsgSLRU *
>> slru_entry(SlruCtl ctl)
>> {
>> int idx = pgstat_slru_index(ctl->shared->lwlock_tranche_name);
>>
>> Assert((idx >= 0) && (idx < SLRU_NUM_ELEMENTS));
>>
>> return &SLRUStats[idx];
>> }
>>
>> which is invoked by all the pgstat_count_slru_XXX routines.
>> This seems mightily inefficient --- the count functions are
>> just there to increment integer counters, but first they
>> have to do up to half a dozen strcmp's to figure out which
>> counter to increment.
>>
>> We could improve this by adding another integer field to
>> SlruSharedData (which is already big enough that no one
>> would notice) and recording the result of pgstat_slru_index()
>> there as soon as the lwlock_tranche_name is set. (In fact,
>> it looks like we could stop saving the tranche name as such
>> altogether, thus buying back way more shmem than the integer
>> field would occupy.)

Sounds good to me.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Atsushi Torikoshi 2020-05-13 12:54:27 Add explanations which are influenced by track_io_timing
Previous Message Fujii Masao 2020-05-13 12:06:15 pgstat_read_statsfiles() and reset timestamp