How to slow down a service-worker to simulate 56k or 2G 3G slow connection

ε祈祈猫儿з 提交于 2021-01-20 07:53:25

问题


Here is my use-case :

I'me developping Static Site Generator and stuff for them.

I would like to host on static pages (like gitlab-pages or github-pages) some demo of my stuff.

So I can't use server-side tricks to simulate slow connexion.

My demo page should look like this :

  • see my stuff in normal mode
  • see my stuff before optimisation with a simulated 56k connection
  • see my stuff after optimisation with a simulated 56k connection

I've not found any service-worker built for this.

Any Idea where i can found one or how i can build one for this ?


回答1:


The tc or Traffic Control command should be able to handle the job for you. tc can do a lot but it sounds like you just need to to 'shape` traffic:

SHAPING When traffic is shaped, its rate of transmission is under control. Shaping may be more than lowering the available bandwidth - it is also used to smooth out bursts in traffic for better network behaviour. Shaping occurs on egress.

Simulating something like cell delay is pretty easy, in the below example I inject a delay of 100 +/- 10ms on interface eth1.

tc qdisc add dev eth1 root netem delay 100ms 10ms

Naturally this is annoying because it is on a primary interface and it does not handle throughput limiting. To do that you need to go into how tc works more (parent/child queues, etc). This writeup explains how to throttle the bandwidth, so if you do that and then add the delay mentioned above, then you should have a pretty solid emulation.



来源:https://stackoverflow.com/questions/65485346/how-to-slow-down-a-service-worker-to-simulate-56k-or-2g-3g-slow-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!