-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic Rate Limiting of Snapshots (#975)
* CASS-2011 update interface to accommodate dependency change * CASS-2011 move backup cleaning outside of getTimer method * CASS-2011 introduce a target time for upload completion. Currently always the epoch which implies a no-op * CASS-2011 Change AbstractFileSystem API to pass target instant to fileUploadImpl * CASS-2011 Delete already-uploaded files to get accurate estimates of remaining bytes to upload. * CASS-2011 create a rate limiter that dynamically adjusts its throttle based on the bytes still to upload in all remaining snapshots and a user-specified target time. Adjust the throttle only when we've deviated by a user-configurable threshold to ensure the rate limiter is not constantly adjusted. In that case, it would be redundant as it does not throttle the subsequent file after an adjustment. Ensure that the target does not exceed the earlier of the next scheduled snapshot or the time at which we would fail to meet our backup verification SLO. * CASS-2011 Add unit tests and associated refactoring for BackupDynamicRateLimiter.
- Loading branch information
1 parent
99df803
commit 27c267e
Showing
27 changed files
with
518 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
priam/src/main/java/com/netflix/priam/backup/BackupDynamicRateLimiter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.netflix.priam.backup; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.util.concurrent.RateLimiter; | ||
import com.netflix.priam.config.IConfiguration; | ||
import java.time.Clock; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import javax.inject.Inject; | ||
|
||
public class BackupDynamicRateLimiter implements DynamicRateLimiter { | ||
|
||
private final Clock clock; | ||
private final IConfiguration config; | ||
private final DirectorySize dirSize; | ||
private final RateLimiter rateLimiter; | ||
|
||
@Inject | ||
BackupDynamicRateLimiter(IConfiguration config, Clock clock, DirectorySize dirSize) { | ||
this.clock = clock; | ||
this.config = config; | ||
this.dirSize = dirSize; | ||
this.rateLimiter = RateLimiter.create(Double.MAX_VALUE); | ||
} | ||
|
||
@Override | ||
public void acquire(AbstractBackupPath path, Instant target, int permits) { | ||
if (target.equals(Instant.EPOCH) | ||
|| !path.getBackupFile() | ||
.getAbsolutePath() | ||
.contains(AbstractBackup.SNAPSHOT_FOLDER)) { | ||
return; | ||
} | ||
long secondsRemaining = Duration.between(clock.instant(), target).getSeconds(); | ||
if (secondsRemaining < 1) { | ||
// skip file system checks when unnecessary | ||
return; | ||
} | ||
int backupThreads = config.getBackupThreads(); | ||
Preconditions.checkState(backupThreads > 0); | ||
long bytesPerThread = this.dirSize.getBytes(config.getDataFileLocation()) / backupThreads; | ||
if (bytesPerThread < 1) { | ||
return; | ||
} | ||
double newRate = (double) bytesPerThread / secondsRemaining; | ||
double oldRate = rateLimiter.getRate(); | ||
if ((Math.abs(newRate - oldRate) / oldRate) > config.getRateLimitChangeThreshold()) { | ||
rateLimiter.setRate(newRate); | ||
} | ||
rateLimiter.acquire(permits); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
priam/src/main/java/com/netflix/priam/backup/DirectorySize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.netflix.priam.backup; | ||
|
||
import com.google.inject.ImplementedBy; | ||
|
||
/** estimates the number of bytes remaining to upload in a snapshot */ | ||
@ImplementedBy(SnapshotDirectorySize.class) | ||
public interface DirectorySize { | ||
/** return the total bytes of all snapshot files south of location in the filesystem */ | ||
long getBytes(String location); | ||
} |
9 changes: 9 additions & 0 deletions
9
priam/src/main/java/com/netflix/priam/backup/DynamicRateLimiter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.netflix.priam.backup; | ||
|
||
import com.google.inject.ImplementedBy; | ||
import java.time.Instant; | ||
|
||
@ImplementedBy(BackupDynamicRateLimiter.class) | ||
public interface DynamicRateLimiter { | ||
void acquire(AbstractBackupPath dir, Instant target, int tokens); | ||
} |
Oops, something went wrong.