-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Several performance optimizations #100
base: develop
Are you sure you want to change the base?
Changes from all commits
a95ce07
64a680d
54fdefb
41e5b0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,16 @@ mod client; | |
use argh::FromArgs; | ||
use coldsnap::{SnapshotDownloader, SnapshotUploader, SnapshotWaiter, WaitParams}; | ||
use indicatif::{ProgressBar, ProgressStyle}; | ||
use rusoto_core::{HttpClient, Region}; | ||
use rusoto_core::{HttpClient,HttpConfig, Region}; | ||
use rusoto_credential::{ChainProvider, ProfileProvider}; | ||
use rusoto_ebs::EbsClient; | ||
use rusoto_ec2::Ec2Client; | ||
use snafu::{ensure, ResultExt}; | ||
use std::path::PathBuf; | ||
use std::time::Duration; | ||
|
||
type Result<T> = std::result::Result<T, error::Error>; | ||
|
||
#[tokio::main] | ||
#[tokio::main(flavor = "multi_thread", worker_threads = 512)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious how you calculated or determined this number! |
||
// Returning a Result from main makes it print a Debug representation of the error, but with Snafu | ||
// we have nice Display representations of the error, so we wrap "main" (run) and print any error. | ||
// https://github.com/shepmaster/snafu/issues/110 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,10 @@ pub struct Error(error::Error); | |
type Result<T> = std::result::Result<T, Error>; | ||
|
||
const GIBIBYTE: i64 = 1024 * 1024 * 1024; | ||
const SNAPSHOT_BLOCK_WORKERS: usize = 64; | ||
const SNAPSHOT_BLOCK_ATTEMPTS: u8 = 3; | ||
const SNAPSHOT_BLOCK_WORKERS: usize = 2000; | ||
const SNAPSHOT_BLOCK_ATTEMPTS: u8 = 5; | ||
const SHA256_ALGORITHM: &str = "SHA256"; | ||
const DISABLE_SHA: bool = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't want to turn off the SHA hash checking by default. I could maybe see providing users a flag to turn this off, but a constant isn't really configurable, and isn't currently documented or particularly discoverable. |
||
|
||
// ListSnapshotBlocks allows us to specify how many blocks are returned in each | ||
// query, from the default of 100 to the maximum of 10000. Since we fetch all | ||
|
@@ -302,24 +303,26 @@ impl SnapshotDownloader { | |
data_length, | ||
} | ||
); | ||
|
||
let mut block_digest = Sha256::new(); | ||
block_digest.update(&block_data); | ||
let hash_bytes = block_digest.finalize(); | ||
let block_hash = base64::encode(&hash_bytes); | ||
|
||
ensure!( | ||
block_hash == expected_hash, | ||
error::BadBlockChecksum { | ||
snapshot_id, | ||
block_index, | ||
block_hash, | ||
expected_hash, | ||
} | ||
); | ||
if !DISABLE_SHA { | ||
let mut block_digest = Sha256::new(); | ||
block_digest.update(&block_data); | ||
let hash_bytes = block_digest.finalize(); | ||
let block_hash = base64::encode(&hash_bytes); | ||
|
||
ensure!( | ||
block_hash == expected_hash, | ||
error::BadBlockChecksum { | ||
snapshot_id, | ||
block_index, | ||
block_hash, | ||
expected_hash, | ||
} | ||
); | ||
} | ||
|
||
// Blocks of all zeroes can be omitted from the file. | ||
let sparse = block_data.iter().all(|&byte| byte == 0u8); | ||
// let sparse = block_data.iter().all(|&byte| byte == 0u8); | ||
let sparse = expected_hash.eq("B4VNL+8pega6gWheZgwzLeNtXRjVRpJ9MNqtbX/aFUE="); // Known checksum for a sparse 512K block. | ||
if sparse { | ||
if let Some(ref progress_bar) = *context.progress_bar { | ||
progress_bar.inc(1); | ||
|
@@ -355,7 +358,9 @@ impl SnapshotDownloader { | |
.await | ||
.context(error::WriteFileBytes { path, count })?; | ||
|
||
f.flush().await.context(error::FlushFile { path })?; | ||
if !DISABLE_SHA { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formatting looks a bit off here - can we make sure to run all the code through |
||
f.flush().await.context(error::FlushFile { path })?; | ||
} | ||
|
||
if let Some(ref progress_bar) = *context.progress_bar { | ||
progress_bar.inc(1); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we're hoping to stay on tokio 1.8 as it's an LTS release.