diff --git a/_benchmarks/README.md b/_benchmarks/README.md index 6991dadf..b8217e4e 100644 --- a/_benchmarks/README.md +++ b/_benchmarks/README.md @@ -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. +## 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! -- 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://dev.to/kataras/go-vsnet-core-in-terms-of-http-performance + diff --git a/_benchmarks/iris-sessions/main.go b/_benchmarks/iris-sessions/main.go new file mode 100644 index 00000000..d5a34062 --- /dev/null +++ b/_benchmarks/iris-sessions/main.go @@ -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") +} diff --git a/_benchmarks/netcore-sessions/Program.cs b/_benchmarks/netcore-sessions/Program.cs new file mode 100644 index 00000000..d7f42c8f --- /dev/null +++ b/_benchmarks/netcore-sessions/Program.cs @@ -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() + .Build(); + } +} diff --git a/_benchmarks/netcore-sessions/Startup.cs b/_benchmarks/netcore-sessions/Startup.cs new file mode 100644 index 00000000..3f4e7b43 --- /dev/null +++ b/_benchmarks/netcore-sessions/Startup.cs @@ -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); + } + } +} diff --git a/_benchmarks/netcore-sessions/appsettings.json b/_benchmarks/netcore-sessions/appsettings.json new file mode 100644 index 00000000..50fe9a31 --- /dev/null +++ b/_benchmarks/netcore-sessions/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Error" + } + } +} diff --git a/_benchmarks/netcore-sessions/netcore-sessions.csproj b/_benchmarks/netcore-sessions/netcore-sessions.csproj new file mode 100644 index 00000000..b36fc56a --- /dev/null +++ b/_benchmarks/netcore-sessions/netcore-sessions.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp2.0 + + + + + + + + + + + diff --git a/_benchmarks/screens/5m_requests_iris-sessions.png b/_benchmarks/screens/5m_requests_iris-sessions.png new file mode 100644 index 00000000..8da528a5 Binary files /dev/null and b/_benchmarks/screens/5m_requests_iris-sessions.png differ diff --git a/_benchmarks/screens/5m_requests_netcore-sessions.png b/_benchmarks/screens/5m_requests_netcore-sessions.png new file mode 100644 index 00000000..6baeebb3 Binary files /dev/null and b/_benchmarks/screens/5m_requests_netcore-sessions.png differ