LORENZO

DEL ROSSI

Computer Engineer

Which is the most efficient Go routing technology?

3 min.
October 1, 2019

In this article I will continue to deal with the optimization in the development of a Web Application.
The starting point for an optimized application is certainly the use of an appropriate language, but it is not enough.
In the previous article I talked about why the choice of the Go language influences the optimization of our application, but it is not enough to choose an optimized language to automatically obtain an optimized application.
In this article I will therefore focus on another equally important aspect: choosing the most efficient routing technology possible.

There are many routers and frameworks available in Go language, starting with the very famous GorillaMux and Martini, which over time have been surpassed in terms of performance by other “younger” routers. Testing them all would be a mammoth job, so I concentrated on testing a router and a framework that I think are among the most efficient at the moment: HttpRouter by Julien Schmidt and the Gin framework.

Some theory..

HttpRouter is a lightweight and optimized HTTP request router that provides high performance with reduced memory consumption compared to the standard mux of the net / http package. Among its main features we have:

Gin is a web framework that presents an API similar to Martini, which was the most used framework until recently, made more performing. Let’s see some of its features:

..and now we move on to the facts

To establish which of the two routers has the best performance, I developed a microservice using the Julien Schmidt router and one using the Gin router which, through a POST call, generates 500 other competing POST calls with a body consisting of the JSON

{
"name": "prova"
}

which will later be printed on the console.
To start the calls on one of the developed microservices, I created a third microservice which, based on the GET call that is passed to it, generates a POST call to one or the other microservice.

After carrying out 50 tests for each microservice and calculating the average of the times necessary to perform them, the result rewarded Gin.

In conclusion, although Julien Schmidt’s router has gained its reputation for its efficiency, we have shown that there is a router that manages to be even more without having to write longer or more complex codes.

If you want to take a look at the code or modify it to test other routers, you can find it HERE.

#LetsGO