Skip to content

Fix computation of the system cache#297

Merged
rjuju merged 2 commits intomasterfrom
fix_cache_computations
Oct 12, 2025
Merged

Fix computation of the system cache#297
rjuju merged 2 commits intomasterfrom
fix_cache_computations

Conversation

@marco44
Copy link
Contributor

@marco44 marco44 commented Oct 9, 2025

We were using shared_blks_hit instead of shared_blks_read to compute total_blks_read Now on some environments like mine where system cache hit is very small, there seems to be slight accounting discrepencies between pg_stat_statements and pg_stat_kcache (some counters must be slightly delayed). So sometimes we get a negative value for system cache hit. Add a greatest(counter,0) to hide this detail

We were using shared_blks_hit instead of shared_blks_read to compute total_blks_read
Now on some environments like mine where system cache hit is very small,
there seems to be slight accounting discrepencies between pg_stat_statements
and pg_stat_kcache (some counters must be slightly delayed). So
sometimes we get a negative value for system cache hit. Add a greatest(counter,0)
to hide this detail
@marco44 marco44 requested a review from rjuju October 9, 2025 09:35
@marco44 marco44 self-assigned this Oct 9, 2025
@marco44 marco44 added the bug label Oct 9, 2025
@marco44
Copy link
Contributor Author

marco44 commented Oct 9, 2025

ruff is always complaining about my PRs. But when I run a ruff format on my tree, it does nothing… any tips about what should be set up to make it work and avoid this back and forth about formatting ?

@rjuju
Copy link
Member

rjuju commented Oct 12, 2025

ruff is always complaining about my PRs. But when I run a ruff format on my tree, it does nothing… any tips about what should be set up to make it work and avoid this back and forth about formatting ?

as mentioned privately the CI is installing a fixed version of ruff, which is now quite outdated. not sure how much changes there would be if we upgraded the version. ideally almost none, otherwise it would be a sign that we should stop using ruff as it's not mature enough.

@rjuju
Copy link
Member

rjuju commented Oct 12, 2025

Now on some environments like mine where system cache hit is very small, there seems to be slight accounting discrepencies between pg_stat_statements and pg_stat_kcache (some counters must be slightly delayed). So sometimes we get a negative value for system cache hit. Add a greatest(counter,0) to hide this detail

I'm wondering if this is because pg_stat_kcache doesn't track the same blocks as pg_stat_statements. pgss only consider buffers, while pgsk will track any disk access. one classic example is looking at the available extensions and their versions. it's all done by looking at the extension directory on disk, and this will lead to more disk access than there should, and powa-web can easily trigger this if you visit the config pages.

@rjuju rjuju merged commit d5333ea into master Oct 12, 2025
2 checks passed
@rjuju rjuju deleted the fix_cache_computations branch October 12, 2025 07:57
@pgiraud
Copy link
Member

pgiraud commented Oct 13, 2025

ruff is always complaining about my PRs. But when I run a ruff format on my tree, it does nothing… any tips about what should be set up to make it work and avoid this back and forth about formatting ?

My only advice would be to make sure ruff actually uses the configuration file (.ruff.toml). You can ensure that by running it in verbose mode or you can explicitly use it with the --config option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants