feat: Move operations from `ShapeCache` to `Shape.Consumer`
Addresses https://github.com/electric-sql/electric/issues/1785 and partially addresses https://github.com/electric-sql/electric/issues/1770
Moves a lot of the operations that went through ShapeCache directly into the Shape.Consumer, so that requests can be replied to directly from the shape consumers rather than flooding the ShapeCache with casts that take a while to reach the requesters.
I've tried to keep changes to a minimum in order to do this incrementally and keep these PRs easily reviewable - the ShapeStatus still persists data on every call, the relations and truncates still go through ShapeCache rather than individual shapes, etc
I've also caught the DBConnection.ConnectionErrors for queue timeouts and converted them to 429 errors.
We need to also handle GenServer.call timeouts as sometimes the PG query might not fail but take longer than the default 5 seconds for the GenServer call.
NOTE: I have not updated any tests yet as I first want to ensure people agree with the approach
PERFORMANCE CHECK:
- On my local machine, using in memory stores, running 1000 concurrent new shape connections consistently took ~20sec with these changes, compared to the ~33sec on main, so a ~30% improvement.
- I was also able to succesfully run 10k concurrent connections with this, although it took ~10min to serve, but on main I wasn't able to succsefully run it (@robacourt I think that was the case for you too?) - at least we know it does not get into an unrecoverable state.
Deploy Preview for electric-next ready!
| Name | Link |
|---|---|
| Latest commit | edf9eeda5299db196d7ef902e4c68ba5519f453a |
| Latest deploy log | https://app.netlify.com/sites/electric-next/deploys/66feb82caa29010008b9c0e0 |
| Deploy Preview | https://deploy-preview-1787--electric-next.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
@balegas PR should be ready, @robacourt has been kind enough to kick off a benchmark run for this PR so we can see results on Monday and hopefully merge (?) I expect an improvement in concurrent shape creation and no regressions on other benchmarks - let's see
Yeah looking forward to that! If the benchmarks show anything odd, we'll be happy to have run the benchmarks before :).