Skip to main content

Config

Struct Config 

Source
pub struct Config {
Show 16 fields pub threads: usize, pub proxy: Proxy<String>, pub headers: HashMap<String, String>, pub min_chunk_size: u64, pub write_buffer_size: usize, pub write_queue_cap: usize, pub retry_gap: Duration, pub pull_timeout: Duration, pub accept_invalid_certs: bool, pub accept_invalid_hostnames: bool, pub write_method: WriteMethod, pub retry_times: usize, pub local_address: Vec<IpAddr>, pub max_speculative: usize, pub downloaded_chunk: Vec<ProgressEntry>, pub chunk_window: u64,
}

Fields§

§threads: usize

线程数量,推荐值 32 / 16 / 8。线程越多不意味着越快

§proxy: Proxy<String>

设置代理,支持 https、http、socks5 代理

§headers: HashMap<String, String>

自定义请求头

§min_chunk_size: u64

最小分块大小,单位为字节,推荐值 8 * 1024 * 1024

  • 分块太小容易造成强烈竞争
  • 当无法分块的时候会进入冗余竞争模式
§write_buffer_size: usize

写入缓冲区大小,单位为字节,推荐值 16 * 1024 * 1024

  • 只对 WriteMethod::Std 写入方法有效,有利于将随机写入转换为顺序写入,提高写入速度
  • 对于 WriteMethod::Mmap 写入方法无效,因为写入缓冲区由系统决定
§write_queue_cap: usize

写入队列容量,推荐值 10240

如果下载线程太快,填满了写入队列,会触发压背,降低下载速度,防止内存占用过大

§retry_gap: Duration

请求失败后的默认重试间隔,推荐值 500ms

如果服务器返回中有 Retry-After 头,则遵循服务器返回的设定

§pull_timeout: Duration

拉取超时时间,推荐值 5000ms

请求发出后,接收字节中,如果在 pull_timeout 这一段时间内一个字节也没收到,则中断连接,重新请求。 有利于触发 TCP 重新检测拥塞状态,提高下载速度

§accept_invalid_certs: bool

是否接受无效证书(危险),推荐值 false

§accept_invalid_hostnames: bool

是否接受无效主机名(危险),推荐值 false

§write_method: WriteMethod

写入磁盘方式,推荐值 WriteMethod::Mmap

  • WriteMethod::Mmap 写入方式速度最快,将写入交给操作系统执行,但是:
    1. 在 32 位系统上最大只能映射 4GB 的文件,所以在 32 位系统上,会自动回退到 WriteMethod::Std
    2. 必须知道文件大小,否则会自动回退到 WriteMethod::Std
    3. 特殊情况下会出现系统把所有数据全部缓存在内存中,下载完成后一次性写入磁盘,造成下载完成后长时间卡顿
  • WriteMethod::Std 写入方式兼容性最好,会在 write_buffer_size 内对片段进行排序,尽量转换为顺序写入
§retry_times: usize

设置获取元数据的重试次数,推荐值 10。注意,这不是下载中的重试次数

§local_address: Vec<IpAddr>

使用哪些地址来发送请求,推荐值 Vec::new()

如果你有多个网卡可用,可以填写他们的对外 IP 地址,请求会在这些 IP 地址上轮换,下载不一定会更快

§max_speculative: usize

冗余线程数,推荐值 3

当块大小小于 min_chunk_size 后无法分块,进入冗余竞争模式。 最多有 max_speculative 个线程在同一分块上竞争下载,以解决下载卡进度 99% 的问题

§downloaded_chunk: Vec<ProgressEntry>

已经下载过的部分,如果你想下载整个文件,就传 Vec::new()

§chunk_window: u64

已下载分块的平滑窗口,单位为字节,推荐值 8 * 1024

它会过滤掉 downloaded_chunk 中小于 chunk_window 的小空洞,以减小 HTTP 请求数量

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Config

Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<Client, BorrowClient> Prefetch<Client> for BorrowClient
where Client: HttpClient, BorrowClient: Borrow<Client> + Sync,

Source§

async fn prefetch( &self, url: Url, ) -> Result<(UrlInfo, <<Client as HttpClient>::RequestBuilder as HttpRequestBuilder>::Response), (HttpError<Client>, Option<Duration>)>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> AnyError for T
where T: Debug + Send + Unpin + 'static,