Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue that caused the operation context to be returned multiple times to the pool. #2556

Merged
merged 6 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/HotChocolate/AspNetCore/sample/StarWars/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void ConfigureServices(IServiceCollection services)
.AddStarWarsTypes()
.AddStarWarsRepositories()
.AddTypeExtension<SlowTypeExtension>()
.AddTypeExtension<SlowHumanTypeExtension>()
.AddGraphQLServer("hello_world")
.AddQueryType(d => d
.Name("Query")
Expand Down Expand Up @@ -54,8 +55,18 @@ public class SlowTypeExtension
{
public async Task<string> SlowAsync()
{
await Task.Delay(3000);
return "hello";
await Task.Delay(600);
return "droid";
}
}

[ExtendObjectType("Human")]
public class SlowHumanTypeExtension
{
public async Task<string> SlowAsync()
{
await Task.Delay(600);
return "human";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<bool> TryOpenAsync()
do
{
Memory<byte> memory = writer.GetMemory(_maxMessageSize);
bool success = MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> buffer);
var success = MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> buffer);

if (success)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
``` ini

BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H2) [Darwin 19.6.0]
BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H15) [Darwin 19.6.0]
Intel Core i9-10910 CPU 3.60GHz, 1 CPU, 20 logical and 10 physical cores
.NET Core SDK=5.0.100-rc.1.20452.10
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
.NET Core SDK=5.0.100-rc.2.20479.15
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT


```
| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------------------------------- |----------:|----------:|----------:|----------:|-----:|----------:|---------:|--------:|-----------:|
| SchemaIntrospection | 1.161 ms | 0.0118 ms | 0.0099 ms | 1.161 ms | 1 | 46.8750 | 1.9531 | - | 491.12 KB |
| SchemaIntrospectionFiveParallelRequests | 3.231 ms | 0.0444 ms | 0.0394 ms | 3.220 ms | 4 | 253.9063 | 82.0313 | - | 2603.97 KB |
| GetHero | 2.287 ms | 0.0399 ms | 0.0392 ms | 2.281 ms | 2 | - | - | - | 7.82 KB |
| GetHeroFiveParallelRequests | 2.349 ms | 0.0234 ms | 0.0219 ms | 2.353 ms | 3 | - | - | - | 39.27 KB |
| GetHeroWithFriends | 8.110 ms | 0.1616 ms | 0.4396 ms | 8.026 ms | 5 | - | - | - | 84.65 KB |
| GetHeroWithFriendsFiveParallelRequests | 8.439 ms | 0.0702 ms | 0.0622 ms | 8.444 ms | 6 | 31.2500 | 15.6250 | - | 428.75 KB |
| GetTwoHerosWithFriends | 8.017 ms | 0.0826 ms | 0.0645 ms | 8.027 ms | 5 | 15.6250 | - | - | 173.61 KB |
| GetTwoHerosWithFriendsFiveParallelRequests | 9.555 ms | 0.1395 ms | 0.1305 ms | 9.564 ms | 7 | 78.1250 | 31.2500 | - | 869.9 KB |
| LargeQuery | 18.918 ms | 0.2521 ms | 0.2235 ms | 18.842 ms | 8 | 312.5000 | 156.2500 | 31.2500 | 3401.36 KB |
| LargeQueryFiveParallelRequests | 41.495 ms | 0.7966 ms | 2.0275 ms | 40.848 ms | 9 | 1636.3636 | 818.1818 | 90.9091 | 17145.3 KB |
| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------------------------------- |----------:|----------:|----------:|----------:|-----:|----------:|---------:|------:|------------:|
| SchemaIntrospection | 1.038 ms | 0.0088 ms | 0.0082 ms | 1.038 ms | 1 | 48.8281 | 1.9531 | - | 503.4 KB |
| SchemaIntrospectionFiveParallelRequests | 2.791 ms | 0.0550 ms | 0.0977 ms | 2.823 ms | 4 | 261.7188 | 101.5625 | - | 2671.83 KB |
| GetHero | 2.408 ms | 0.0139 ms | 0.0130 ms | 2.409 ms | 2 | - | - | - | 8.17 KB |
| GetHeroFiveParallelRequests | 2.602 ms | 0.0184 ms | 0.0173 ms | 2.600 ms | 3 | 3.9063 | - | - | 41.01 KB |
| GetHeroWithFriends | 8.019 ms | 0.0422 ms | 0.0352 ms | 8.021 ms | 5 | - | - | - | 84.4 KB |
| GetHeroWithFriendsFiveParallelRequests | 8.744 ms | 0.0813 ms | 0.0635 ms | 8.758 ms | 7 | 31.2500 | 15.6250 | - | 418.41 KB |
| GetTwoHerosWithFriends | 8.327 ms | 0.0582 ms | 0.0544 ms | 8.334 ms | 6 | 15.6250 | - | - | 176.3 KB |
| GetTwoHerosWithFriendsFiveParallelRequests | 9.537 ms | 0.0725 ms | 0.0678 ms | 9.539 ms | 8 | 78.1250 | 31.2500 | - | 913.14 KB |
| LargeQuery | 17.247 ms | 0.1668 ms | 0.1479 ms | 17.295 ms | 9 | 343.7500 | 156.2500 | - | 3692.05 KB |
| LargeQueryFiveParallelRequests | 39.248 ms | 0.7407 ms | 0.6929 ms | 39.304 ms | 10 | 1692.3077 | 846.1538 | - | 17823.86 KB |
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
``` ini

BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H2) [Darwin 19.6.0]
BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H15) [Darwin 19.6.0]
Intel Core i9-10910 CPU 3.60GHz, 1 CPU, 20 logical and 10 physical cores
.NET Core SDK=5.0.100-rc.1.20452.10
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
.NET Core SDK=5.0.100-rc.2.20479.15
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT


```
| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|----------------------------------- |---------:|---------:|---------:|---------:|-----:|-------:|-------:|------:|----------:|
| PrepareSelectionSets_Introspection | 25.58 μs | 0.487 μs | 0.478 μs | 25.36 μs | 2 | 2.5024 | 0.2136 | - | 25.63 KB |
| PrepareSelectionSets_StarWars | 16.65 μs | 0.287 μs | 0.269 μs | 16.53 μs | 1 | 1.7700 | 0.1221 | - | 18.34 KB |
| PrepareSelectionSets_Introspection | 29.19 μs | 0.154 μs | 0.136 μs | 29.21 μs | 2 | 2.5330 | 0.2136 | - | 26.14 KB |
| PrepareSelectionSets_StarWars | 19.88 μs | 0.128 μs | 0.114 μs | 19.86 μs | 1 | 1.8616 | 0.1221 | - | 19.25 KB |
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
``` ini

BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H2) [Darwin 19.6.0]
BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H15) [Darwin 19.6.0]
Intel Core i9-10910 CPU 3.60GHz, 1 CPU, 20 logical and 10 physical cores
.NET Core SDK=5.0.100-rc.1.20452.10
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
.NET Core SDK=5.0.100-rc.2.20479.15
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT


```
| Method | Size | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|--------------------------- |----- |------------:|-----------:|-----------:|------------:|-----:|-------:|-------:|-------:|----------:|
| **Create_And_Fill_Dictionary** | **1** | **51.03 ns** | **0.725 ns** | **0.642 ns** | **50.83 ns** | **3** | **0.0229** | **-** | **-** | **240 B** |
| Create_And_Fill_ArrayPool | 1 | 30.06 ns | 0.604 ns | 0.827 ns | 29.70 ns | 2 | 0.0023 | - | - | 24 B |
| Create_And_Fill_ResultMap | 1 | 19.94 ns | 0.222 ns | 0.186 ns | 19.95 ns | 1 | 0.0023 | - | - | 24 B |
| **Create_And_Fill_Dictionary** | **8** | **465.41 ns** | **5.564 ns** | **4.646 ns** | **464.75 ns** | **8** | **0.1130** | **0.0005** | **-** | **1184 B** |
| Create_And_Fill_ArrayPool | 8 | 143.00 ns | 2.613 ns | 2.444 ns | 142.79 ns | 5 | 0.0184 | - | - | 192 B |
| Create_And_Fill_ResultMap | 8 | 98.58 ns | 1.890 ns | 2.829 ns | 98.07 ns | 4 | 0.0184 | - | - | 192 B |
| **Create_And_Fill_Dictionary** | **16** | **498.96 ns** | **10.026 ns** | **10.728 ns** | **496.39 ns** | **9** | **0.1497** | **0.0010** | **-** | **1568 B** |
| Create_And_Fill_ArrayPool | 16 | 213.14 ns | 3.217 ns | 3.010 ns | 212.12 ns | 6 | 0.0551 | - | - | 576 B |
| Create_And_Fill_ResultMap | 16 | 231.26 ns | 2.787 ns | 2.327 ns | 231.36 ns | 7 | 0.0548 | - | - | 576 B |
| **Create_And_Fill_Dictionary** | **50** | **2,029.05 ns** | **17.202 ns** | **15.249 ns** | **2,026.58 ns** | **14** | **0.6790** | **0.0229** | **-** | **7104 B** |
| Create_And_Fill_ArrayPool | 50 | 860.53 ns | 13.253 ns | 12.397 ns | 859.07 ns | 10 | 0.2365 | 0.0019 | - | 2480 B |
| Create_And_Fill_ResultMap | 50 | 921.01 ns | 17.578 ns | 19.538 ns | 919.34 ns | 11 | 0.2365 | 0.0010 | - | 2480 B |
| **Create_And_Fill_Dictionary** | **100** | **4,626.16 ns** | **92.034 ns** | **102.296 ns** | **4,588.51 ns** | **16** | **1.4725** | **0.1068** | **-** | **15472 B** |
| Create_And_Fill_ArrayPool | 100 | 1,616.39 ns | 32.094 ns | 52.731 ns | 1,607.14 ns | 12 | 0.5035 | 0.0095 | - | 5280 B |
| Create_And_Fill_ResultMap | 100 | 1,631.37 ns | 7.813 ns | 6.100 ns | 1,631.72 ns | 13 | 0.5035 | 0.0038 | 0.0019 | 5280 B |
| **Create_And_Fill_Dictionary** | **200** | **7,984.81 ns** | **108.261 ns** | **111.176 ns** | **7,987.00 ns** | **17** | **3.1738** | **0.4425** | **-** | **33192 B** |
| Create_And_Fill_ArrayPool | 200 | 3,165.21 ns | 62.366 ns | 55.286 ns | 3,167.34 ns | 15 | 1.0376 | 0.0381 | - | 10880 B |
| Create_And_Fill_ResultMap | 200 | 4,452.51 ns | 182.177 ns | 534.293 ns | 4,721.03 ns | 16 | 1.0376 | 0.0191 | - | 10880 B |
| Method | Size | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|--------------------------- |----- |------------:|----------:|----------:|------------:|-----:|-------:|-------:|------:|----------:|
| **Create_And_Fill_Dictionary** | **1** | **52.43 ns** | **0.153 ns** | **0.136 ns** | **52.43 ns** | **3** | **0.0229** | **-** | **-** | **240 B** |
| Create_And_Fill_ArrayPool | 1 | 29.74 ns | 0.270 ns | 0.239 ns | 29.82 ns | 2 | 0.0023 | - | - | 24 B |
| Create_And_Fill_ResultMap | 1 | 14.82 ns | 0.305 ns | 0.286 ns | 14.69 ns | 1 | 0.0023 | - | - | 24 B |
| **Create_And_Fill_Dictionary** | **8** | **320.14 ns** | **2.100 ns** | **1.753 ns** | **320.61 ns** | **8** | **0.1130** | **-** | **-** | **1184 B** |
| Create_And_Fill_ArrayPool | 8 | 103.81 ns | 1.080 ns | 1.010 ns | 104.11 ns | 5 | 0.0184 | - | - | 192 B |
| Create_And_Fill_ResultMap | 8 | 102.09 ns | 0.265 ns | 0.234 ns | 102.08 ns | 4 | 0.0184 | - | - | 192 B |
| **Create_And_Fill_Dictionary** | **16** | **542.58 ns** | **5.048 ns** | **4.475 ns** | **542.10 ns** | **9** | **0.1497** | **0.0010** | **-** | **1568 B** |
| Create_And_Fill_ArrayPool | 16 | 227.88 ns | 1.363 ns | 1.208 ns | 227.85 ns | 6 | 0.0551 | - | - | 576 B |
| Create_And_Fill_ResultMap | 16 | 242.44 ns | 1.279 ns | 1.196 ns | 242.32 ns | 7 | 0.0548 | - | - | 576 B |
| **Create_And_Fill_Dictionary** | **50** | **2,149.02 ns** | **21.885 ns** | **20.471 ns** | **2,145.86 ns** | **14** | **0.6790** | **0.0229** | **-** | **7104 B** |
| Create_And_Fill_ArrayPool | 50 | 746.83 ns | 4.849 ns | 4.535 ns | 747.37 ns | 10 | 0.2365 | 0.0019 | - | 2480 B |
| Create_And_Fill_ResultMap | 50 | 828.53 ns | 6.307 ns | 4.924 ns | 827.43 ns | 11 | 0.2365 | - | - | 2480 B |
| **Create_And_Fill_Dictionary** | **100** | **4,228.38 ns** | **75.276 ns** | **70.413 ns** | **4,205.91 ns** | **17** | **1.4725** | **0.1068** | **-** | **15472 B** |
| Create_And_Fill_ArrayPool | 100 | 1,556.68 ns | 30.235 ns | 31.049 ns | 1,566.25 ns | 12 | 0.5035 | 0.0095 | - | 5280 B |
| Create_And_Fill_ResultMap | 100 | 1,706.82 ns | 16.799 ns | 14.892 ns | 1,705.31 ns | 13 | 0.5035 | 0.0038 | - | 5280 B |
| **Create_And_Fill_Dictionary** | **200** | **8,382.26 ns** | **68.324 ns** | **60.567 ns** | **8,376.07 ns** | **18** | **3.1738** | **0.4425** | **-** | **33192 B** |
| Create_And_Fill_ArrayPool | 200 | 3,367.62 ns | 25.932 ns | 22.988 ns | 3,367.25 ns | 15 | 1.0376 | 0.0381 | - | 10880 B |
| Create_And_Fill_ResultMap | 200 | 3,504.05 ns | 65.722 ns | 61.477 ns | 3,514.07 ns | 16 | 1.0376 | 0.0191 | - | 10880 B |
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
``` ini

BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H2) [Darwin 19.6.0]
BenchmarkDotNet=v0.12.1, OS=macOS Catalina 10.15.7 (19H15) [Darwin 19.6.0]
Intel Core i9-10910 CPU 3.60GHz, 1 CPU, 20 logical and 10 physical cores
.NET Core SDK=5.0.100-rc.1.20452.10
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.45114, CoreFX 5.0.20.45114), X64 RyuJIT
.NET Core SDK=5.0.100-rc.2.20479.15
[Host] : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT
DefaultJob : .NET Core 5.0.0 (CoreCLR 5.0.20.47505, CoreFX 5.0.20.47505), X64 RyuJIT


```
| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------------------- |---------:|---------:|---------:|---------:|-----:|-------:|------:|------:|----------:|
| One_String_Literal | 165.0 ns | 2.18 ns | 2.04 ns | 165.0 ns | 1 | - | - | - | - |
| One_String | 184.8 ns | 2.60 ns | 2.43 ns | 184.8 ns | 2 | 0.0052 | - | - | 56 B |
| One_Object_Literal | 546.5 ns | 10.40 ns | 12.39 ns | 546.8 ns | 3 | 0.0134 | - | - | 144 B |
| One_Object_Dictionary | 693.9 ns | 10.07 ns | 9.42 ns | 691.5 ns | 4 | 0.0610 | - | - | 640 B |
| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------------------- |---------:|--------:|--------:|---------:|-----:|-------:|------:|------:|----------:|
| One_String_Literal | 139.8 ns | 0.54 ns | 0.48 ns | 139.8 ns | 1 | - | - | - | - |
| One_String | 156.6 ns | 0.40 ns | 0.38 ns | 156.5 ns | 2 | 0.0052 | - | - | 56 B |
| One_Object_Literal | 478.6 ns | 4.42 ns | 3.69 ns | 479.0 ns | 3 | 0.0134 | - | - | 144 B |
| One_Object_Dictionary | 579.0 ns | 5.25 ns | 4.65 ns | 578.7 ns | 4 | 0.0610 | - | - | 640 B |
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System.Collections.Generic;
using System;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Options;
using GreenDonut;
using HotChocolate.DataLoader;
using HotChocolate.Execution;
using HotChocolate.Execution.Caching;
using HotChocolate.Execution.Configuration;
using HotChocolate.Execution.Internal;
using HotChocolate.Execution.Processing;
using HotChocolate.Fetching;
using HotChocolate.Language;
using HotChocolate.Utilities;
using HotChocolate.DataLoader;
using HotChocolate.Execution.Configuration;
using HotChocolate.Execution.Internal;
using HotChocolate.Types.Relay;
using Microsoft.Extensions.Options;
using HotChocolate.Utilities;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -40,33 +40,39 @@ internal static class InternalServiceCollectionExtensions
int maximumRetained = 512)
{
services.TryAddSingleton<ObjectPool<ResultObjectBuffer<ResultMap>>>(
sp => new ResultMapPool(maximumRetained));
_ => new ResultMapPool(maximumRetained));
services.TryAddSingleton<ObjectPool<ResultObjectBuffer<ResultMapList>>>(
sp => new ResultMapListPool(maximumRetained));
_ => new ResultMapListPool(maximumRetained));
services.TryAddSingleton<ObjectPool<ResultObjectBuffer<ResultList>>>(
sp => new ResultListPool(maximumRetained));
_ => new ResultListPool(maximumRetained));
services.TryAddSingleton<ResultPool>();
return services;
}

internal static IServiceCollection TryAddResolverTaskPool(
this IServiceCollection services,
int maximumRetained = 16)
int maximumRetained = 256)
{
services.TryAddSingleton<ObjectPool<ResolverTask>>(
sp => new BufferedObjectPool<ResolverTask>(t => t.Reset()));
_ => new ResolverTaskPool(
maximumRetained));
return services;
}

internal static IServiceCollection TryAddOperationContextPool(
this IServiceCollection services,
int maximumRetained = 16)
int maximumRetained = -1)
{
if (maximumRetained < 1)
{
maximumRetained = Environment.ProcessorCount * 2;
}

services.TryAddTransient<OperationContext>();
services.TryAddSingleton<ObjectPool<OperationContext>>(
sp => new OperationContextPool(
sp.GetRequiredService<OperationContext>,
maximumRetained));
sp => new DefaultObjectPool<OperationContext>(
new OperationContextPoolPolicy(sp.GetRequiredService<OperationContext>),
maximumRetained));
return services;
}

Expand Down