Skip to content

Instantly share code, notes, and snippets.

View leonardaustin's full-sized avatar

Leonard Austin leonardaustin

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@leonardaustin
leonardaustin / a.sh-session
Created August 16, 2016 13:07 — forked from hraban/a.sh-session
code snippets for Ravelin blog post
/tmp $ git clone -q github.com/unravelin/tomono
/tmp $ cat sub-repositories.txt
https://github.com/outr/scalarelational.git scalarelational
https://github.com/realph/gulp-zero.git zero
https://github.com/reaxis/mu µ
/tmp $ cat sub-repositories.txt | ./tomono/tomono.sh
… crunch crunch crunch
/tmp $ cd core
/tmp/core $ git branch
2.0.0
/tmp $ git clone -q github.com/unravelin/tomono
/tmp $ cat sub-repositories.txt
https://github.com/outr/scalarelational.git scalarelational
https://github.com/realph/gulp-zero.git zero
https://github.com/reaxis/mu µ
/tmp $ cat sub-repositories.txt | ./tomono/tomono.sh
… crunch crunch crunch
/tmp $ cd core
/tmp/core $ git branch
2.0.0
/tmp/core $ alias gitlog='git log --graph --format="format:%h %s%d (%aN, %ar)" --all --branches=\* --remotes=\*'
/tmp/core $ gitlog | head
* 4a21d29 Merging µ to master (HEAD -> master) (Hraban Luyat, 0 seconds ago)
|\
| * 0f0a833 .attr() now uses setAttribute() and getAttribute to make it work with data- attributes (µ/master) (Koen Mostert, 1 year, 3 months ago)
| * 9fe9636 added .remove() (Koen Mostert, 1 year, 3 months ago)
| * ce7a6e9 Merge branch 'master' of https://github.com/reaxis/mu (Koen Mostert, 1 year, 3 months ago)
| |\
| | * 56df7d9 initiating µ twice resulted in an infinite loop of adding event handlers (Koen Mostert, 1 year, 4 months ago)
| * | ab10873 more tests (Koen Mostert, 1 year, 3 months ago)
/tmp/core $ cd ..
/tmp $ mkdir fake-repo
/tmp $ cd fake-repo
/tmp/fake-repo $ git init
Initialized empty Git repository in /private/tmp/fake-repo/.git/
/tmp/fake-repo $ echo hello > world
/tmp/fake-repo $ git add -A .
/tmp/fake-repo $ git commit -m 'initial commit in fake-repo (add file world)'
[master (root-commit) e74125e] initial commit in fake-repo (add file world)
1 file changed, 1 insertion(+)
/tmp/fake-repo $ cd ..
/tmp $ ./tomono/tomono.sh --continue <<EOF
> /tmp/fake-repo foo
> EOF
/tmp/core /tmp
Merging in /tmp/fake-repo..
warning: no common commits
4a21d29473e8ed735d60e3d4e785c3860340a335
Automatic merge went well; stopped before committing as requested
/tmp $ cd core
/tmp/core $ cd ../fake-repo
/tmp/fake-repo $ echo bonjour > monde
/tmp/fake-repo $ git add -A .
/tmp/fake-repo $ git commit -m 'fake-repo commit #2 (add file monde)'
[master bddded4] fake-repo commit #2 (add file monde)
1 file changed, 1 insertion(+)
create mode 100644 monde