On Wed Dec 6 21:25:09 2023 +0000, Zebediah Figura wrote:
It may be worth being aware that this won't actually work on Windows, or, well, it'll give you a wait at least as long as one interrupt timer tick, which is no shorter than 1 ms. I... *think* Linux can do shorter waits, although it's not particularly easy to find this out from research, and I don't know how much of a concern it is if this is only a problem on Windows. I'm also not sure how much of a concern it is to poll for queries only every 1 ms. I guess cases where there are active queries but the CS is sleeping for more than 100 µs are going to be rare anyway (or symptomatic of some client-side overhead that should be fixed)?
I'm pretty sure that Linux can do these shorter sleeps just fine (with the understanding that it's only going to be a lower bound anyway). AFAIK recent Windows can actually go lower than 1ms as well, although it's not that simple because of course it isn't. I remember reading some blog post with all the interesting details but I can't find it now (I'll keep looking).
I'm also not sure how much of a concern it is to poll for queries only every 1 ms. I guess cases where there are active queries but the CS is sleeping for more than 100 µs are going to be rare anyway (or symptomatic of some client-side overhead that should be fixed)?
I think that's usually the case. The timeout was originally 1 ms and I didn't encounter obvious issues while testing (of course my testing was also necessarily limited). I guess the question is whether trying to go with this and possibly finding out the hard way is what we want to do for this one. There's also the option of yielding instead (i.e. 0 timeout), which maybe is safer in this sense, but also potentially not as good.
I should also mention that the following patch uses the same timeout but for client-side waits, and for those yielding is probably less of a problem (i.e. there's a good chance that the CS thread or some other would use the CPU time and we won't actually end up spinning). I could 1. use a separate timeout for the client side 2. set it to 0. I think I'll do 1 regardless, let me know how you feel about 2.