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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
@startuml
title "Torflow measurements scaling."
' Own previous bwfile
:prev_votes = VoteSet();
note right
initialize measurements from previous Bandwidth File
end note
' while (for n in nodes.itervalues()?)
' if (n.idhex in prev_votes.vote_map and n.idhex in prev_consensus) then (yes)
' endif
' endwhile
:tot_net_bw = 0;
:;
note right
for every measurement
end note
while (for n in nodes.itervalues()?)
' Anything not set is initialized to 0 or None
:n.fbw_ratio = n.filt_bw/true_filt_avg[n.node_class()];
:n.sbw_ratio = n.strm_bw/true_strm_avg[n.node_class()];
:n.use_bw = n.desc_bw;
:n.pid_error = ...;
note right
if n.sbw_ratio > n.fbw_ratio:
#assert cs_junk.use_best_ratio == True
n.pid_error = (n.strm_bw - true_strm_avg[n.node_class()])
/ true_strm_avg[n.node_class()]
else:
n.pid_error = (n.filt_bw - true_filt_avg[n.node_class()])
/ true_filt_avg[n.node_class()]
0 <= n.pid_error <= 500.0
end note
if (n.idhex in prev_votes.vote_map?) then (yes)
:;
note right
if n.measured_at >
prev_votes.vote_map[n.idhex].measured_at;
end note
if (measurement newer?) then (yes)
:;
note right
if n.idhex in prev_consensus
and ("Guard" in prev_consensus[n.idhex].flags
and "Exit" not in prev_consensus[n.idhex].flags)
end note
if (in prev_consensus, \nis guard \nbut not exit?) then (yes)
:;
note right
if n.idhex not in prev_votes.vote_map
or n.measured_at - prev_votes.vote_map[n.idhex].measured_at
> cs_junk.guard_sample_rate:
# cs_jung.guard_sample_rate = 2*7*24*60*60 # 2wks
end note
if (diff bigger than 2 weeks) then (yes)
:;
note right
# full feedback
n.new_bw = n.get_pid_bw(prev_votes.vote_map[n.idhex],
cs_junk.K_p,
cs_junk.K_i,
cs_junk.K_d,
cs_junk.K_i_decay)
= n.get_pid_bw(prev_votes.vote_map[n.idhex],
1.0, 0, 0, 0)
end note
:self.prev_error = prev_vote.pid_error
self.pid_bw = self.use_bw
+ self.use_bw * self.pid_error
# + self.desc_bw * self.pid_error
self.pid_error_sum = 0 + self.pid_error
n.new_bw = self.pid_bw;
else (no)
:;
note right
\# Use new measurement but not feedback
n.copy_vote(prev_vote.vote_map[n.idhex]));
n.new_bw = n.get_pid_bw(prev_votes.vote_map[n.idhex],
cs_junk.K_p,
cs_junk.K_i,
cs_junk.K_d,
0.0, False)
end note
:\# self.new_bw = vote.bw * 1000
self.pid_bw = vote.pid_bw
self.pid_error_sum = vote.pid_error_sum
self.pid_delta = vote.pid_delta
n.new_bw = self.use_bw + self.use_bw * self_pid_error
n.measured_at = prev_vote.measured_at
n.pid_error = prev_vote.pid_error;
endif
' No (G and noE)
else (no)
if (in prev_consensus, \nis guard and exit) then (yes)
:;
note right
n.new_bw = n.get_pid_bw(prev_votes.vote_map[n.idhex],
cs_junk.K_p*weight,
cs_junk.K_i*weight,
cs_junk.K_d*weight,
cs_junk.K_i_decay)
n.new_bw = n.get_pid_bw(prev_votes.vote_map[n.idhex],
1.0*1.0, 0, 0, 0)
\# so, same code as for when diff is bigger than 2 weeks
end note
:self.prev_error = prev_vote.pid_error
self.pid_bw = self.use_bw
+ self.use_bw * self.pid_error
# + self.desc_bw * self.pid_error
self.pid_error_sum = 0 + self.pid_error
n.new_bw = self.pid_bw;
else (no)
:;
note right
\#again, same code
end note
:self.prev_error = prev_vote.pid_error
self.pid_bw = self.use_bw
+ self.use_bw * self.pid_error
# + self.desc_bw * self.pid_error
self.pid_error_sum = 0 + self.pid_error
n.new_bw = self.pid_bw;
endif
endif
' No new measurement (in prev bwfile, but havent check consensus), do not vote this round
else (no)
:;
note right
\# Reset values. Don't vote/sample this measurement round.
\# is in the previous bwfile, but haven't check the consensus
n.revert_to_vote(prev_votes.vote_map[n.idhex])
\# which calls again self.copy_vote(vote)
end note
:self.new_bw = prev_vote.bw*1000
self.pid_bw = prev_vote.pid_bw
self.pid_error_sum = prev_vote.pid_error_sum
self.pid_delta = prev_vote.pid_delta
self.pid_error = vote.pid_error
self.measured_at = vote.measured_at;
endif
' Not in previous bwfile, usually only with authoritites, possibly not in conensus?
else (no)
' :n.new_bw = n.use_bw + cs_junk.K_p*n.use_bw*n.pid_error = \n
:n.new_bw = n.use_bw + n.use_bw * n.pid_error
n.pid_error_sum = n.pid_error
n.pid_bw = n.new_bw;
endif
' :n.change = n.new_bw - n.desc_bw;
' For capping later
if (n.idhex in prev_consensus) then (yes)
if (prev_consensus[n.idhex].bandwidth != None) then (yes)
:prev_consensus[n.idhex].measured = True;
:tot_net_bw += n.new_bw;
endif
endif
endwhile
while (for n in nodes.itervalues()?)
:cap...;
endwhile
stop
footer last updated 2021-01-08
@enduml
|