Home

Awesome

golax performance

<!-- MarkdownTOC autolink=true bracket=round depth=4 --> <!-- /MarkdownTOC -->

Intro

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.

The results

List users

<p align="center"> <img src="https://docs.google.com/spreadsheets/d/1q0NdoBge4UO_VmFGwcYDN4WQZzKuqCXNrtJzThVdJWQ/pubchart?oid=1063158416&format=image"> </p>

Retrieve user

<p align="center"> <img src="https://docs.google.com/spreadsheets/d/1q0NdoBge4UO_VmFGwcYDN4WQZzKuqCXNrtJzThVdJWQ/pubchart?oid=478921787&format=image"> </p>

GET letters/z/z

<p align="center"> <img src="https://docs.google.com/spreadsheets/d/1q0NdoBge4UO_VmFGwcYDN4WQZzKuqCXNrtJzThVdJWQ/pubchart?oid=1350397502&format=image"> </p>

GET letters/z/z/z

<p align="center"> <img src="https://docs.google.com/spreadsheets/d/1q0NdoBge4UO_VmFGwcYDN4WQZzKuqCXNrtJzThVdJWQ/pubchart?oid=1153847898&format=image"> </p>

Keep alive with 100 threads

<p align="center"> <img src="https://docs.google.com/spreadsheets/d/1q0NdoBge4UO_VmFGwcYDN4WQZzKuqCXNrtJzThVdJWQ/pubchart?oid=1936169051&format=image"> </p>

Tests has been executed in a Intel(R) Core(TM) i5-2400 CPU @ 3.10GHz and 16GiB RAM.

Run tests in your machine

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

About the implementations

All implement a CRUD API described here and:

Golax

The code is the standard way a REST API should be implemented with golax.

Gorilla

Gorilla implementation has been done following Making a RESTful JSON API in Go article.

Chi

I am glad to know about Chi, it follows the same approach as golax and it has a very similar implementation.

About the code readability and maintainability

TODO: comment several points here, and how easy (or not) is adding middlewares/interceptors and routes.