Go gin vs Springboot: Hello world perfomance comparison
--
As both Go and Springboot are compiled & executed, in this article, I’m going to compare the performance comparison for a simple hello world case. A follow-up article will compare Go gin with Spring webflux (for a more fair comparison). And then some more follow-up articles will compare JSON processing as well.
Test setup
Configuration
The test is executed on MacBook Pro M1 with 16G of RAM.
The software versions are:
- Go 1.20.2
- Springboot 3.0.5 over Java 17
Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications. Spring Boot provides a good platform for Java developers to develop a stand-alone and production-grade spring application that you can just run. You can get started with minimum configurations without the need for an entire Spring configuration setup.
As Springboot is a framework, I’m going to use a popular framework on Go side as well: Gin. Gin is a web framework written in Go. It features a martini-like API with performance that is up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin.
Code
The hello world code in both cases is as follows:
Go
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.New()
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello world!")
})
r.Run(":3000")
}
Spring
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/")
public String handleRequest() {
return "Hello World!";
}
}
The application code is pretty simple in both the cases.
Execution
Each test is executed for 5M (5 million) requests.
The tests are executed for 25, 100, and 300 concurrent connections.
The load test is carried out using Bombardier HTTP testing tool.
The following are the charts showing the results, followed by a quick analysis at the end:
Analysis
First, the competition was tough. That was expected and unexpected.
It was expected because both are compiled languages. It was unexpected, because Spring is a very big, complicated, feature-rich framework when compared Gin, still Spring managed to give a tough competition to Go. That’s commendable.
Just by looking at RPS numbers, Go leads by a big margin. But looking at latency numbers, we can see that the competition was very tough till 3rd quartile. The only reason Spring looses is because of the maximum latency numbers. The one-off requests that took a very long time. If we look at median latency, Spring is better than Go.
In terms of resources, Go uses more CPU compared to Spring. However, Go’s memory usage is nothing when compared to Spring.
So, who’s the winner? Purely based on numbers, I have to say Go.
For a similar comparison with Spring Webflux (reactive), the article can be seen here.