The Leaky Bucket Algorithm
This lesson gives an implementation and explanation of an algorithm that controls client-server communication using a buffer.
We'll cover the following...
Introduction
Consider the following client-server configuration. The client
goroutine performs an infinite loop that is receiving data from some source, perhaps a network; the data are read in buffers of type Buffer
. To avoid allocating and freeing buffers too much, it keeps a free list of them, and uses a buffered channel to represent them:
var freeList = make(chan *Buffer, 100)
This queue of reusable buffers is ...