Re: Improve the granularity of PQsocketPoll's timeout parameter?
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org, Tristan Partin <tristan@partin.io>,
Dominique Devienne <ddevienne@gmail.com>
Date: 2024-06-12T17:53:13Z
Lists: pgsql-hackers
Attachments
- pqsocketpoll-in-microseconds-v2.patch (text/x-diff) patch v2
Robert Haas <robertmhaas@gmail.com> writes: > I agree this is not great. I guess I didn't think about it very hard > because, after all, we were just exposing an API that we'd already > been using internally. But I think it's reasonable to adjust the API > to allow for better resolution, as you propose. A second is a very > long amount of time, and it's entirely reasonable for someone to want > better granularity. Here's a v2 responding to some of the comments. * People pushed back against not using "int64", but the difficulty with that is that we'd have to #include c.h or at least pg_config.h in libpq-fe.h, and that would be a totally disastrous invasion of application namespace. However, I'd forgotten that libpq-fe.h does include postgres_ext.h, and there's just enough configure infrastructure behind that to allow defining pg_int64, which indeed libpq-fe.h is already relying on. So we can use that. * I decided to invent a typedef typedef pg_int64 PGusec_time_t; instead of writing "pg_int64" explicitly everywhere. This is perhaps not as useful as it was when I was thinking the definition would be "long long int", but it still seems to add some readability. In my eyes anyway ... anyone think differently? * I also undid changes like s/end_time/end_time_us/. I'd done that mostly to ensure I looked at/fixed every reference to those variables, but on reflection I don't think it's doing anything for readability. * I took Ranier's suggestion to make fast paths for end_time == 0. I'm not sure this will make any visible performance difference, but it's simple and shouldn't hurt. We do have some code paths that use that behavior. * Ranier also suggested using clock_gettime instead of gettimeofday, but I see no reason to do that. libpq already relies on gettimeofday, but not on clock_gettime, and anyway post-beta1 isn't a great time to start experimenting with portability-relevant changes. regards, tom lane
Commits
-
Improve the granularity of PQsocketPoll's timeout parameter.
- 105024a47238 17.0 landed