Making migrations faster
Migrations are probably my biggest pain point right now. Any patch operation against a table has to be done on 200 records per page, and each page takes ~30s. This seems orders of magnitude slower than it should be, so I'm pretty sure I'm doing something wrong.
I was originally using the helper from your repo, but thought I'd try just writing a plain action that uses a paginated mutation so I don't have to manually page through and keep passing the cursor in myself (which the helper requires).
I'm now trying to patch records concurrently, say in chunks of 20, but this seems to break convex and the instance stops responding for a while before what I can only assume is a reboot of some sort.
So I guess the questions are:
1. are concurrent write operations supported?
2. are migrations supposed to take this long or am I holding it wrong?
23 Replies
This sounds pretty rough, could you share the instance name in DM? I agree this is orders of magnitude slower that it should be.
In this paginated mutation, is it just fetching the first N or so each time, or how are you paginating?
Concurrent writes are supported, though if you're reading & writing the same rows as other mutations, you'll be contending with write conflicts (which auto-retry to a degree).
There's also some nuances to scanning the same region over & over. e.g.:
This will have some performance implications differently from using our cursors, which is a bit complicated but I can explain if you're curious
@erquhart re "holding it wrong," you might stop doing these writes in parallel. We're working on making these more efficient, but doing them in parallel is not actually helping right now and it's hitting a corner case with timeouts that don't get surfaced correctly.
I'm doing them in other places too, and I'm betting that's what's causing the issues with my instance that surfaced last week
I think Ian's advice generally applies, my advice is specific to us looking at traffic on your instance right now
I was originally using the helper from your repo, but thought I'd try just writing a plain action that uses a paginated mutation so I don't have to manually page through and keep passing the cursor in myself (which the helper requires).You might be interested in the action that comes along with the helper in the repo: https://github.com/get-convex/convex-helpers/blob/main/convex/lib/migrations.ts#L65 That one you can call like:
GitHub
convex-helpers/convex/lib/migrations.ts at main · get-convex/convex...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
Yeah that's the one I've been using
... and it will run the batches without you having to pass in a cursor
hmm wait a minute, I don't remember passing a name argument though...
yeah there's the migration wrapper which makes something that can do just one batch, and a second dedicated action that does the looping for you
it's at the bottom of the file
Ah so there is a looping handler, that's what was I was missing
Yeah I'm realizing I never added good comments to that file. Doing it now
Setting that aside for a sec, shouldn't this just work:
I'm running the action from the dashboard. It's not doing anything concurrently. But it's taking a really long time to run.
Actually it just failed after 70 seconds:
The table has ~12k documents, so 120 pages of 100.
At a glance that does look right
It does manage to patch some records, but it eventually fails
After the failure message, the action is still running, there's just a lost connection or something
but the running action still does eventually fail
and this is doing mutations serially, even though the writes are batched in the mutation
yeah it's completely serial
I dropped the concurrency
The failing action seems tough. @ballingt are you looking at exceptions / logs already?
Yeah Lee is taking a look
Here's the last few logs from the mutations this action ran:
Note how it says it took ~8s for each page, but the logs are ~25s apart
@erquhart just send you a direct message, this is something we would expect to go much better so we're investigating and will let you know when we know more
Thank you!