

Serving static files with Go - shakedko
http://www.shakedos.com/2014/Feb/08/serving-static-files-with-go.html

======
georgemcbay
Nice writeup!

One other thing I'd mention to anyone considering serving static files in Go
is this:

You might be tempted to cache the static files into a map for "performance".
After all memory is much faster than disk, right? Be careful with this, Go's
http FileServer uses sendto on platforms that support it and because it
bypasses the userland/kernel barrier and can thus do a zero-copy transmission,
sendto (in combination with OS-level file caching) will almost certainly
outperform your in-memory caching.

If you really want to optimize transmission, one way to do it (if you're
serving mostly data that isn't already naturally compressed) is to gzip
everything that is gzip-friendly either in a post-compile step or at runtime,
and then serve an on-disk-cached (filename).gz version instead of (filename)
with appropriate headers (and checking client headers to make sure they can
accept gzip content), but still using the internal FileServer logic to make
use of the sendto functionality. Go's internal http stuff is very
comprehensive but it is an API and not really a framework and it doesn't try
to do anything clever with gzipping of content.

As always, whenever "optimizing" make sure you measure extensively to make
sure you're actually helping and not making things worse.

