2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
23 class bwlimit: public SMARTALLOC
25 static const int sample_capacity=10;
28 int64_t m_bwlimit; /* set to limit bandwidth */
29 int64_t m_nb_bytes; /* bytes sent/recv since the last tick */
30 btime_t m_last_tick; /* last tick used by bwlimit */
31 btime_t m_backlog_limit; /* don't handle more backlog thna this us */
32 pthread_mutex_t m_bw_mutex;
34 int64_t samples_time[sample_capacity];
35 int64_t samples_byte[sample_capacity];
36 int64_t samples_sleep[sample_capacity];
37 int64_t total_time, total_byte, total_sleep;
38 int64_t current_time, current_byte, current_sleep;
39 int64_t current_sample;
41 void push_sample(int64_t t, int64_t bytes, int64_t sleep);
44 bwlimit(int64_t speed=0): m_bwlimit(speed), m_nb_bytes(0), m_last_tick(0),
45 m_backlog_limit(10*1000*1000),
46 total_time(0), total_byte(0), total_sleep(0), current_sample(0)
48 pthread_mutex_init(&m_bw_mutex, NULL);
52 pthread_mutex_destroy(&m_bw_mutex);
55 void control_bwlimit(int bytes);
56 void set_bwlimit(int64_t maxspeed) { m_bwlimit = maxspeed; };
57 int64_t get_bwlimit() { return m_bwlimit; };
58 bool use_bwlimit() { return m_bwlimit > 0;};
60 void get_total(int64_t *t, int64_t *bytes, int64_t *sleep);