Playing With Web.go
Finally, curiosity go the best of me. I decided to install Go language and it’s web.py like framework called web.go.
My OS Info
OS X Snow Leopard, 2.26 GHz Intel Core 2 Duo, 8 GB 1067 MHz DDR3 RAM
Prerequisites(on OS X)
- To install go, simply download the package and double click.
- To install web.go:
# You may need to restart your terminal session after installing Go language. sudo go get github.com/hoisie/web
Hello World Page
Follow the instruction on web.go github for creating the hello world page. I copy-pasted the instruction here for convenience:
# Do all 3 steps in the same directory
# 1. Create hello.go
package main
import (
"github.com/hoisie/web"
)
func hello(val string) string { return "hello " + val }
func main() {
web.Get("/(.*)", hello)
web.Run("0.0.0.0:9999")
}
# 2. Compile hello.go
go build hello.go
# 3. Run the executable
./hello
# Visit: http://localhost:9999/world to see the page.
The compilation time is miniscule, but that doesn’t say much because our application is tiny. Once we got the hello world page up, like a true tech blogger, we have to benchmark it using AB tool.
# 100,000 requests. 210 simultaneous requests. Keep-alive is on. ab -k -n 100000 -c 210 http://localhost:9999/world
The result is quite astonishing. On fresh boot, our little app server took only 4.1 MB of RAM and after AB is finished, the memory usage climbs to 15.3 MB. Not bad at all.
Now let’s look at the AB result:
Server Software: web.go
Server Hostname: localhost
Server Port: 9999
Document Path: /world
Document Length: 11 bytes
Concurrency Level: 210
Time taken for tests: 25.870 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Keep-Alive requests: 100000
Total transferred: 16700000 bytes
HTML transferred: 1100000 bytes
Requests per second: 3865.54 [#/sec] (mean)
Time per request: 54.326 [ms] (mean)
Time per request: 0.259 [ms] (mean, across all concurrent requests)
Transfer rate: 630.41 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 22.8 0 1000
Processing: 0 54 36.6 51 486
Waiting: 0 54 36.6 51 486
Total: 0 54 42.9 51 1159
Percentage of the requests served within a certain time (ms)
50% 51
66% 57
75% 62
80% 71
90% 102
95% 116
98% 155
99% 175
100% 1159 (longest request)
3865.54 requests per second and 0 failed requests! I am very impressed, this result beats anything I’ve ever tested in this laptop. And look at that time per request: 54 ms. Wow!