Skip to content

Instantly share code, notes, and snippets.

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
@nvcnvn
nvcnvn / cheat.js
Created April 1, 2014 09:25
stackoverflow Unicoins cheat code
/*
Open your browser with a network tool (inpsect element in Chrome) than mine one rock.
Check the POST request to stackoverflow.com/unicoin/mine when you just finish the rock, you will find your fkey.
Paste this code to console tab, hit enter and leave the browser mine coin for you.
*/
var fkey = "your fkey";
var rocks = [];
@nvcnvn
nvcnvn / server.go
Created June 12, 2015 05:10
A slow test
package main
import (
"net/http"
"time"
)
func main() {
http.HandleFunc("/a", pageA)
http.HandleFunc("/b", pageB)
@nvcnvn
nvcnvn / log.txt
Created June 12, 2015 05:16
slow test output
$ ginkgo -v
Running Suite: Old Internavenue Suite
=====================================
Random Seed: 1434085966
Will run 1 of 1 specs
PhantomJS is launching GhostDriver...
[INFO - 2015-06-12T05:12:47.238Z] GhostDriver - Main - running on port 40081
[INFO - 2015-06-12T05:12:47.670Z] Session [aa4e9f40-10c1-11e5-bd52-e1d260b9875c] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.8 Safari/534.34","webSecurityEnabled":true}
[INFO - 2015-06-12T05:12:47.670Z] Session [aa4e9f40-10c1-11e5-bd52-e1d260b9875c] - page.customHeaders: - {}
@Service
public class Car {
public void Move(Destination destination) {}
}
type Car struct {}
func (c *Car) Move(to Desitation) {}
type Transporter struct {
vehicle *Car
}
func (t *Transporter) makeOutWith(pretty Lady) {
// ...
}
type Car struct {}
func (c *Car) Move(to Desitation) {}
type Vehicle interface {
Move(to Desitation)
}
type Transporter struct {
vehicle Vehicle
}
@nvcnvn
nvcnvn / factory.go
Last active December 20, 2017 04:15
func main() {
assasinService := &KindOfAssasinService{}
transporter := NewTransporter(assasinService)
hitman := NewHitMan(assasinService);
}
type KindOfAssasinService {}
func (ass *KindOfAssasinService) GetVehicle(t string) Vehicle {
if t == "car" {
return &Car{}
@Purchase
Feature: User able to send request to purchase product
Scenario: The product's quantity is keep when the connection is lost
Given I send request to buy product to the server
And I disconnect the connection before the server receive the request
And I get the response about disconnect
Scenario: The product's quantity is keep when cancel the request
Given I send request to buy product to the server
→ ./istio-1.5.1/bin/istioctl manifest generate | kubectl delete -f -
clusterrole.rbac.authorization.k8s.io "prometheus-istio-system" deleted
clusterrolebinding.rbac.authorization.k8s.io "prometheus-istio-system" deleted
configmap "prometheus" deleted
deployment.apps "prometheus" deleted
service "prometheus" deleted
serviceaccount "prometheus" deleted
clusterrole.rbac.authorization.k8s.io "istio-reader-istio-system" deleted
clusterrolebinding.rbac.authorization.k8s.io "istio-reader-istio-system" deleted
customresourcedefinition.apiextensions.k8s.io "meshpolicies.authentication.istio.io" deleted