Skip to content

Instantly share code, notes, and snippets.

@larytet
Last active January 11, 2022 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larytet/06f73cbccfaddfa03cd1dd72b1c2f535 to your computer and use it in GitHub Desktop.
Save larytet/06f73cbccfaddfa03cd1dd72b1c2f535 to your computer and use it in GitHub Desktop.
Throttling bandwidth with Go

Throttling bandwidth with Go

Imagine a service that is serving big log files over raw TCP, you decided to implement simple QoS for an existing server.

The goal of the task is to create small Go package that would allow for throttling bandwidth for TCP connections.

Requirements:

  • keep it simple
    • think of it as open-source software that builds upon existing solutions
  • use only stdlib and/or supplementary repositories (golang.org/x/*)
  • the package should allow for:
    • setting bandwidth limit per server
    • setting bandwidth limit per connection
    • changing limits in runtime (applies to all existing connections)
  • for a 30s transfer sample consumed bandwidth should be accurate +/- 5%

Reasonable deadline for submitting a solution is 8 days. Questions, clarifications - please drop us an e-mail!

Links

@larytet
Copy link
Author

larytet commented Jan 11, 2022

Re https://github.com/efarrer/iothrottler

This is not the full solution, you need to give us a wrapper for net.Listener.
The code you linked may work, but there's too many channels for my taste, so I am afraid it will not pass the benchmarks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment