Skip to content

Feature/master/versioned benchmarks #4216

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

Merged
merged 2 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Elastic Abstractions CI" value="https://ci.appveyor.com/nuget/elasticsearch-net-abstractions" />
<add key="Versioned Clients" value="https://ci.appveyor.com/nuget/elasticsearch-net" />
<add key="AssemblyRewriter" value="https://ci.appveyor.com/nuget/assemblyrewriter" />
<add key="AssemblyDiffer" value="https://ci.appveyor.com/nuget/assemblydiffer" />
</packageSources>
Expand Down
2 changes: 2 additions & 0 deletions src/Elasticsearch.Net/Providers/MemoryStreamFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace Elasticsearch.Net
/// </summary>
public class MemoryStreamFactory : IMemoryStreamFactory
{
public static MemoryStreamFactory Default { get; } = new MemoryStreamFactory();

/// <inheritdoc />
public MemoryStream Create() => new MemoryStream();

Expand Down
34 changes: 18 additions & 16 deletions src/Tests/Tests.Benchmarking/BenchmarkProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
Expand Down Expand Up @@ -30,21 +31,21 @@ static Program()
if (!Directory.Exists(Path.Combine(dirInfo.FullName, ".git"))) Environment.Exit(2);

Console.WriteLine(dirInfo.FullName);
using (var repos = new Repository(dirInfo.FullName))
{
Commit = repos.Head.Tip.Sha;
CommitMessage = repos.Head.Tip.Message?.Trim(' ', '\t', '\r', '\n');
Branch = repos.Head.FriendlyName;
var remoteName = repos.Head.RemoteName;
Repository =
repos.Network.Remotes.FirstOrDefault(r => r.Name == remoteName)?.Url
?? repos.Network.Remotes.FirstOrDefault()?.Url;
}
// using (var repos = new Repository(dirInfo.FullName))
// {
// Commit = repos.Head.Tip.Sha;
// CommitMessage = repos.Head.Tip.Message?.Trim(' ', '\t', '\r', '\n');
// Branch = repos.Head.FriendlyName;
// var remoteName = repos.Head.RemoteName;
// Repository =
// repos.Network.Remotes.FirstOrDefault(r => r.Name == remoteName)?.Url
// ?? repos.Network.Remotes.FirstOrDefault()?.Url;
// }
}

public static int Main(string[] arguments)
{
Console.WriteLine($"Tests.Benchmarking: [{Branch}]@({Commit}) on {Repository} : {CommitMessage} - ");
//Console.WriteLine($"Tests.Benchmarking: [{Branch}]@({Commit}) on {Repository} : {CommitMessage} - ");
var config = CreateDefaultConfig();
if (arguments.Any() && arguments[0].Equals("--all", StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -61,14 +62,15 @@ public static int Main(string[] arguments)

private static IConfig CreateDefaultConfig()
{
var jobs = new[]
var jobs = new List<Job>
{
Job.ShortRun.With(Runtime.Core).With(Jit.RyuJit),
Job.ShortRun.With(Runtime.Clr).With(Jit.RyuJit),
Job.ShortRun.With(Runtime.Clr).With(Jit.LegacyJit),
Job.MediumRun.With(CoreRuntime.Core30).With(Jit.RyuJit),
};
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
jobs.Add(Job.MediumRun.With(ClrRuntime.Net472).With(Jit.LegacyJit));

var config = DefaultConfig.Instance
.With(jobs)
.With(jobs.ToArray())
.With(MemoryDiagnoser.Default);
return config;
}
Expand Down
78 changes: 78 additions & 0 deletions src/Tests/Tests.Benchmarking/BulkBenchmarkTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Elasticsearch.Net;
using Nest;
using Tests.Benchmarking.Framework;
using Tests.Core.Client;
using Tests.Domain;

namespace Tests.Benchmarking
{
[BenchmarkConfig(5)]
public class BulkBenchmarkTests
{
private static readonly IList<Project> Projects = Project.Generator.Clone().Generate(10000);
private static readonly byte[] Response = TestClient.DefaultInMemoryClient.ConnectionSettings.RequestResponseSerializer.SerializeToBytes(ReturnBulkResponse(Projects));

private static readonly IElasticClient Client =
new ElasticClient(new ConnectionSettings(new InMemoryConnection(Response, 200, null, null))
.DefaultIndex("index")
.EnableHttpCompression(false)
);

//TODO can uncomment when https://github.com/elastic/elasticsearch-net/pull/4202 lands
// private static readonly IElasticClient ClientNoRecyclableMemory =
// new ElasticClient(new ConnectionSettings(new InMemoryConnection(Response, 200, null, null))
// .DefaultIndex("index")
// .EnableHttpCompression(false)
// .MemoryStreamFactory(MemoryStreamFactory.Default)
// );

private static readonly Nest8.IElasticClient ClientV8 =
new Nest8.ElasticClient(new Nest8.ConnectionSettings(
new Elasticsearch.Net8.InMemoryConnection(Response, 200, null, null))
.DefaultIndex("index")
.EnableHttpCompression(false)
);

[GlobalSetup]
public void Setup() { }

[Benchmark(Description = "PR")]
public BulkResponse NestUpdatedBulk() => Client.Bulk(b => b.IndexMany(Projects));

// [Benchmark(Description = "PR no recyclable")]
// public BulkResponse NoRecyclableMemory() => ClientNoRecyclableMemory.Bulk(b => b.IndexMany(Projects));

[Benchmark(Description = "8.x")]
public Nest8.BulkResponse NestCurrentBulk() => ClientV8.Bulk(b => b.IndexMany(Projects));

private static object BulkItemResponse(Project project) => new
{
index = new
{
_index = "nest-52cfd7aa",
_id = project.Name,
_version = 1,
_shards = new
{
total = 2,
successful = 1,
failed = 0
},
created = true,
status = 201
}
};

private static object ReturnBulkResponse(IList<Project> projects) => new
{
took = 276,
errors = false,
items = projects
.Select(p => BulkItemResponse(p))
.ToArray()
};
}
}
4 changes: 3 additions & 1 deletion src/Tests/Tests.Benchmarking/Tests.Benchmarking.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp3.0;net472</TargetFrameworks>
<OutputType>Exe</OutputType>
<TieredCompilation>false</TieredCompilation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>true</Optimize>
Expand All @@ -11,8 +12,9 @@
<ProjectReference Include="..\Tests.Core\Tests.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="Elastic.BenchmarkDotNetExporter" Version="0.1.0-ci20191017T152836" />
<PackageReference Include="LibGit2Sharp" Version="0.26.0-preview-0062" />
<PackageReference Include="NEST.v8" Version="8.1.0-ci20191112T041057" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class AlwaysInMemoryConnectionSettings : TestConnectionSettings
{
public AlwaysInMemoryConnectionSettings() : base(forceInMemory: true) { }

public AlwaysInMemoryConnectionSettings(byte[] bytes) : base(forceInMemory: true, response: bytes) { }

public AlwaysInMemoryConnectionSettings(
Func<ICollection<Uri>, IConnectionPool> createPool = null,
SourceSerializerFactory sourceSerializerFactory = null,
Expand All @@ -23,7 +25,7 @@ public AlwaysInMemoryConnectionSettings(
createPool,
sourceSerializerFactory,
propertyMappingProvider,
true,
forceInMemory: true,
port
) { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public TestConnectionSettings(
SourceSerializerFactory sourceSerializerFactory = null,
IPropertyMappingProvider propertyMappingProvider = null,
bool forceInMemory = false,
int port = 9200
int port = 9200,
byte[] response = null
)
: base(
CreatePool(createPool, port),
TestConfiguration.Instance.CreateConnection(forceInMemory),
TestConfiguration.Instance.CreateConnection(forceInMemory, response),
CreateSerializerFactory(sourceSerializerFactory),
propertyMappingProvider
) =>
Expand All @@ -40,7 +41,7 @@ public TestConnectionSettings(

private static string LocalHost => "localhost";

private void ApplyTestSettings() =>
private void ApplyTestSettings() =>
RerouteToProxyIfNeeded()
.EnableDebugMode()
.EnableHttpCompression(TestConfiguration.Instance.Random.HttpCompression)
Expand Down
6 changes: 6 additions & 0 deletions src/Tests/Tests.Core/Client/TestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public static class TestClient
public static readonly TestConfigurationBase Configuration = TestConfiguration.Instance;
public static readonly IElasticClient Default = new ElasticClient(new TestConnectionSettings().ApplyDomainSettings());
public static readonly IElasticClient DefaultInMemoryClient = new ElasticClient(new AlwaysInMemoryConnectionSettings().ApplyDomainSettings());
public static IElasticClient FixedInMemoryClient(byte[] response) => new ElasticClient(
new AlwaysInMemoryConnectionSettings(response)
.ApplyDomainSettings()
.DisableDirectStreaming()
.EnableHttpCompression(false)
);

public static readonly IElasticClient DisabledStreaming =
new ElasticClient(new TestConnectionSettings().ApplyDomainSettings().DisableDirectStreaming());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ namespace Tests.Core.Extensions
{
public static class TestConfigurationExtensions
{
public static IConnection CreateConnection(this TestConfigurationBase configuration, bool forceInMemory = false) =>
configuration.RunIntegrationTests && !forceInMemory ? (IConnection)new HttpConnection() : new InMemoryConnection();
public static IConnection CreateConnection(this TestConfigurationBase configuration, bool forceInMemory = false, byte[] response = null) =>
forceInMemory
? new InMemoryConnection(response)
: configuration.RunIntegrationTests
? (IConnection)new HttpConnection()
: new InMemoryConnection(response);

public static bool InRange(this TestConfigurationBase configuration, string range) =>
ElasticVersion.From(configuration.ElasticsearchVersion).InRange(range);
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Tests.Domain/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class Project
.RuleFor(p => p.DateString, (p, d) => d.StartedOn.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"))
.RuleFor(p => p.LastActivity, p => p.Date.Recent())
.RuleFor(p => p.LeadDeveloper, p => Developer.Developers[Gimme.Random.Number(0, Developer.Developers.Count - 1)])
.RuleFor(p => p.Tags, f => Tag.Generator.Generate(Gimme.Random.Number(2, 50)))
.RuleFor(p => p.Tags, f => Tag.Generator.Generate(Gimme.Random.Number(2, 10)))
.RuleFor(p => p.CuratedTags, f => Tag.Generator.Generate(Gimme.Random.Number(1, 5)))
.RuleFor(p => p.LocationPoint, f => SimpleGeoPoint.Generator.Generate())
.RuleFor(p => p.LocationShape, f => new PointGeoShape(new GeoCoordinate(f.Address.Latitude(), f.Address.Latitude())))
Expand Down
68 changes: 49 additions & 19 deletions src/Tests/Tests.ScratchPad/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Elasticsearch.Net;
using Elasticsearch.Net.Diagnostics;
using Nest;
using Tests.Core.Client;
using Tests.Domain;
using Xunit.Sdk;

namespace Tests.ScratchPad
Expand Down Expand Up @@ -46,33 +49,60 @@ void WriteToConsole<T>(string eventName, T data)
}
}

private static async Task Main(string[] args)
{
DiagnosticListener.AllListeners.Subscribe(new ListenerObserver());

using (var node = new Elastic.Managed.Ephemeral.EphemeralCluster("7.0.0"))
{
node.Start();
private static readonly IList<Project> Projects = Project.Generator.Clone().Generate(10000);
private static readonly byte[] Response = TestClient.DefaultInMemoryClient.ConnectionSettings.RequestResponseSerializer.SerializeToBytes(ReturnBulkResponse(Projects));

var settings = new ConnectionSettings(new StaticConnectionPool(new[] { node.NodesUris("ipv4.fiddler").First() }))
.EnableHttpCompression()
.Proxy(new Uri("http://127.0.0.1:8080"), (string)null, (string)null)
;
var client = new ElasticClient(settings);
private static readonly IElasticClient Client =
new ElasticClient(new ConnectionSettings(new InMemoryConnection(Response, 200, null, null))
.DefaultIndex("index")
.EnableHttpCompression(false)
);

var x = client.Search<object>(s=>s.AllIndices());

await Task.Delay(TimeSpan.FromSeconds(7));

Console.WriteLine(new string('-', Console.WindowWidth - 1));
private static async Task Main(string[] args)
{
Console.Write($"Warmup...");
var response = Client.Bulk(b => b.IndexMany(Projects));
Console.WriteLine("\rWarmed up kicking off in 2 seconds!");

var y = client.Search<object>(s=>s.Index("does-not-exist"));
await Task.Delay(TimeSpan.FromSeconds(2));
Console.WriteLine($"Kicking off");

await Task.Delay(TimeSpan.FromSeconds(7));
for (var i = 0; i < 10_000; i++)
{
var r = Client.Bulk(b => b.IndexMany(Projects));
Console.Write($"\r{i}: {r.IsValid} {r.Items.Count}");
}
}


private static object BulkItemResponse(Project project) => new
{
index = new
{
_index = "nest-52cfd7aa",
_type = "_doc",
_id = project.Name,
_version = 1,
_shards = new
{
total = 2,
successful = 1,
failed = 0
},
created = true,
status = 201
}
}
};

private static object ReturnBulkResponse(IList<Project> projects) => new
{
took = 276,
errors = false,
items = projects
.Select(p => BulkItemResponse(p))
.ToArray()
};

private static void Bench<TBenchmark>() where TBenchmark : RunBase => BenchmarkRunner.Run<TBenchmark>();

Expand Down
5 changes: 2 additions & 3 deletions src/Tests/Tests.ScratchPad/Tests.ScratchPad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Optimize>true</Optimize>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.5.1" />
<ProjectReference Include="..\Tests.Core\Tests.Core.csproj" />
<PackageReference Include="BenchMarkDotNet" Version="0.11.5" />
</ItemGroup>
</Project>
</Project>