本文是pensieve运行经验的第二篇,pensieve运行的主要错误和重点内容放在前篇中,点击可查看。
pensieve运行的经验1
while past_bandwidths[0] == 0.0:
IndexError: index 0 is out of bounds for axis 0 with size 0
上面的错误警示我们,在发送post请求测试pensieve中服务器的效果时,务必要从实际出发,我先前为了图方便,在postman中直接将发送数据设置为:
{“RebufferTime”:1,“lastquality”:1,“lastChunkFinishTime”:1,“lastChunkStartTime”:1,“lastChunkSize”:10,“buffer”:1,“lastRequest”:1}
这样lastChunkFinishTime=lastChunkStartTime。
由于原代码:
video_chunk_fetch_time = post_data['lastChunkFinishTime'] - post_data['lastChunkStartTime']
video_chunk_size = post_data['lastChunkSize']
try:
state[0, -1] = VIDEO_BIT_RATE[post_data['lastquality']] / float(np.max(VIDEO_BIT_RATE))
state[1, -1] = post_data['buffer'] / BUFFER_NORM_FACTOR
state[2, -1] = rebuffer_time / M_IN_K
state[3, -1] = float(video_chunk_size) / float(video_chunk_fetch_time) / M_IN_K # kilo byte / ms
state[4, -1] = np.minimum(video_chunk_remain, CHUNK_TIL_VIDEO_END_CAP) / float(CHUNK_TIL_VIDEO_END_CAP)
except ZeroDivisionError:
# this should occur VERY rarely (1 out of 3000), should be a dash issue
# in this case we ignore the observation and roll back to an eariler one
if len(self.s_batch) == 0:
state = [np.zeros((S_INFO, S_LEN))]
else:
state = np.array(self.s_batch[-1], copy=True)
past_bandwidths = state[3,-5:]
while past_bandwidths[0] == 0.0:
past_bandwidths = past_bandwidths[1:]
这就导致 在while 循环中,past_bandwidths 数组被切片为一个空数组。尝试访问 past_bandwidths 的第一个元素时会出现索引错误——因为空数组没有任何元素可供访问。
关于signal,直接点击这篇博客即可
简单介绍了项目中出现的signal.SIGALRM和signal.alarm(time)。
原本代码中:
VIDEO_BIT_RATE = [300,750,1200,1850,2850,4300] # Kbps
BITRATE_REWARD = [1, 2, 3, 12, 15, 20]
BITRATE_REWARD_MAP = {0: 0, 300: 1, 750: 2, 1200: 3, 1850: 12, 2850: 15, 4300: 20}
如果在我们自定义视频中应用算法,除了修改以上直接可见的部分,还应该注意修改以下部分的代码,否则将会出现许多IndexError: list index out of range错误,如下所示:
File "mpc_server.py", line 66, in get_chunk_size
sizes = {1: size_video1[index], 2: size_video2[index], 3: size_video3[index], 4: size_video4[index]}
IndexError: list index out of range
注意修改的部分:
def get_chunk_size(quality, index):
if ( index < 0 or index > 21 ):
return 0
# note that the quality and video labels are inverted (i.e., quality 8 is highest and this pertains to video1)
sizes = {0: size_video1[index], 1: size_video2[index], 2: size_video3[index], 3: size_video4[index]}
return sizes[quality]
CHUNK_COMBO_OPTIONS元素的添加应该注意,itertools.product([0,1,2,3], repeat=5)原来为itertools.product([0,1,2,3,4,5], repeat=5)。如果将视频比特率级别从6改成4,就应该减少。
def run(server_class=HTTPServer, port=8000, log_file_path=LOG_FILE):
np.random.seed(RANDOM_SEED)
if not os.path.exists(SUMMARY_DIR):
os.makedirs(SUMMARY_DIR)
# make chunk combination options
for combo in itertools.product([0,1,2,3], repeat=5):
CHUNK_COMBO_OPTIONS.append(combo)
否则将会使bitrate_sum += BITRATE_REWARD[chunk_quality]
报错:IndexError: list index out of range。
修改视频切片数量时,除了注释原有部分,添加自己的视频块切片大小的列表外,
# video chunk sizes
#size_video1 = [2354772, 2123065, 2177073, 2160877, 2233056, 1941625, 2157535, 2290172, 2055469, 2169201, 2173522, 2102452, 2209463, 2275376, 2005399, 2152483, 2289689, 2059512, 2220726, 2156729, 2039773,# 2176469, 2221506, 2044075, 2186790, 2105231, 2395588, 1972048, 2134614, 2164140, 2113193, 2147852, 2191074, 2286761, 2307787, 2143948, 1919781, 2147467, 2133870, 2146120, 2108491, 2184571, 2121928, 2219102#, 2124950, 2246506, 1961140, 2155012, 1433658]
#size_video2 = [1728879, 1431809, 1300868, 1520281, 1472558, 1224260, 1388403, 1638769, 1348011, 1429765, 1354548, 1519951, 1422919, 1578343, 1231445, 1471065, 1491626, 1358801, 1537156, 1336050, 1415116,# 1468126, 1505760, 1323990, 1383735, 1480464, 1547572, 1141971, 1498470, 1561263, 1341201, 1497683, 1358081, 1587293, 1492672, 1439896, 1139291, 1499009, 1427478, 1402287, 1339500, 1527299, 1343002, 1587250#, 1464921, 1483527, 1231456, 1364537, 889412]
#size_video3 = [1034108, 957685, 877771, 933276, 996749, 801058, 905515, 1060487, 852833, 913888, 939819, 917428, 946851, 1036454, 821631, 923170, 966699, 885714, 987708, 923755, 891604, 955231, 968026,# 874175, 897976, 905935, 1076599, 758197, 972798, 975811, 873429, 954453, 885062, 1035329, 1026056, 943942, 728962, 938587, 908665, 930577, 858450, 1025005, 886255, 973972, 958994, 982064, 830730, 846370,# 598850]
#size_video4 = [668286, 611087, 571051, 617681, 652874, 520315, 561791, 709534, 584846, 560821, 607410, 594078, 624282, 687371, 526950, 587876, 617242, 581493, 639204, 586839, 601738, 616206, 656471, 536667#, 587236, 590335, 696376, 487160, 622896, 641447, 570392, 620283, 584349, 670129, 690253, 598727, 487812, 575591, 605884, 587506, 566904, 641452, 599477, 634861, 630203, 638661, 538612, 550906, 391450]
#size_video5 = [450283, 398865, 350812, 382355, 411561, 318564, 352642, 437162, 374758, 362795, 353220, 405134, 386351, 434409, 337059, 366214, 360831, 372963, 405596, 350713, 386472, 399894, 401853, 343800#, 359903, 379700, 425781, 277716, 400396, 400508, 358218, 400322, 369834, 412837, 401088, 365161, 321064, 361565, 378327, 390680, 345516, 384505, 372093, 438281, 398987, 393804, 331053, 314107, 255954]
#size_video6 = [181801, 155580, 139857, 155432, 163442, 126289, 153295, 173849, 150710, 139105, 141840, 156148, 160746, 179801, 140051, 138313, 143509, 150616, 165384, 140881, 157671, 157812, 163927, 137654#, 146754, 153938, 181901, 111155, 153605, 149029, 157421, 157488, 143881, 163444, 179328, 159914, 131610, 124011, 144254, 149991, 147968, 161857, 145210, 172312, 167025, 160064, 137507, 118421, 112270]
还应该注意以下,如:
def get_chunk_size(quality, index):
if ( index < 0 or index > 21 ):
return 0
# note that the quality and video labels are inverted (i.e., quality 8 is highest and this pertains to video1)
sizes = {0: size_video1[index], 1: size_video2[index], 2: size_video3[index], 3: size_video4[index]}
return sizes[quality]
这里要对index进行限定,比如当前视频切片只有22个,那么index>21的就要return 0。根据后面的代码,设置return 0最为贴切。