Skip to content

Instantly share code, notes, and snippets.

/* Tiny web server in Golang for sharing a folder
Copyright (c) 2010 Alexis ROBERT <[email protected]>
Contains some code from Golang's http.ServeFile method, and
uses lighttpd's directory listing HTML template. */
package main
import "http"
import "io"
#!/usr/bin/ruby
# Runs as follows:
#
# ~$ ruby tls-cert-generator.rb
require "openssl"
require "socket"
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"log"
)

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
# docker build -t="rails" .
FROM ubuntu:12.04
RUN apt-get update
## MYSQL
RUN apt-get install -y -q mysql-client libmysqlclient-dev
## RUBY
@elvuel
elvuel / x_simple_rename.rb
Created January 2, 2014 06:13
rails app simple rename
# encoding: utf-8
args = ARGV.dup
from = args.first || "name"
to = args.last || "to"
cmd = "find ./ -name \"*.rb\" | xargs grep #{from}"
result = `#{cmd}`
// MIT license (c) andelf 2012
type InMemoryCookieJar struct{
storage map[string][]http.Cookie
}
// buggy... but works
func (jar InMemoryCookieJar) SetCookies(u *url.URL, cookies []*http.Cookie) {
for _, ck := range cookies {
path := ck.Domain
@elvuel
elvuel / log.go
Created October 8, 2013 06:27 — forked from cespare/log.go
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
# Run with: rake environment elasticsearch:reindex
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klass = Place
ENV['CLASS'] = klass.name
ENV['INDEX'] = new_index = klass.tire.index.name << '_' << Time.now.strftime('%Y%m%d%H%M%S')
.DS_Store
*.log
Gemfile.lock