@@ -27,7 +27,7 @@ def __init__(self, port=0, train=False, debug=False):
27
27
28
28
# UDP datagram template
29
29
self .data = {}
30
- self .data ['payload' ] = 'x' * 1400
30
+ self .data ['payload' ] = 'x' * 1350
31
31
32
32
# dimension of state space and action space
33
33
self .state_dim = 4
@@ -45,8 +45,7 @@ def __init__(self, port=0, train=False, debug=False):
45
45
self .prev_recv_ts = None
46
46
47
47
if self .train :
48
- self .max_step_cnt = 2000
49
- self .max_runtime = 5000
48
+ self .max_runtime = 10000
50
49
51
50
# statistics variables to compute rewards
52
51
self .sent_bytes = 0
@@ -62,7 +61,7 @@ def handshake(self):
62
61
"""Handshake with peer receiver. Must be called before run()."""
63
62
64
63
while True :
65
- msg , addr = self .sock .recvfrom (1500 )
64
+ msg , addr = self .sock .recvfrom (1600 )
66
65
67
66
if msg == 'Hello from receiver' and self .peer_addr is None :
68
67
self .peer_addr = addr
@@ -79,7 +78,7 @@ def set_sample_action(self, sample_action):
79
78
self .sample_action = sample_action
80
79
81
80
def reset (self ):
82
- """Reset the sender. Must be called in every training iteration."""
81
+ """Reset the sender. Must be called after every training iteration."""
83
82
84
83
self .seq_num = 0
85
84
self .next_ack = 0
@@ -89,13 +88,14 @@ def reset(self):
89
88
self .prev_send_ts = None
90
89
self .prev_recv_ts = None
91
90
92
- self .sent_bytes = 0
93
- self .acked_bytes = 0
94
- self .first_recv_ts = float ('inf' )
95
- self .last_recv_ts = 0
96
- self .total_delays = []
91
+ if self .train :
92
+ self .sent_bytes = 0
93
+ self .acked_bytes = 0
94
+ self .first_recv_ts = float ('inf' )
95
+ self .last_recv_ts = 0
96
+ self .total_delays = []
97
97
98
- self .drain_packets ()
98
+ self .drain_packets ()
99
99
100
100
def drain_packets (self ):
101
101
"""Drain all the packets left in the channel."""
@@ -116,7 +116,7 @@ def drain_packets(self):
116
116
sys .exit ('Channel closed or error occurred' )
117
117
118
118
if flag & READ_FLAGS :
119
- self .sock .recvfrom (1500 )
119
+ self .sock .recvfrom (1600 )
120
120
121
121
def update_state (self , ack ):
122
122
send_ts = ack ['ack_send_ts' ]
@@ -145,10 +145,6 @@ def update_state(self, ack):
145
145
self .first_recv_ts = min (recv_ts , self .first_recv_ts )
146
146
self .last_recv_ts = max (recv_ts , self .last_recv_ts )
147
147
148
- self .step_cnt += 1
149
- if self .step_cnt >= self .max_step_cnt :
150
- self .running = False
151
-
152
148
if curr_ts_ms () - self .runtime_start > self .max_runtime :
153
149
self .running = False
154
150
@@ -157,9 +153,7 @@ def update_state(self, ack):
157
153
158
154
def take_action (self , action ):
159
155
self .cwnd += self .action_mapping [action ]
160
-
161
- if self .cwnd < 5.0 :
162
- self .cwnd = 5.0
156
+ self .cwnd = max (5.0 , self .cwnd )
163
157
164
158
if self .debug :
165
159
sys .stderr .write ('cwnd %.2f\n ' % self .cwnd )
@@ -175,8 +169,9 @@ def compute_reward(self):
175
169
delay_percentile = float (np .percentile (self .total_delays , 95 ))
176
170
loss_rate = 1.0 - float (self .acked_bytes ) / self .sent_bytes
177
171
178
- reward = np .log (max (1e-4 , avg_throughput ))
179
- reward -= np .log (max (1.0 , delay_percentile / 10.0 ))
172
+ reward = 2 * np .log (max (1e-3 , avg_throughput ))
173
+ reward -= np .log (max (1.0 , delay_percentile ))
174
+ reward += np .log (1.0 - loss_rate )
180
175
181
176
sys .stderr .write ('Average throughput: %.2f Mbps\n ' % avg_throughput )
182
177
sys .stderr .write ('95th percentile one-way delay: %d ms\n ' %
@@ -204,7 +199,7 @@ def send(self):
204
199
sys .stderr .write ('Sent seq_num %d\n ' % int (self .data ['seq_num' ]))
205
200
206
201
def recv (self ):
207
- serialized_ack , addr = self .sock .recvfrom (1500 )
202
+ serialized_ack , addr = self .sock .recvfrom (1600 )
208
203
209
204
if addr != self .peer_addr :
210
205
return
@@ -231,7 +226,6 @@ def run(self):
231
226
curr_flags = ALL_FLAGS
232
227
233
228
self .running = True
234
- self .step_cnt = 0
235
229
self .runtime_start = curr_ts_ms ()
236
230
237
231
while not self .train or self .running :
0 commit comments