Skip to content

Instantly share code, notes, and snippets.

@benaadams
Forked from malekpour/Startup.cs
Created August 25, 2017 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaadams/66d1a6c0b1cfca8f9d4ff25922c949f9 to your computer and use it in GitHub Desktop.
Save benaadams/66d1a6c0b1cfca8f9d4ff25922c949f9 to your computer and use it in GitHub Desktop.
Iris Go vs .NET Core Kestrel in terms of HTTP performance

In Iris Go vs .NET Core Kestrel in terms of HTTP performance, an article by @kataras, he explains how his Iris framework beats AspNetCore and also tells his story on how some of the DotNet community members insulted him because of technological disagreements. In some cases, he is right and I am sure we can have a more constructive discourse. I appreciate his work and the technology he developed.

I tried his code and yes, Iris outperforms Kestrel when it returns a short constant string (value). In real world scenarios, we don’t do this usually. We do so many different things to prepare the response. To simulate a real-world example and a fair benchmark, I modified his example to return 1KB randomly generated string as response. On my machine (Corei7-7700K) Kestrel does the job 10+ times faster.

BTW, this result is more about runtime, memory management and compiler performance. Iris is still a lightweight framework comparing to AspNetCore and may perform better in some cases.

AspNetCore benchmark in C# (Startup.cs)

Bombarding http://localhost:5000/api/values/5 with 500000 requests using 125 connections
 500000 / 500000 [=============================================================================================================] 100.00% 5s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     99891.00   13123.35     111093
  Latency        1.25ms     1.00ms    39.00ms
  HTTP codes:
    1xx - 0, 2xx - 500000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:   110.60MB/s

Iris benchmark in Go (main.go)

Bombarding http://localhost:5000/api/values/5 with 500000 requests using 125 connections
 500000 / 500000 [===========================================================================================================] 100.00% 1m6s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec      7501.00     199.76       9393
  Latency       16.66ms     3.09ms    55.00ms
  HTTP codes:
    1xx - 0, 2xx - 500000, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0
  Throughput:     8.31MB/s
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/context"
//"strings"
"math/rand"
)
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "
func randomString(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}
func main() {
app := iris.New()
//txt := strings.Repeat("g", 10000)
app.Get("/api/values/{id}", func(ctx context.Context) {
txt := randomString(1024)
ctx.WriteString(txt)
})
app.Run(iris.Addr(":5000"))
}
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
static void Main(string[] args)
=> WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build().Run();
public void ConfigureServices(IServiceCollection services)
=> services.AddRouting();
const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
static string RandomString(int length)
{
var random = new Random(DateTime.Now.Millisecond);
var bytes = new char[length];
for (var i = 0; i < length; i++)
{
bytes[i] = chars[random.Next(chars.Length)];
}
return new string(bytes);
}
public void Configure(IApplicationBuilder app)
{
var routeBuilder = new RouteBuilder(app);
//var txt = new string('n', 10000);
routeBuilder.MapGet("api/values/{id?}", context =>
{
var txt = RandomString(1024);
return context.Response.WriteAsync(txt);
});
var routes = routeBuilder.Build();
app.UseRouter(routes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment