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

Viewed 139

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 :

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 Answers

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.

Related