fix: Start listening after schema cache load#4880
Conversation
ca17636 to
5bb48c5
Compare
|
Previous discussion on the motivation of the change on #4703 (comment). |
|
@mkleczek As per #4703 (comment), this would clearly benefit the case of But let's consider the scenario of a single instance managed by systemd behind a proxy:
With this change, now we'll not respond and clients will get a So under this scenario, it looks like this new behavior is worse? Thinking more what we need is zero-downtime restarts, which I guess is easier under this new behavior since we could rely on systemd socket activation? |
Not really. From the point of view of the client there is not much gain from these |
5bb48c5 to
99554cb
Compare
Thought about removing the
So it's a minimum, not exact time. I think it should be fine to be clear about this on the docs and recommend jitter. |
|
@mkleczek The direction here is good, make sure to address the comments and then we can merge this. |
99554cb to
6a927aa
Compare
|
I am marking this PR as draft to address concerns related to handling schema cache loading errors during start-up. It seems the right course of action cannot be any of these two extremes:
The first one forces clients to handle normal conditions as errors. It seems like the best (ultimate?) startup sequence should be:
That way we achieve both:
The above requires wider refactoring - today the whole schema cache loading loop is implemented in a single function without any means to introspect the state of the loading process. Clients can only trigger asynchronous schema load and wait for it to finish. @steve-chavez WDYT? |
f577ea6 to
3eed89b
Compare
I wrote up two different proposals but threw them away, because I always came to the conclusion that this is the sensible thing to do. So 👍 |
Looks much better. Also 👍 from me. |
So between these two steps, we'd still return the connection error, however after that we'd retry and get the 503. I agree with this. @steve-chavez Not sure if it was discussed elsewhere, but this would mean that the proposal to wait until the schema cache is loaded on startup is no longer desired, right? |
|
@laurenceisla The waiting is being discussed on #4873 (comment). #4129 won't be solved here. |
e653c00 to
55c3e8c
Compare
Updated the code to implemented the above. |
c442894 to
feffcfd
Compare
Rebased |
Same reasoning here - but with an eye on our future selves, when we need to maintain things. It's much more likely we'd like to revert this fix compared to the refactor. If we do the refactor first, then the fix, it's easy to revert. If we do it the other way around, we'd then need to be very careful at that time. btw rebasing your changeset over it should not have been hard. It should have been as easy as:
The result after the two commits is the same, so that part is really easy. The harder to resolve conflict, which included actually looking at the code, was the one that I did when I cherry-picked it. That's why I did it and didn't force it onto you. |
steve-chavez
left a comment
There was a problem hiding this comment.
Looked at all the change in tests, they look fine.
All is left is resolving https://github.com/PostgREST/postgrest/pull/4880/changes#r3306654090.
8297bfd to
28f283d
Compare
01b020d to
0cb9e0f
Compare
Done |
0cb9e0f to
15b2665
Compare
15b2665 to
1adea05
Compare
This change ensures PostgREST starts listening on a server socket only after it loaded the schema cache and is ready to handle requests. It is no longer going to return 503 errors during startup until the schema cache is loaded.
1adea05 to
3a0356f
Compare
|
Was about to merge but noticed the loadtest failed: https://github.com/PostgREST/postgrest/actions/runs/27539944616?pr=4880
Is it just a sporadic failure? |
It does look like some spurious failure, indeed. The changes in this PR do not touch request processing code paths. @wolfgangwalther WDYT? |
|
Hm, now I also see that we have an improvement in perf?
But as you mentioned that doesn't make sense for this PR. So I guess the the |
I don't think that would help - the opposite in fact. We'd be unable to detect small improvements like the one in #5008. Reading loadtest results just isn't straight forward. It has never been and will never be. To properly assess these results, you always need to look at a lot of context. For example:
For this PR we have seen some crazy numbers in both directions on recent runs. Same after merge on main. And on the next commit on main. This indicates there is just a high level of baseline noise in GHA right now. You should get much better results by running the loadtest locally, ideally with a mostly idle machine otherwise. |
Hm, that's no good TBH. It makes me lose confidence on the loadtests, I'd rather always run them locally, but that wastes too much time. What if we use https://docs.github.com/en/actions/concepts/runners/self-hosted-runners for the loadtests? We did use a custom AWS instance for aarch64 builds before, so it should work. Edit: we could use an euronodes VPS. |
This change ensures PostgREST starts listening on a server socket only after it loaded the schema cache and is ready to handle requests. It is no longer going to return 503 errors during startup until the schema cache is loaded.
DISCLAIMER:
This commit was authored entirely by a human without the assistance of LLMs.