.NET Core (no mvc) with Sessions vs Iris (no mvc) with Sessions

Former-commit-id: 04a9660645a824dfbc49414605aeff2b3ff88b55
This commit is contained in:
kataras 2017-08-21 13:29:49 +03:00
parent 14aa770869
commit 0c403fd0c6
8 changed files with 264 additions and 1 deletions

View File

@ -169,7 +169,73 @@ Statistics Avg Stdev Max
Iris MVC with Templates Application ran for **37 seconds** serving **26656.76** requests per second with **192.51MB/s** within **1.18ms** latency in average and **22.52ms** max, the memory usage of all these was ~17MB. Iris MVC with Templates Application ran for **37 seconds** serving **26656.76** requests per second with **192.51MB/s** within **1.18ms** latency in average and **22.52ms** max, the memory usage of all these was ~17MB.
## Results with Sessions
Here we will check the sessions performance, this time
we wanna use the .NET Core raw, **not MVC** and Iris raw, not MVC respectfully.
Spawn `5000000 requests` with 125 different "threads" that sets and gets a session with name `key` and string value `"value"` to the same static request path.
### .NET Core with Sessions
```bash
$ cd netcore-sessions
$ dotnet run -c Release
Hosting environment: Production
Content root path: C:\mygopath\src\github.com\kataras\iris\_benchmarks\netcore-sessions
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
```
```bash
Bombarding http://localhost:5000/setget with 5000000 requests using 125 connections
5000000 / 5000000 [====================================================================================] 100.00% 2m40s
Done!
Statistics Avg Stdev Max
Reqs/sec 31844.77 13856.19 253746
Latency 4.02ms 15.57ms 0.96s
HTTP codes:
1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 14.51MB/s
```
### Iris with Sessions
```bash
$ cd iris-sessions
$ go run main.go
Now listening on: http://localhost:5000
Application started. Press CTRL+C to shut down.
```
```bash
Bombarding http://localhost:5000/setget with 5000000 requests using 125 connections
5000000 / 5000000 [====================================================================================] 100.00% 1m15s
Done!
Statistics Avg Stdev Max
Reqs/sec 66749.70 32110.67 110445
Latency 1.88ms 9.13ms 1.94s
HTTP codes:
1xx - 0, 2xx - 5000000, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 20.65MB/s
```
#### Summary
* Time to complete the `5000000 requests` - smaller is better.
* Reqs/sec - bigger is better.
* Latency - smaller is better
* Throughput - bigger is better.
.NET Core with Sessions Application ran for **2 minutes and 40 seconds** serving **31844.77** requests per second with **14.51MB/s** within **4.02ms** latency in average and **0.96s** max.
Iris with Sessions Application ran for **1 minute and 15 seconds** serving **66749.70** requests per second with **20.65MB/s** within **1.88ms** latency in average and **1.94s** max.
**Thank you all** for the 100% green feedback, have fun! **Thank you all** for the 100% green feedback, have fun!
- https://dev.to/kataras/go-vsnet-core-in-terms-of-http-performance
- https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8 - https://medium.com/@kataras/go-vs-net-core-in-terms-of-http-performance-7535a61b67b8
- https://dev.to/kataras/go-vsnet-core-in-terms-of-http-performance

View File

@ -0,0 +1,67 @@
package main
import (
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/sessions"
)
var sess = sessions.New(sessions.Config{
Cookie: ".cookiesession.id",
Expires: time.Minute,
})
func main() {
app := iris.New()
app.Get("/setget", h)
/*
Test them one by one by these methods:
app.Get("/get", getHandler)
app.Post("/set", postHandler)
app.Delete("/del", delHandler)
*/
app.Run(iris.Addr(":5000"))
}
// Set and Get
func h(ctx context.Context) {
session := sess.Start(ctx)
session.Set("key", "value")
value := session.GetString("key")
if value == "" {
ctx.WriteString("NOT_OK")
return
}
ctx.WriteString(value)
}
// Get
func getHandler(ctx context.Context) {
session := sess.Start(ctx)
value := session.GetString("key")
if value == "" {
ctx.WriteString("NOT_OK")
return
}
ctx.WriteString(value)
}
// Set
func postHandler(ctx context.Context) {
session := sess.Start(ctx)
session.Set("key", "value")
ctx.WriteString("OK")
}
// Delete
func delHandler(ctx context.Context) {
session := sess.Start(ctx)
session.Delete("key")
ctx.WriteString("OK")
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace netcore_sessions
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Http;
namespace netcore_sessions
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddRouting();
// Adds a default in-memory implementation of IDistributedCache.
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.Cookie.Name = ".cookiesession.id";
options.Cookie.HttpOnly = true;
options.IdleTimeout = TimeSpan.FromMinutes(1);
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var routeBuilder = new RouteBuilder(app);
routeBuilder.MapGet("setget", context =>{
context.Session.SetString("key", "value");
var value = context.Session.GetString("key");
if (String.IsNullOrEmpty(value)) {
return context.Response.WriteAsync("NOT_OK");
}
return context.Response.WriteAsync(value);
});
/*
Test them one by one by these methods:
routeBuilder.MapGet("get", context =>{
var value = context.Session.GetString("key");
if (String.IsNullOrEmpty(value)) {
return context.Response.WriteAsync("NOT_OK");
}
return context.Response.WriteAsync(value);
});
routeBuilder.MapPost("set", context =>{
context.Session.SetString("key", "value");
return context.Response.WriteAsync("OK");
});
routeBuilder.MapDelete("del", context =>{
context.Session.Remove("key");
return context.Response.WriteAsync("OK");
});
*/
var routes = routeBuilder.Build();
app.UseSession();
app.UseRouter(routes);
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Error"
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB