You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Backfilling large data sets on rotational drives is slow #2393
Unfortunately, after leaving the replication running over the weekend, it's now dropped to a very unstable rate of 50-450 writes/s (centered around 250/s) and is behaving very erratically. After 3 days, it has only completed 747340/2730617 blocks. So, it doesn't appear like this problem is resolved in the latest 1.12 releases.
I can reproduce similar replication rates on deadshot (one of our servers). #2392 describes a possible solution, at least a partial one.
It's 6 x 2TB SATA disks in hardware RAID10 with 512MiB BBU write cache, 48GiB of RAM, 2 x E5645 Xeons for each node. The storage is pretty slow at random IO, but reasonably speedy at block IO. It's not SSDs because this is the hardware I had free when I went to set up our test cluster, and because we tend to like to test on underpowered hardware so we can see where things break a little easier. That's definitely what's led to the tickets I've opened, so it feels like the right approach. ;)
A big remaining problem seems to be that secondary indexes are post constructed while the backfilling is going on.
Maybe backfilling should wait until secondary indexes have finished constructing. Running both at the same time just slows down the process for everybody.
Maybe backfilling should wait until secondary indexes have finished constructing.
That doesn't seem like a bad idea, but it opens up a few other questions:
What happens if the user tries to post-construct multiple secondary indexes?
What happens if the user tries to do backfilling multiple times concurrently (for example, but adding a replica to a big table, waiting half an hour, then adding another big replica?) How would that work with our idea of backfilling in small chunks? (Ideally the second replica would start off where the first replica is at, and then backfill the beginning at the end?)
Let me first describe more precisely what we are talking about here:
At the beginning of a backfill operation, the backfiller sends a list of all secondary indexes that exist on the backfilled table to the backfillee.
The backfillee compares that list to the secondary indexes that already exist on its side, drops the ones that are not in the list, and creates the ones that are in the list but don't exist on its side yet. This initiates secondary index post construction for the new indexes.
At the same time, the backfiller also starts sending data over to the backfillee.
There are two cases that can be distinguished:
The backfillee already was a replica for a shard of that table. In that case, it will already have the right set of secondary indexes, unless the secondary indexes have been changed recently and it hasn't heard about it yet. A common case where this will happen is if the backfillee is a secondary that has been down. When the user creates a secondary index on the primary while the secondary is down, and the secondary comes back up, it will have to create the index as part of the backfill process.
The backfillee didn't have any responsibility for the table. In that case, all secondary indexes will be created. However they will be created on an empty table, so the post construction should be fast.
The scenario that I tested was the second one. The node didn't have any prior responsibility for the table. The problem therefore appeared to be that it started postconstructing on an empty table, but before it could finish, data started to come in from the backfiller and it never caught up.
In the second case, it definitely would make sense to wait for postconstruction to complete before starting to backfill. It will only take something like a second.
In the first case it probably still makes sense. If the backfill finishes but the index isn't there yet, the replica will not be fully usable for all queries since the secondary index on it is not ready. That will lead to inconsistent query results for outdated queries that try to use the index (sometimes it will work, other times it won't). If the primary fails while the secondary is still constructing the index, the index will become completely inaccessible, which might come as a surprise for the user (after all the user sees that they have an otherwise working replica).
@coffeemug If a user creates a new secondary index while a backfill is in progress, that will indeed lead to the same performance problem again.
Here's an alternative way to fix this and some other related problems:
We can try to scale the relative priority of secondary index post construction based on the growth rate of the secondary index queue.
If new writes are added to the secondary index queue, faster than post construction is processing existing data (either from the primary tree or from the other end of the queue), we can start throttling writes to the secondary index queue and give secondary index post construction a higher priority (in terms of yielding less often).
Of course there should be some leeway there. We would have to come up with a robust scheme of how to do this.
As a third (and best, but maybe difficult) solution, we should implement #2134 to get rid of the overhead that secondary index post construction incurs altogether.
I think the smartest approach is to have backfilling wait for secondary index post construction for now. That will be done in the sense of not processing any backfill chunks while any secondary index is being constructed on the table. Note that this way, we also consider user-initiated secondary index construction while backfills are in progress.
The advantage is that this is easy to implement and will immediately get rid of the most obvious problems.
I think it will give a dramatic improvement in backfilling speed on rotational drives, though I still have to test that.
The fix for having backfills paused during post construction is in code review 1559 by @Tryneus.
A quick test shows backfill rates improving from <200 documents/s to 1.3K documents/s. This was on sinister and arclight with rotational drives (2 each in a software RAID), and two secondary indexes.
I think it's worth blocking 1.13 for this.
Partially because the fix is already in code review, and partially because backfilling with secondary indexes has been really slow on rotational drives. At least @nergdron needs this and has been waiting for a solution for a while.
Activity
danielmewes commentedon May 14, 2014
More information from @nergdron:
danielmewes commentedon May 27, 2014
I have to retest this now that #2392 is in next.
danielmewes commentedon May 28, 2014
A big remaining problem seems to be that secondary indexes are post constructed while the backfilling is going on.
Maybe backfilling should wait until secondary indexes have finished constructing. Running both at the same time just slows down the process for everybody.
coffeemug commentedon May 28, 2014
That doesn't seem like a bad idea, but it opens up a few other questions:
danielmewes commentedon May 28, 2014
Let me first describe more precisely what we are talking about here:
At the beginning of a backfill operation, the backfiller sends a list of all secondary indexes that exist on the backfilled table to the backfillee.
The backfillee compares that list to the secondary indexes that already exist on its side, drops the ones that are not in the list, and creates the ones that are in the list but don't exist on its side yet. This initiates secondary index post construction for the new indexes.
At the same time, the backfiller also starts sending data over to the backfillee.
There are two cases that can be distinguished:
The scenario that I tested was the second one. The node didn't have any prior responsibility for the table. The problem therefore appeared to be that it started postconstructing on an empty table, but before it could finish, data started to come in from the backfiller and it never caught up.
In the second case, it definitely would make sense to wait for postconstruction to complete before starting to backfill. It will only take something like a second.
In the first case it probably still makes sense. If the backfill finishes but the index isn't there yet, the replica will not be fully usable for all queries since the secondary index on it is not ready. That will lead to inconsistent query results for outdated queries that try to use the index (sometimes it will work, other times it won't). If the primary fails while the secondary is still constructing the index, the index will become completely inaccessible, which might come as a surprise for the user (after all the user sees that they have an otherwise working replica).
@coffeemug If a user creates a new secondary index while a backfill is in progress, that will indeed lead to the same performance problem again.
Here's an alternative way to fix this and some other related problems:
We can try to scale the relative priority of secondary index post construction based on the growth rate of the secondary index queue.
If new writes are added to the secondary index queue, faster than post construction is processing existing data (either from the primary tree or from the other end of the queue), we can start throttling writes to the secondary index queue and give secondary index post construction a higher priority (in terms of yielding less often).
Of course there should be some leeway there. We would have to come up with a robust scheme of how to do this.
As a third (and best, but maybe difficult) solution, we should implement #2134 to get rid of the overhead that secondary index post construction incurs altogether.
danielmewes commentedon May 28, 2014
I think the smartest approach is to have backfilling wait for secondary index post construction for now. That will be done in the sense of not processing any backfill chunks while any secondary index is being constructed on the table. Note that this way, we also consider user-initiated secondary index construction while backfills are in progress.
The advantage is that this is easy to implement and will immediately get rid of the most obvious problems.
I think it will give a dramatic improvement in backfilling speed on rotational drives, though I still have to test that.
In the longer term, we will implement #2134.
coffeemug commentedon May 28, 2014
Thanks for the explanation Daniel, that makes sense!
danielmewes commentedon May 29, 2014
The fix for having backfills paused during post construction is in code review 1559 by @Tryneus.
A quick test shows backfill rates improving from <200 documents/s to 1.3K documents/s. This was on sinister and arclight with rotational drives (2 each in a software RAID), and two secondary indexes.
danielmewes commentedon May 29, 2014
I think it's worth blocking 1.13 for this.
Partially because the fix is already in code review, and partially because backfilling with secondary indexes has been really slow on rotational drives. At least @nergdron needs this and has been waiting for a solution for a while.
coffeemug commentedon May 29, 2014
I'm ok with that.
danielmewes commentedon May 29, 2014
Merged into next 1153a0d