- Intro
- The results
- Run tests in your machine
- About the implementations
- About the code readability and maintainability
The reason for this project is this question made by Adrian Sampaleanu in golang-nuts.
The performance compared with the most popular alternative is very similar (actually golax performs slightly better) however code readability and maintainability is far better with golax implementation.
Tests has been executed in a Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz
and 16GiB RAM.
Run all benchmarks for all frameworks:
make dependencies
make benchmark
Make and run golax:
make golax
Make and run gorilla:
make gorilla
Make and run chi:
make chi
Execute tests:
1 thread:
ab -n 20000 -c 1 http://localhost:9999/service/v1/users
ab -n 20000 -c 1 http://localhost:9999/service/v1/users/2
ab -n 20000 -c 1 http://localhost:9999/letters/z/z
ab -n 20000 -c 1 http://localhost:9999/letters/z/z/z
10 threads:
ab -n 200000 -c 10 http://localhost:9999/service/v1/users
ab -n 200000 -c 10 http://localhost:9999/service/v1/users/2
ab -n 200000 -c 10 http://localhost:9999/letters/z/z
ab -n 200000 -c 10 http://localhost:9999/letters/z/z/z
100 threads:
ab -n 200000 -c 100 http://localhost:9999/service/v1/users
ab -n 200000 -c 100 http://localhost:9999/service/v1/users/2
ab -n 200000 -c 100 http://localhost:9999/letters/z/z
ab -n 200000 -c 100 http://localhost:9999/letters/z/z/z
500 threads:
ab -n 200000 -c 500 http://localhost:9999/service/v1/users
ab -n 200000 -c 500 http://localhost:9999/service/v1/users/2
ab -n 200000 -c 500 http://localhost:9999/letters/z/z
ab -n 200000 -c 500 http://localhost:9999/letters/z/z/z
Keep alive:
ab -k -n 200000 -c 100 http://localhost:9999/service/v1/users
ab -k -n 200000 -c 100 http://localhost:9999/service/v1/users/2
ab -k -n 200000 -c 100 http://localhost:9999/letters/z/z
ab -k -n 200000 -c 100 http://localhost:9999/letters/z/z/z
All implement a CRUD API described here and:
- Errors are returned in JSON format
- All requests are logged to stdout and/or stderr
The code is the standard way a REST API should be implemented with golax.
Gorilla implementation has been done following Making a RESTful JSON API in Go article.
I am glad to know about Chi, it follows the same approach as golax and it has a very similar implementation.
TODO: comment several points here, and how easy (or not) is adding middlewares/interceptors and routes.