mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
12 changed files with 182 additions and 73 deletions
@ -0,0 +1,23 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using MongoDB.Driver; |
||||
|
|
||||
|
namespace Squidex.Infrastructure.MongoDb |
||||
|
{ |
||||
|
public static class Batching |
||||
|
{ |
||||
|
public const int BufferSize = 100; |
||||
|
|
||||
|
public const int Size = BufferSize * 2; |
||||
|
|
||||
|
public static readonly FindOptions Options = new FindOptions |
||||
|
{ |
||||
|
BatchSize = Size |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace LoadTest |
||||
|
{ |
||||
|
public class ContentCreationBenchmarks : IClassFixture<ClientQueryFixture> |
||||
|
{ |
||||
|
public ClientQueryFixture Fixture { get; } |
||||
|
|
||||
|
public ContentCreationBenchmarks(ClientQueryFixture fixture) |
||||
|
{ |
||||
|
Fixture = fixture; |
||||
|
} |
||||
|
|
||||
|
public static IEnumerable<object[]> Loads() |
||||
|
{ |
||||
|
int[] users = { 1, 5, 10, 20, 50, 100 }; |
||||
|
int[] loads = { 5, 10, 20, 50, 100 }; |
||||
|
|
||||
|
foreach (var user in users) |
||||
|
{ |
||||
|
foreach (var load in loads) |
||||
|
{ |
||||
|
yield return new object[] { user, load }; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Theory] |
||||
|
[MemberData(nameof(Loads))] |
||||
|
public async Task Should_create_items(int numUsers, int numIterationsPerUser) |
||||
|
{ |
||||
|
var random = new Random(); |
||||
|
|
||||
|
await Run.Parallel(numUsers, numIterationsPerUser, async () => |
||||
|
{ |
||||
|
await Fixture.Client.CreateAsync(new TestEntityData { Value = random.Next() }, true); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Diagnostics; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace LoadTest |
||||
|
{ |
||||
|
public static class Run |
||||
|
{ |
||||
|
public static async Task Parallel(int numUsers, int numIterationsPerUser, Func<Task> action, int expectedAvg = 100) |
||||
|
{ |
||||
|
var elapsedMs = new ConcurrentBag<long>(); |
||||
|
|
||||
|
var errors = 0; |
||||
|
|
||||
|
async Task RunAsync() |
||||
|
{ |
||||
|
for (var i = 0; i < numIterationsPerUser; i++) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
var watch = Stopwatch.StartNew(); |
||||
|
|
||||
|
await action(); |
||||
|
|
||||
|
watch.Stop(); |
||||
|
|
||||
|
elapsedMs.Add(watch.ElapsedMilliseconds); |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
Interlocked.Increment(ref errors); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
var tasks = new List<Task>(); |
||||
|
|
||||
|
for (var i = 0; i < numUsers; i++) |
||||
|
{ |
||||
|
tasks.Add(Task.Run(RunAsync)); |
||||
|
} |
||||
|
|
||||
|
await Task.WhenAll(tasks); |
||||
|
|
||||
|
var count = elapsedMs.Count; |
||||
|
|
||||
|
var max = elapsedMs.Max(); |
||||
|
var min = elapsedMs.Min(); |
||||
|
|
||||
|
var avg = elapsedMs.Average(); |
||||
|
|
||||
|
Assert.Equal(0, errors); |
||||
|
Assert.Equal(count, numUsers * numIterationsPerUser); |
||||
|
|
||||
|
Assert.InRange(max, 0, expectedAvg * 10); |
||||
|
Assert.InRange(min, 0, expectedAvg); |
||||
|
|
||||
|
Assert.InRange(avg, 0, expectedAvg); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue