Skip to content

Commit

Permalink
Documented reasons for enabling buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
onitake committed Feb 7, 2018
1 parent d530c59 commit f50c017
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ load demands.
## Architecture

restreamer is written in [Go](https://golang.org/), a very versatile
programming language, and suited perfectly for the development of
network services.
programming language. The built-in network layer makes it a first-class
choice for a streaming server.

These are the key components:
* util - a small utility library
Expand Down Expand Up @@ -163,3 +163,24 @@ Using the built-in Go profiler can be more useful to watch memory usage.
You should check out the `profiler` branch, it opens a separate web
server on port 6060 that Go pprof can connect to. See [net/http/pprof](https://golang.org/pkg/net/http/pprof/)
for instructions on its usage.

### Syscall Load

Live streaming services like restreamer require realtime or near-realtime
operation. Latency should be minimised, highlighting the importance of
small buffers. Unfortunately, small buffers will increase the number of
syscalls needed to feed data to the remote clients.

In light of the recently published [speculative execution exploits
affecting Intel CPUs](https://meltdownattack.com/), high syscall rates will
have a devastating effect on performance on these CPUs due to
mitigations in the operating system.

For this reason, restreamer is relying on buffered I/O, with default buffer
sizes as set in the Go http package. In the current implementation,
a 2KiB and a 4KiB buffer is used. This should give a good compromise
between moderate latency and limited system load.

Even with these buffers, performance loss compared with unmitigated systems
is considerable. If this is unacceptable, it is highly recommended to run
restreamer on a system that does not need/use Meltdown mitigations.
3 changes: 3 additions & 0 deletions streaming/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ func (conn *Connection) Serve() {
//log.Printf("Sending packet (length %d):\n%s\n", len(packet), hex.Dump(packet))
// send the packet out
_, err := conn.writer.Write(packet)
// NOTE we shouldn't flush here, to avoid swamping the kernel with syscalls.
// see https://golang.org/pkg/net/http/?m=all#response.Write for details
// on how Go buffers HTTP responses (hint: a 2KiB bufio and a 4KiB bufio)
if err != nil {
conn.logger.Log(util.Dict{
"event": eventConnectionClosed,
Expand Down

0 comments on commit f50c017

Please sign in to comment.