Conversation
6295ac8 to
6b514fb
Compare
CyberDem0n
left a comment
There was a problem hiding this comment.
Last, but not least, code is not formatted according to Postgres standards. Please make yourself familiar with https://wiki.postgresql.org/wiki/Developer_FAQ#What.27s_the_formatting_style_used_in_PostgreSQL_source_code.3F and https://wiki.postgresql.org/wiki/Configuring_vim_for_postgres_development
| float8 st_total_active_time;; | ||
| float8 st_total_transaction_idle_time; |
There was a problem hiding this comment.
I believe we should use PgStat_Counter for that (which is internally int64).
| beentry->st_total_active_time += ((double) secs * 1000000 + usecs) / 1000.0; // convert to msec | ||
| } | ||
| else if (beentry->st_state == STATE_IDLEINTRANSACTION || | ||
| beentry->st_state == STATE_IDLEINTRANSACTION_ABORTED) | ||
| { | ||
| pgstat_count_conn_txn_idle_time((PgStat_Counter) secs * 1000000 + usecs); | ||
| beentry->st_total_transaction_idle_time += ((double) secs * 1000000 + usecs) / 1000.0; // convert to msec |
There was a problem hiding this comment.
If st_total_active_time and st_total_transaction_idle_time are PgStat_Counter types, calculation becomes a simple assignment:
beentry->st_total_active_time = pgStatActiveTime;
beentry->st_total_transaction_idle_time = pgStatTransactionIdleTime;And the conversion from usec to msec should happen in the pg_stat_get_activity() function https://github.com/sdudoladov/postgres/pull/4/files#diff-55e2a3d715341559d0d9c960cd2bc697595435c7e15fe59b35f4b36f279ca360R920-R921.
It will help to save a few CPU cycles.
pg_stat_get_db_idle_in_transaction_time() and pg_stat_get_db_active_time() are using exactly this approach.
6b514fb to
60ec5d4
Compare
sdudoladov
left a comment
There was a problem hiding this comment.
@CyberDem0n What is the status of pgident ? Is it still used ? When I run it on the source tree I see tens of violations
| } | ||
|
|
||
| Datum | ||
| pg_stat_get_time_in_msec(PG_FUNCTION_ARGS) |
There was a problem hiding this comment.
- This function saves CPU cycles because it does fp division only on data display and not on every update of the backend status, right ?
- is there a need to split this function into two
pg_stat_get_backend_active_timeandpg_stat_get_backend_idle_in_transaction_time? Those would be completely identical except the names.
There was a problem hiding this comment.
Why have you created this function in the first place?
I only talked about modifying https://github.com/sdudoladov/postgres/pull/4/files#diff-55e2a3d715341559d0d9c960cd2bc697595435c7e15fe59b35f4b36f279ca360R920-R921
If you do something similar to how pg_stat_database view work - that doesn't make sense.
There was a problem hiding this comment.
If you do something similar to how pg_stat_database view work
yes
that doesn't make sense.
true, reverted to simple fp division. I was too focused on understanding
pg_stat_databse and mechanics of catalog initialization.
| { | ||
| pgstat_count_conn_active_time((PgStat_Counter) secs * 1000000 + usecs); | ||
| else | ||
| beentry->st_total_active_time += (secs * 1000000 + usecs); |
There was a problem hiding this comment.
using simple assignemnt
beentry->st_total_active_time = pgStatActiveTime;
beentry->st_total_transaction_idle_time = pgStatTransactionIdleTime;
here won't work, see the comment before the if code section
There was a problem hiding this comment.
I see, pgstat_send_tabstat() resets them after sending...
Ok, then at least we can introduce a new variable in order to store the result of secs * 1000000 + usecs calculation.
d4ff7d7 to
ac8fa4b
Compare
bd63917 to
0ed1bc3
Compare
0ed1bc3 to
146dacb
Compare
|
credit for diffs that form the core of v8: Kyotaro Horiguchi |
73ef7d4 to
db9ccfb
Compare
db9ccfb to
a1d7858
Compare
In a similar effort to f736e18 and 110d817, fixup various usages of string functions where a more appropriate function is available and more fit for purpose. These changes include: 1. Use cstring_to_text_with_len() instead of cstring_to_text() when working with a StringInfoData and the length can easily be obtained. 2. Use appendStringInfoString() instead of appendStringInfo() when no formatting is required. 3. Use pstrdup(...) instead of psprintf("%s", ...) 4. Use pstrdup(...) instead of psprintf(...) (with no formatting) 5. Use appendPQExpBufferChar() instead of appendPQExpBufferStr() when the length of the string being appended is 1. 6. appendStringInfoChar() instead of appendStringInfo() when no formatting is required and string is 1 char long. 7. Use appendPQExpBufferStr(b, .) instead of appendPQExpBuffer(b, "%s", .) 8. Don't use pstrdup when it's fine to just point to the string constant. I (David) did find other cases of #8 but opted to use #4 instead as I wasn't certain enough that applying #8 was ok (e.g in hba.c) Author: Ranier Vilela, David Rowley Discussion: https://postgr.es/m/CAApHDvo2j2+RJBGhNtUz6BxabWWh2Jx16wMUMWKUjv70Ver1vg@mail.gmail.com
There've been a few complaints that it can be overly difficult to figure out why the planner picked a Memoize plan. To help address that, here we adjust the EXPLAIN output to display the following additional details: 1) The estimated number of cache entries that can be stored at once 2) The estimated number of unique lookup keys that we expect to see 3) The number of lookups we expect 4) The estimated hit ratio Technically #4 can be calculated using #1, #2 and #3, but it's not a particularly obvious calculation, so we opt to display it explicitly. The original patch by Lukas Fittl only displayed the hit ratio, but there was a fear that might lead to more questions about how that was calculated. The idea with displaying all 4 is to be transparent which may allow queries to be tuned more easily. For example, if #2 isn't correct then maybe extended statistics or a manual n_distinct estimate can be used to help fix poor plan choices. Author: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com> Author: Lukas Fittl <lukas@fittl.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Andrei Lepikhov <lepihov@gmail.com> Reviewed-by: Robert Haas <robertmhaas@gmail.com> Discussion: https://postgr.es/m/CAP53Pky29GWAVVk3oBgKBDqhND0BRBN6yTPeguV_qSivFL5N_g%40mail.gmail.com
replacement of #2
idle_timewas introduced and indeed got the identical values in the following query:so I've removed the idle time tracking.
float8anddoubleare effectively synonyms so I left the types ofst_total_active_timeandst_total_transaction_idle_timeas is. In fact for exampleDoubleGetDatumis not even defined.pgStatActiveTimeandpgStatidleInTransactionTimeare no longer used to track per-backend values, see comments for explanation.pgstat.h