From fad231003fb265ddbf53106915566448f5fbeb81 Mon Sep 17 00:00:00 2001 From: mrocajr Date: Wed, 17 May 2017 10:20:39 -0400 Subject: [PATCH 1/3] Added throttle-server from videojs-contrib-hls --- switcher/network-trace.txt | 390 ++++++++++++++++++++++++++++++++++++ switcher/throttle-server.js | 156 +++++++++++++++ 2 files changed, 546 insertions(+) create mode 100644 switcher/network-trace.txt create mode 100755 switcher/throttle-server.js diff --git a/switcher/network-trace.txt b/switcher/network-trace.txt new file mode 100644 index 0000000..5cec88f --- /dev/null +++ b/switcher/network-trace.txt @@ -0,0 +1,390 @@ +1297715985 5276720 59.894124 10.629597 254601 1010 +1297715986 5277740 59.894132 10.629601 314236 1020 +1297715987 5278770 59.894135 10.629618 104796 1030 +1297715988 5279800 59.894141 10.629639 173687 1030 +1297715989 5280999 59.894146 10.629678 139938 1199 +1297715990 5282000 59.894143 10.629713 154375 1001 +1297715991 5283210 59.894129 10.629727 233790 1210 +1297715992 5284240 59.894102 10.629755 193145 1030 +1297715994 5285410 59.894072 10.629728 219496 1170 +1297715995 5286631 59.894015 10.62962 240782 1221 +1297715996 5287810 59.893981 10.629537 252258 1179 +1297715997 5288812 59.89394 10.62945 329688 1002 +1297715998 5289820 59.893903 10.629349 248922 1008 +1297715999 5290870 59.893862 10.629263 181127 1050 +1297716000 5291871 59.893817 10.629158 233479 1001 +1297716001 5292881 59.893785 10.629057 245447 1010 +1297716002 5294070 59.893751 10.628974 240750 1189 +1297716003 5295270 59.893716 10.628908 323609 1200 +1297716004 5296271 59.893685 10.628842 255456 1001 +1297716005 5297272 59.893662 10.62878 244783 1001 +1297716006 5298290 59.893651 10.628721 268382 1018 +1297716007 5299291 59.893662 10.628594 209232 1001 +1297716008 5300292 59.893662 10.628594 223042 1001 +1297716009 5301301 59.893692 10.628531 261720 1009 +1297716010 5302302 59.893779 10.628375 256746 1001 +1297716012 5303310 59.893779 10.628375 261257 1008 +1297716013 5304321 59.893898 10.628176 271287 1011 +1297716014 5305340 59.893964 10.62807 246284 1019 +1297716015 5306430 59.893964 10.62807 269860 1090 +1297716016 5307540 59.894106 10.627843 277255 1110 +1297716017 5308641 59.894181 10.627722 273966 1101 +1297716018 5309720 59.894181 10.627722 270316 1079 +1297716019 5310821 59.894339 10.627446 285189 1101 +1297716020 5311822 59.894419 10.627325 254999 1001 +1297716021 5312823 59.894495 10.627187 257355 1001 +1297716022 5313831 59.894577 10.627048 236596 1008 +1297716023 5314832 59.894652 10.626928 268820 1001 +1297716024 5315841 59.894719 10.626804 260337 1009 +1297716025 5316851 59.894776 10.626659 300960 1010 +1297716026 5317860 59.894823 10.626546 261711 1009 +1297716027 5318873 59.894871 10.626415 220063 1013 +1297716028 5319880 59.894914 10.626285 191520 1007 +1297716029 5320890 59.894968 10.626175 110568 1010 +1297716030 5321891 59.89504 10.626089 233928 1001 +1297716031 5322892 59.895124 10.626025 342539 1001 +1297716032 5323901 59.895216 10.625998 373805 1009 +1297716033 5324911 59.89531 10.625993 337991 1010 +1297716034 5325912 59.895416 10.625991 478514 1001 +1297716035 5326913 59.895529 10.626009 448818 1001 +1297716036 5327915 59.895645 10.626028 430519 1002 +1297716037 5328962 59.895759 10.626029 405278 1047 +1297716038 5329963 59.895872 10.626048 465176 1001 +1297716039 5330971 59.895976 10.626063 393461 1008 +1297716040 5331972 59.896083 10.626061 322404 1001 +1297716041 5332991 59.896195 10.62608 374338 1019 +1297716042 5333992 59.8963 10.626095 448872 1001 +1297716043 5334993 59.896405 10.62611 553223 1001 +1297716044 5336182 59.896517 10.626129 499230 1189 +1297716045 5337183 59.896617 10.626145 477739 1001 +1297716046 5338192 59.896722 10.62616 438451 1009 +1297716047 5339281 59.896815 10.626172 292212 1089 +1297716048 5340282 59.896907 10.626184 435502 1001 +1297716049 5341283 59.897105 10.626212 554424 1001 +1297716051 5342361 59.897105 10.626212 539067 1078 +1297716052 5343362 59.897322 10.626246 523744 1001 +1297716053 5344373 59.897442 10.626268 542623 1011 +1297716054 5345380 59.897442 10.626268 379774 1007 +1297716055 5346381 59.8977 10.626297 261731 1001 +1297716056 5347382 59.897826 10.626302 313272 1001 +1297716057 5348401 59.897826 10.626302 197777 1019 +1297716058 5349491 59.898102 10.626264 197058 1090 +1297716059 5350492 59.89825 10.62624 247608 1001 +1297716060 5351500 59.89825 10.62624 185927 1008 +1297716061 5352511 59.898561 10.626178 220248 1011 +1297716062 5353521 59.898723 10.626139 177332 1010 +1297716063 5354531 59.898723 10.626139 207936 1010 +1297716064 5355541 59.899042 10.62608 201712 1010 +1297716065 5356551 59.89919 10.626056 139536 1010 +1297716066 5357553 59.89919 10.626056 200282 1002 +1297716067 5358751 59.899493 10.62599 453381 1198 +1297716068 5359752 59.899648 10.625949 366806 1001 +1297716069 5360753 59.899797 10.625925 368143 1001 +1297716070 5361761 59.899939 10.62588 348940 1008 +1297716071 5362772 59.900081 10.625835 354187 1011 +1297716072 5363862 59.900225 10.625772 370885 1090 +1297716073 5364991 59.900369 10.62571 320406 1129 +1297716074 5365992 59.900511 10.625626 376200 1001 +1297716075 5366993 59.900655 10.625564 321876 1001 +1297716076 5368002 59.900792 10.62548 264787 1009 +1297716077 5369022 59.900933 10.6254 386542 1020 +1297716078 5370023 59.901069 10.625334 401120 1001 +1297716079 5371024 59.901198 10.625265 352356 1001 +1297716080 5372031 59.901322 10.625196 336314 1007 +1297716081 5373071 59.901433 10.625141 380175 1040 +1297716082 5374073 59.901534 10.625101 376200 1002 +1297716083 5375081 59.901633 10.625095 277190 1008 +1297716084 5376082 59.901725 10.625107 317376 1001 +1297716085 5377101 59.901807 10.625151 119620 1019 +1297716086 5378102 59.901898 10.625181 180576 1001 +1297716087 5379151 59.901988 10.625228 186393 1049 +1297716088 5380152 59.902083 10.625314 194256 1001 +1297716090 5381331 59.902167 10.625431 159491 1179 +1297716091 5382341 59.902329 10.625684 102600 1010 +1297716092 5383351 59.902407 10.625819 165528 1010 +1297716093 5384361 59.902407 10.625819 130430 1010 +1297716094 5385371 59.902551 10.626047 162792 1010 +1297716095 5386393 59.902617 10.62614 183312 1022 +1297716096 5387401 59.902617 10.62614 157281 1008 +1297716097 5388402 59.902725 10.626303 199728 1001 +1297716098 5389413 59.902785 10.626414 195624 1011 +1297716099 5390421 59.902785 10.626414 133971 1008 +1297716100 5391432 59.902941 10.626645 169632 1011 +1297716101 5392441 59.903031 10.626784 171000 1009 +1297716102 5393462 59.903031 10.626784 161755 1021 +1297716103 5394463 59.903228 10.627102 214776 1001 +1297716104 5395501 59.903336 10.627282 180760 1038 +1297716105 5396511 59.903336 10.627282 186048 1010 +1297716106 5397522 59.90357 10.627649 179208 1011 +1297716107 5398532 59.903689 10.627832 152359 1010 +1297716108 5399541 59.903689 10.627832 113386 1009 +1297716109 5400543 59.903922 10.628216 131328 1002 +1297716110 5401544 59.904029 10.628396 221017 1001 +1297716111 5402660 59.904029 10.628396 298878 1116 +1297716112 5403662 59.904258 10.628725 322714 1002 +1297716113 5404682 59.904368 10.628869 307691 1020 +1297716114 5405693 59.904368 10.628869 347833 1011 +1297716115 5406702 59.904606 10.629092 372904 1009 +1297716116 5407703 59.904725 10.629185 298741 1001 +1297716117 5408711 59.904725 10.629185 180576 1008 +1297716118 5409772 59.904994 10.629326 106704 1061 +1297716119 5410774 59.905131 10.629352 268252 1002 +1297716120 5411802 59.905263 10.629377 225344 1028 +1297716121 5412812 59.905398 10.629367 192888 1010 +1297716122 5414012 59.905528 10.629371 157495 1200 +1297716123 5415103 59.905663 10.629362 142272 1091 +1297716124 5416114 59.905791 10.629348 202464 1011 +1297716125 5417132 59.905932 10.629321 127970 1018 +1297716126 5418162 59.906073 10.629294 150480 1030 +1297716127 5419182 59.906213 10.629266 56088 1020 +1297716129 5420392 59.906353 10.629256 54451 1210 +1297716130 5421401 59.90664 10.62924 205200 1009 +1297716131 5422402 59.906791 10.629233 223056 1001 +1297716132 5423403 59.906791 10.629233 289833 1001 +1297716133 5424405 59.907092 10.629203 310252 1002 +1297716134 5425412 59.907239 10.629196 210278 1007 +1297716135 5426422 59.907239 10.629196 197270 1010 +1297716136 5427423 59.907542 10.629131 263528 1001 +1297716137 5428432 59.907698 10.62911 220663 1009 +1297716138 5429482 59.907698 10.62911 157320 1050 +1297716139 5430492 59.908001 10.629005 75932 1010 +1297716140 5431493 59.908134 10.628975 187416 1001 +1297716141 5432494 59.908134 10.628975 137698 1001 +1297716142 5433513 59.908392 10.628875 199728 1019 +1297716143 5434515 59.9085163333333 10.6287873333333 189457 1002 +1297716144 5435522 59.9086406666667 10.6286996666667 209734 1007 +1297716145 5436532 59.908765 10.628612 240768 1010 +1297716146 5437542 59.908901 10.628493 142917 1010 +1297716147 5438552 59.908901 10.628493 160056 1010 +1297716148 5439553 59.909178 10.628309 103883 1001 +1297716149 5440562 59.909312 10.62826 123120 1009 +1297716150 5441762 59.909455 10.628215 97084 1200 +1297716151 5442763 59.909602 10.62817 138168 1001 +1297716152 5443772 59.909756 10.628129 203330 1009 +1297716153 5444823 59.909909 10.628105 170247 1051 +1297716154 5445824 59.910071 10.628066 316008 1001 +1297716155 5446825 59.910232 10.628045 340363 1001 +1297716156 5447832 59.910394 10.628007 334521 1007 +1297716157 5448845 59.910563 10.62799 288252 1013 +1297716158 5449852 59.91073 10.62799 251200 1007 +1297716159 5450873 59.910892 10.62799 173736 1021 +1297716160 5451882 59.911064 10.628028 189042 1009 +1297716162 5453333 59.911232 10.628049 218934 1451 +1297716163 5454372 59.9113998076923 10.6281021730769 233096 1039 +1297716164 5455373 59.9115676153846 10.6281553461538 263302 1001 +1297716165 5456814 59.9117354230769 10.6282085192308 330690 1441 +1297716166 5457816 59.9119032307692 10.6282616923077 354312 1002 +1297716167 5458823 59.9120710384615 10.6283148653846 306100 1007 +1297716168 5459824 59.9122388461538 10.6283680384615 325584 1001 +1297716169 5460833 59.9124066538462 10.6284212115385 237731 1009 +1297716170 5461835 59.9125744615385 10.6284743846154 314640 1002 +1297716171 5462851 59.9127422692308 10.6285275576923 285961 1016 +1297716172 5463932 59.9129100769231 10.6285807307692 273738 1081 +1297716173 5464933 59.9130778846154 10.6286339038462 325584 1001 +1297716174 5466003 59.9132456923077 10.6286870769231 290305 1070 +1297716176 5467713 59.9135813076923 10.6287934230769 32800 1710 +1297716177 5468723 59.9137491153846 10.6288465961538 693994 1010 +1297716178 5469733 59.9139169230769 10.6288997692308 268128 1010 +1297716179 5470913 59.9140847307692 10.6289529423077 253851 1180 +1297716180 5471915 59.9142525384615 10.6290061153846 290016 1002 +1297716181 5472923 59.9144203461538 10.6290592884615 285326 1008 +1297716182 5473933 59.9145881538462 10.6291124615385 241929 1010 +1297716183 5474942 59.9147559615385 10.6291656346154 298224 1009 +1297716184 5475943 59.9149237692308 10.6292188076923 260566 1001 +1297716185 5476944 59.9150915769231 10.6292719807692 228537 1001 +1297716186 5478003 59.9152593846154 10.6293251538462 282048 1059 +1297716187 5479005 59.9154271923077 10.6293783269231 214776 1002 +1297716188 5480013 59.915595 10.6294315 213421 1008 +1297716189 5481193 59.9157628076923 10.6294846730769 315263 1180 +1297716190 5482194 59.9159306153846 10.6295378461538 255816 1001 +1297716191 5483213 59.9160984230769 10.6295910192308 235140 1019 +1297716192 5484233 59.9162662307692 10.6296441923077 181076 1020 +1297716193 5485695 59.9164340384615 10.6296973653846 6840 1462 +1297716194 5486703 59.9166018461538 10.6297505384615 254448 1008 +1297716195 5487704 59.9167696538462 10.6298037115385 195419 1001 +1297716196 5488714 59.9169374615385 10.6298568846154 211967 1010 +1297716197 5489715 59.9171052692308 10.6299100576923 244855 1001 +1297716198 5490723 59.9172730769231 10.6299632307692 265801 1008 +1297716199 5491734 59.9174408846154 10.6300164038462 272756 1011 +1297716200 5492735 59.9176086923077 10.6300695769231 333792 1001 +1297716201 5493743 59.9177765 10.63012275 241487 1008 +1297716202 5494744 59.9179443076923 10.6301759230769 254515 1001 +1297716203 5495745 59.9181121153846 10.6302290961538 234461 1001 +1297716204 5496755 59.9182799230769 10.6302822692308 267481 1010 +1297716205 5497756 59.9184477307692 10.6303354423077 384408 1001 +1297716206 5498763 59.9186155384615 10.6303886153846 296276 1007 +1297716207 5499764 59.9187833461538 10.6304417884615 317376 1001 +1297716208 5500774 59.9189511538462 10.6304949615385 318744 1010 +1297716209 5501775 59.9191189615385 10.6305481346154 264347 1001 +1297716210 5502776 59.9192867692308 10.6306013076923 282092 1001 +1297716211 5503783 59.9194545769231 10.6306544807692 259920 1007 +1297716212 5504784 59.9196223846154 10.6307076538462 167958 1001 +1297716214 5505794 59.919958 10.630814 172368 1010 +1297716215 5506795 59.920014 10.631122 113566 1001 +1297716216 5507803 59.920113 10.631383 198360 1008 +1297716217 5508813 59.920224 10.63163 154931 1010 +1297716218 5509814 59.920347 10.631846 258552 1001 +1297716219 5510823 59.920476 10.632026 211935 1009 +1297716220 5511824 59.920615 10.632192 229164 1001 +1297716221 5512834 59.920758 10.632343 220248 1010 +1297716222 5513843 59.920895 10.632474 150193 1009 +1297716223 5514844 59.92104 10.632608 65664 1001 +1297716224 5515845 59.921191 10.632725 149112 1001 +1297716225 5517034 59.921345469697 10.6328061363636 291830 1189 +1297716226 5518035 59.9214999393939 10.6328872727273 307800 1001 +1297716227 5519043 59.9216544090909 10.6329684090909 269496 1008 +1297716228 5520044 59.9218088787879 10.6330495454545 235539 1001 +1297716229 5521053 59.9219633484849 10.6331306818182 223713 1009 +1297716230 5522054 59.9221178181818 10.6332118181818 222984 1001 +1297716231 5523055 59.9222722878788 10.6332929545455 148601 1001 +1297716232 5524235 59.9224267575758 10.6333740909091 250628 1180 +1297716233 5525263 59.9225812272727 10.6334552272727 186048 1028 +1297716234 5526494 59.9227356969697 10.6335363636364 82637 1231 +1297716235 5527634 59.9228901666667 10.6336175 280537 1140 +1297716236 5528635 59.9230446363636 10.6336986363636 451441 1001 +1297716237 5529815 59.9231991060606 10.6337797727273 523149 1180 +1297716238 5530824 59.9233535757576 10.6338609090909 453561 1009 +1297716239 5531825 59.9235080454545 10.6339420454545 299620 1001 +1297716240 5532864 59.9236625151515 10.6340231818182 376389 1039 +1297716241 5533866 59.9238169848485 10.6341043181818 418222 1002 +1297716242 5534903 59.9239714545455 10.6341854545455 493724 1037 +1297716243 5535904 59.9241259242424 10.6342665909091 372640 1001 +1297716244 5536916 59.9242803939394 10.6343477272727 521071 1012 +1297716245 5537924 59.9244348636364 10.6344288636364 452756 1008 +1297716246 5538964 59.9245893333333 10.63451 167758 1040 +1297716247 5539974 59.9247438030303 10.6345911363636 262656 1010 +1297716248 5540975 59.9248982727273 10.6346722727273 287060 1001 +1297716249 5541976 59.9250527424242 10.6347534090909 333792 1001 +1297716250 5542984 59.9252072121212 10.6348345454545 371842 1008 +1297716251 5543985 59.9253616818182 10.6349156818182 448160 1001 +1297716252 5544986 59.9255161515152 10.6349968181818 417660 1001 +1297716253 5545987 59.9256706212121 10.6350779545455 468521 1001 +1297716254 5547005 59.9258250909091 10.6351590909091 588202 1018 +1297716255 5548006 59.9259795606061 10.6352402272727 561251 1001 +1297716256 5549014 59.926134030303 10.6353213636364 564144 1008 +1297716257 5550015 59.9262885 10.6354025 569088 1001 +1297716258 5551016 59.926442969697 10.6354836363636 469963 1001 +1297716259 5552019 59.9265974393939 10.6355647727273 567259 1003 +1297716260 5553024 59.9267519090909 10.6356459090909 459648 1005 +1297716261 5554144 59.9269063787879 10.6357270454545 440357 1120 +1297716262 5555289 59.9270608484848 10.6358081818182 25992 1145 +1297716263 5556314 59.9272153181818 10.6358893181818 891326 1025 +1297716264 5557315 59.9273697878788 10.6359704545455 513000 1001 +1297716265 5558316 59.9275242575758 10.6360515909091 421882 1001 +1297716266 5559319 59.9276787272727 10.6361327272727 421995 1002 +1297716267 5560321 59.9278331969697 10.6362138636364 418527 1002 +1297716268 5561325 59.9279876666667 10.636295 547289 1004 +1297716269 5562339 59.9281421363636 10.6363761363636 595894 1014 +1297716270 5563341 59.9282966060606 10.6364572727273 552581 1002 +1297716271 5564345 59.9284510757576 10.6365384090909 536823 1004 +1297716272 5565346 59.9286055454545 10.6366195454545 407310 1001 +1297716273 5566347 59.9287600151515 10.6367006818182 514368 1001 +1297716274 5567354 59.9289144848485 10.6367818181818 430457 1007 +1297716276 5569106 59.9292234242424 10.6369440909091 313379 1752 +1297716277 5570234 59.9293778939394 10.6370252272727 1262164 1128 +1297716278 5571235 59.9295323636364 10.6371063636364 519840 1001 +1297716279 5572246 59.9296868333333 10.6371875 586872 1011 +1297716280 5573255 59.9298413030303 10.6372686363636 559699 1009 +1297716281 5574256 59.9299957727273 10.6373497727273 478911 1001 +1297716282 5575257 59.9301502424242 10.6374309090909 528048 1001 +1297716283 5576263 59.9303047121212 10.6375120454545 432252 1006 +1297716284 5577265 59.9304591818182 10.6375931818182 475081 1001 +1297716285 5578266 59.9306136515152 10.6376743181818 499320 1001 +1297716286 5579267 59.9307681212121 10.6377554545455 461694 1001 +1297716287 5580275 59.9309225909091 10.6378365909091 488376 1008 +1297716290 5581635 59.931386 10.63808 381112 1360 +1297716291 5582637 59.931386 10.63808 441864 1002 +1297716292 5583645 59.930784 10.640656 440496 1008 +1297716294 5586075 59.930304 10.642906 148788 2430 +1297716295 5587174 59.930102 10.643952 828676 1099 +1297716296 5588175 59.929914 10.644913 195624 1001 +1297716297 5589185 59.929756 10.64581 240768 1010 +1297716298 5590205 59.929613 10.646676 168264 1020 +1297716299 5591225 59.929489 10.647474 164160 1020 +1297716301 5592465 59.929285 10.648958 123120 1240 +1297716302 5593605 59.929207 10.649644 38304 1140 +1297716303 5594615 59.929207 10.649644 189603 1010 +1297716304 5595625 59.929087 10.650902 199728 1010 +1297716305 5596636 59.929054 10.651491 191649 1011 +1297716306 5597646 59.929054 10.651491 250344 1010 +1297716307 5598655 59.928997 10.652587 211390 1009 +1297716308 5599656 59.928991 10.653095 285912 1001 +1297716309 5600665 59.928991 10.653095 209787 1009 +1297716310 5601816 59.928994 10.654063 287441 1151 +1297716311 5602851 59.929004 10.654522 262656 1035 +1297716312 5603855 59.929015 10.654964 133892 1004 +1297716313 5604956 59.92904 10.655391 235557 1101 +1297716314 5605957 59.929074 10.655804 250344 1001 +1297716315 5606965 59.9291 10.656214 222264 1008 +1297716316 5607975 59.929127 10.656624 198506 1010 +1297716317 5608985 59.929155 10.657016 214628 1010 +1297716318 5609995 59.92919 10.657412 239400 1010 +1297716319 5611005 59.929219 10.657786 167518 1010 +1297716320 5612015 59.929244 10.658175 198360 1010 +1297716321 5613016 59.929273 10.65855 168801 1001 +1297716322 5614017 59.929296 10.658903 212805 1001 +1297716323 5615075 59.929318 10.659275 211125 1058 +1297716324 5616245 59.929353 10.659632 281807 1170 +1297716325 5617247 59.929368 10.659982 298224 1002 +1297716326 5618248 59.929391 10.660336 243517 1001 +1297716327 5619255 59.929415 10.660672 244856 1007 +1297716328 5620265 59.929444 10.661008 257184 1010 +1297716329 5621266 59.929481 10.661348 206251 1001 +1297716330 5622267 59.929519 10.66167 254235 1001 +1297716331 5623286 59.929612 10.662317 257068 1019 +1297716332 5624295 59.929612 10.662317 258383 1009 +1297716333 5625296 59.929662 10.662642 214948 1001 +1297716335 5626307 59.929781 10.663261 220248 1011 +1297716336 5627315 59.929781 10.663261 122589 1008 +1297716337 5628326 59.929918 10.663869 132696 1011 +1297716338 5629335 59.930004 10.664151 125856 1009 +1297716339 5630337 59.930004 10.664151 132116 1002 +1297716340 5631338 59.930178 10.664698 222984 1001 +1297716341 5632345 59.930274 10.664966 157748 1007 +1297716342 5633358 59.930274 10.664966 194256 1013 +1297716343 5634375 59.930467 10.665482 135527 1017 +1297716344 5635395 59.930557 10.665729 106704 1020 +1297716345 5636566 59.930557 10.665729 56088 1171 +1297716346 5637725 59.930747 10.666227 39672 1159 +1297716347 5638749 59.93085 10.66646 46512 1024 +1297716348 5639755 59.930944 10.666708 57456 1006 +1297716349 5640785 59.93104 10.666958 49248 1030 +1297716350 5641795 59.931142 10.667209 40781 1010 +1297716351 5642825 59.931244 10.667442 56088 1030 +1297716352 5643845 59.931341 10.667692 60192 1020 +1297716353 5644856 59.931435 10.66794 41755 1011 +1297716354 5645865 59.931533 10.668173 69768 1009 +1297716355 5646876 59.931635 10.668423 76608 1011 +1297716356 5647885 59.931737 10.668656 65118 1009 +1297716357 5648886 59.931839 10.668907 69638 1001 +1297716358 5649895 59.931945 10.669143 106704 1009 +1297716359 5650916 59.932046 10.669394 75593 1021 +1297716360 5651935 59.932149 10.669627 95760 1019 +1297716361 5652985 59.93225 10.669878 63507 1050 +1297716362 5654006 59.932356 10.670114 74326 1021 +1297716363 5655015 59.932457 10.670365 83448 1009 +1297716364 5656016 59.932559 10.670615 67667 1001 +1297716365 5657036 59.932664 10.670852 75607 1020 +1297716366 5658195 59.932766 10.671102 89283 1159 +1297716368 5659366 59.932979 10.671572 72504 1171 +1297716369 5660375 59.932979 10.671572 55203 1009 +1297716370 5661456 59.933179 10.672056 62488 1081 +1297716371 5662465 59.933289 10.672292 82080 1009 +1297716372 5663485 59.933289 10.672292 58050 1020 +1297716373 5664495 59.933493 10.672776 73872 1010 +1297716374 5665496 59.933591 10.673009 50357 1001 +1297716375 5666505 59.933591 10.673009 71136 1009 +1297716376 5667517 59.933804 10.673478 57400 1012 +1297716377 5668556 59.933906 10.673729 49248 1039 +1297716378 5669595 59.933906 10.673729 44369 1039 +1297716379 5670616 59.934111 10.674195 38304 1021 +1297716380 5671646 59.934206 10.674425 36936 1030 +1297716381 5673216 59.934308 10.674676 4104 1570 +1297716400 5692178 59.936109 10.679293 10944 18962 +1297716402 5694146 59.936246 10.679701 2095 1968 +1297716404 5695966 59.936366 10.680029 19152 1820 +1297716405 5697056 59.936424 10.680157 34200 1090 +1297716406 5698067 59.93647 10.680244 26598 1011 +1297716407 5699136 59.93651 10.68031 31910 1069 +1297716408 5700156 59.936528 10.680335 43776 1020 +1297716409 5700522 59.936536 10.680338 10773 366 diff --git a/switcher/throttle-server.js b/switcher/throttle-server.js new file mode 100755 index 0000000..5531a14 --- /dev/null +++ b/switcher/throttle-server.js @@ -0,0 +1,156 @@ +#!/usr/bin/env node +'use strict'; + +const http = require('http'); +const url = require('url'); +const fs = require('fs'); +const path = require('path'); +let networkTrace = 'network-trace.txt'; +const port = 9000; +let firstRequestTime; + +if (Number.isFinite(process.argv[2])) { + port = Number(process.argv[2]); + if (process.argv[3]) { + networkTrace = process.argv[3]; + } +} else if (process.argv[2]) { + networkTrace = process.argv[2]; +} + +const throttleConfig = fs.readFileSync(networkTrace).toString() + .split('\n') + .map((line) => + line.split(' ') + .slice(-2) + .map(Number)); + +// Just trust that this code works... +const getBytesForTimespan = (start, end) => { + let acc = 0; + let i = 0; + let relativeStart = start - firstRequestTime; + let duration = end - start; + let bytesSent = 0; + let tcLength = throttleConfig.length; + + // Find start + do { + acc += throttleConfig[i % tcLength][1]; + } while (acc < relativeStart && ++i); + + let timeRemaining = acc - relativeStart; + bytesSent = throttleConfig[i % tcLength][0] * (timeRemaining / throttleConfig[i % tcLength][1]); + + // Find end + acc = timeRemaining - throttleConfig[i % tcLength][1]; + let j = i; + do { + acc += throttleConfig[j % tcLength][1]; + + if (j > i) { + bytesSent += throttleConfig[j % tcLength][0]; + } + } while (acc < duration && ++j); + + let timeOverage = acc - duration; + bytesSent -= throttleConfig[j % tcLength][0] * (timeOverage / throttleConfig[j % tcLength][1]); + + return Math.floor(bytesSent); +}; + +const writeSlowly = (req, res, data) => { + let ended = false; + let start = Date.now(); + + req.on('close', () => { + // request closed unexpectedly + ended = true; +}); + + setTimeout(function writer(offset) { + if (offset === null) { + res.end(); + return; + } + if (ended) { + console.log('request aborted by client'); + return; + } + + let bytesToSend = getBytesForTimespan(start, Date.now()); + let chunkEnd = offset + bytesToSend; + start = Date.now(); + + if (chunkEnd >= data.length) { + res.write(data.slice(offset)); + setTimeout(writer, 10, null); + } else { + res.write(data.slice(offset, chunkEnd)); + setTimeout(writer, 10, chunkEnd); + } + }, 1, 0); +}; + +// maps file extention to MIME type +// we only care about these two types +const map = { + '.ts': 'application/vnd.apple.mpegurl', + '.m3u8': 'application/x-mpegurl' +}; + +const setHeaders = (res, ext) => { + // Website you wish to allow to connect + res.setHeader('Access-Control-Allow-Origin', '*'); + // Request methods you wish to allow + res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE'); + // Request headers you wish to allow + res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type'); + // Set to true if you need the website to include cookies in the requests sent + // to the API (e.g. in case you use sessions) + res.setHeader('Access-Control-Allow-Credentials', true); + // Set the default to application/octet-stream in the event of a key request + // With the exception of manifests, we should never be sending text + res.setHeader('Content-type', map[ext] || 'application/octet-stream' ); +}; + +http.createServer(function (req, res) { + console.log(`${req.method} ${req.url}`); + + // parse URL + const parsedUrl = url.parse(req.url); + // extract URL path + let pathname = `.${parsedUrl.pathname}`; + // based on the URL path, extract the file extention. e.g. .js, .doc, ... + const ext = path.parse(pathname).ext; + + fs.exists(pathname, function (exist) { + if(!exist || fs.statSync(pathname).isDirectory()) { + // if the file is not found, return 404 + res.statusCode = 404; + res.end(`File ${pathname} not found!`); + return; + } + + // read file from file system + fs.readFile(pathname, function(err, data){ + if(err){ + res.statusCode = 500; + res.end(`Error getting the file: ${err}.`); + } else { + setHeaders(res, ext); + if (ext === '.m3u8') { + // if the file is found, set Content-type and send data + res.end(data); + } else { + if (!firstRequestTime) { + firstRequestTime = Date.now(); + } + writeSlowly(req, res, data); + } + } + }); + }); +}).listen(parseInt(port)); + +console.log(`Murphy throttler on port ${port}`); From f340a5298a3e702645dbbea83fd818d346f740ac Mon Sep 17 00:00:00 2001 From: mrocajr Date: Wed, 17 May 2017 10:25:58 -0400 Subject: [PATCH 2/3] Launch throttler from npm run throttle --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 73bc0f3..e3725f4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "bin": "./murphy", "scripts": { "test": "node ./test/live.test.js", - "start": "node murphy" + "start": "node murphy", + "throttle": "node ./switcher/throttle-server.js ./switcher/network-trace.txt" }, "dependencies": { "express": "~3.3.4", From 7fced6f41a6eb537f3c13e70362aa738ff42b9d1 Mon Sep 17 00:00:00 2001 From: mrocajr Date: Wed, 17 May 2017 10:39:47 -0400 Subject: [PATCH 3/3] Match spacing of hls project --- switcher/throttle-server.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/switcher/throttle-server.js b/switcher/throttle-server.js index 5531a14..fbae10e 100755 --- a/switcher/throttle-server.js +++ b/switcher/throttle-server.js @@ -19,11 +19,11 @@ if (Number.isFinite(process.argv[2])) { } const throttleConfig = fs.readFileSync(networkTrace).toString() - .split('\n') - .map((line) => - line.split(' ') - .slice(-2) - .map(Number)); + .split('\n') + .map((line) => + line.split(' ') + .slice(-2) + .map(Number)); // Just trust that this code works... const getBytesForTimespan = (start, end) => { @@ -66,7 +66,7 @@ const writeSlowly = (req, res, data) => { req.on('close', () => { // request closed unexpectedly ended = true; -}); + }); setTimeout(function writer(offset) { if (offset === null) {