With the recent release of .NET 9, I was eager to explore how it compares to GoLang in terms of performance. As a longtime .NET core enthusiast, I’ve always believed that .NET core holds an edge over GoLang. Today, we’ll explore key metrics like requests per second, latency, and data transfer rates to understand how each framework performs under similar conditions.
Introduction to HTTP Performance
HTTP performance is crucial for web applications, influencing user experience and server resource efficiency. Key metrics to consider include:
- Requests per Second (RPS): Measures how many requests a server can handle per second.
- Latency: The time taken to process a request, typically measured in milliseconds (ms).
- Data Transfer Rate: The amount of data transferred per second, measured in kilobytes per second (KB/sec).
Benchmark Setup
We used ApacheBench (ab
) to benchmark both GoLang and .NET 9. Here’s a summary of our benchmarking setup:
- Concurrency Level: 100
- Total Requests: 10,000
Server Code
Below is the server code used for both GoLang and .NET 9:
GoLang
package main
import (
"fmt"
"net/http"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}
func main() {
http.HandleFunc("/", handler)
server := &http.Server{
Addr: ":5044",
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
fmt.Println("Starting server on :5044")
server.ListenAndServe()
}
.Net 9
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();
Results & Analysis
GoLang Performance
Concurrency Level: 100
Time taken for tests: 1.659 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1300000 bytes
HTML transferred: 130000 bytes
Requests per second: 6027.31 [#/sec] (mean)
Time per request: 16.591 [ms] (mean)
Time per request: 0.166 [ms] (mean, across all concurrent requests)
Transfer rate: 765.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 3 16 0.9 16 19
Waiting: 1 9 4.5 9 18
Total: 3 16 0.9 16 19
Percentage of the requests served within a certain time (ms)
50% 16
66% 16
75% 17
80% 17
90% 17
95% 18
98% 18
99% 18
100% 19 (longest request)
.Net 9 Performance
Concurrency Level: 100
Time taken for tests: 1.610 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1450000 bytes
HTML transferred: 120000 bytes
Requests per second: 6211.65 [#/sec] (mean)
Time per request: 16.099 [ms] (mean)
Time per request: 0.161 [ms] (mean, across all concurrent requests)
Transfer rate: 879.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.1 0 16
Processing: 0 16 4.3 16 32
Waiting: 0 9 7.7 10 31
Total: 0 16 4.3 16 32
Percentage of the requests served within a certain time (ms)
50% 16
66% 16
75% 16
80% 17
90% 19
95% 25
98% 29
99% 31
100% 32 (longest request)
Comparative Analysis
Both GoLang and .NET 9 exhibit impressive performance metrics, but there are some differences worth noting:
Requests per Second (RPS):
- GoLang: 6027.31 RPS
- .NET 9: 6211.65 RPS
.NET 9 slightly edges out GoLang in handling more requests per second, indicating a marginally higher throughput.
Latency:
- GoLang: 16.591 ms (mean)
- .NET 9: 16.099 ms (mean)
Both frameworks demonstrate low latency, with .NET 9 having a slight advantage in mean latency.
Data Transfer Rate:
- GoLang: 765.19 KB/sec
- .NET 9: 879.58 KB/sec
.NET 9 shows a higher data transfer rate, which can be beneficial for data-intensive applications.
Conclusion
In conclusion, both GoLang and .NET 9 offer robust performance for HTTP APIs, with .NET 9 showing a slight edge in requests per second, latency, and data transfer rate. The choice between these frameworks may come down to factors like development ecosystem, language preferences, and specific application requirements.