1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::net::SocketAddr;
use clap::Clap;
use dvm_net::endpoint::Endpoint;

/// Configuration for service that gathers metrics about VM execution.
#[derive(Debug, Default, Clone, Clap)]
pub struct InfoServiceConfig {
    /// Info service address  in the form of HOST_ADDRESS:PORT.
    /// Optional parameter. If the address is set, the web service starts.
    #[clap(
        name = "info service listen address. HOST_ADDRESS:PORT",
        env = "INFO_SERVICE_ADDR",
        long = "info-service-addr",
        short = 'i',
        verbatim_doc_comment
    )]
    pub info_service_addr: Option<SocketAddr>,

    /// Dvm self address. HOST_ADDRESS:PORT.
    /// Optional parameter. If the address is set, the health check service starts.
    #[clap(
        name = "Dvm self check address. protocol://HOST_ADDRESS:PORT",
        env = "DVM_SELF_CHECK_ADDRESS",
        long = "dvm-self-check-addr",
        verbatim_doc_comment
    )]
    pub dvm_self_check_addr: Option<Endpoint>,

    /// Metric refresh interval in seconds.
    #[clap(
        default_value = "5",
        env = "METRIC_UPDATE_INTERVAL",
        name = "seconds between updates",
        long = "metric-update-interval",
        verbatim_doc_comment
    )]
    pub metric_update_interval: u64,

    /// Maximum period between heartbeats. In seconds.
    #[clap(
        default_value = "5",
        env = "HEARTBEAT_INTERVAL_MAX",
        name = "max seconds between heartbeats",
        long = "heartbeat-interval-max",
        verbatim_doc_comment
    )]
    pub heartbeat_max_interval: u64,

    /// The interval between ping requests to dvm. In seconds.
    #[clap(
        default_value = "4",
        env = "HEARTBEAT_PRESSURE",
        name = "seconds between heartbeats",
        long = "heartbeat-pressure",
        verbatim_doc_comment
    )]
    pub heartbeat_stimulation_interval: u64,
}

/// Memory options.
#[derive(Debug, Default, Clone, Clap)]
pub struct MemoryOptions {
    /// Module cache size in KB. Default size is 100 MB.
    #[clap(
        default_value = "102400",
        long = "module_cache_size",
        verbatim_doc_comment
    )]
    pub module_cache: usize,

    /// Number of executions between vm reset.
    #[clap(
        default_value = "1000",
        long = "vm_reset_interval",
        verbatim_doc_comment
    )]
    pub vm_reset_interval: usize,
}

impl MemoryOptions {
    /// Returns the module cache size in bytes.
    pub fn module_cache(&self) -> usize {
        self.module_cache * 1024
    }

    /// Returns the number of execution between memory checks.
    pub fn memory_check_period(&self) -> usize {
        self.vm_reset_interval
    }
}