Permalink
Browse files

Refactoring WorkerQueryKey (#105)

  • Loading branch information...
sebastienros committed Apr 25, 2018
1 parent 8e4ba8e commit fe52ee6cd782ddff50fb097c45b595389ef8add8
@@ -42,6 +42,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Provider.Sqlite", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesSql.Provider.PostgreSql", "src\YesSql.Provider.PostgreSql\YesSql.Provider.PostgreSql.csproj", "{ACC28167-D2C3-426A-9C45-C4906E09BA4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YesSql.Samples.Gating", "samples\YesSql.Samples.Gating\YesSql.Samples.Gating.csproj", "{E6178207-4220-4D29-A8B7-20AE390D70FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -262,6 +264,22 @@ Global
{ACC28167-D2C3-426A-9C45-C4906E09BA4E}.Release|x64.Build.0 = Release|Any CPU
{ACC28167-D2C3-426A-9C45-C4906E09BA4E}.Release|x86.ActiveCfg = Release|Any CPU
{ACC28167-D2C3-426A-9C45-C4906E09BA4E}.Release|x86.Build.0 = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|x64.ActiveCfg = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|x64.Build.0 = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|x86.ActiveCfg = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Debug|x86.Build.0 = Debug|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|Any CPU.Build.0 = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|x64.ActiveCfg = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|x64.Build.0 = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|x86.ActiveCfg = Release|Any CPU
{E6178207-4220-4D29-A8B7-20AE390D70FF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -280,6 +298,10 @@ Global
{C5627926-D605-4F27-8324-F85862D22B05} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{5668D506-DA4C-4910-A4A5-4A3C3DC4576B} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{ACC28167-D2C3-426A-9C45-C4906E09BA4E} = {0C294EC4-E6EF-4839-AD34-335C1A5112F9}
{E6178207-4220-4D29-A8B7-20AE390D70FF} = {0882456B-4A70-4895-A3AE-39B9D30A1B31}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6AB2945-2138-42B9-8F82-FCCF4DFC8F55}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Store.vsmdi
@@ -0,0 +1,10 @@
namespace YesSql.Samples.Gating
{
public class Person
{
public int Id { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public int Age { get; set; }
}
}
@@ -0,0 +1,23 @@
using YesSql.Indexes;
namespace YesSql.Samples.Gating
{
public class PersonByName : MapIndex
{
public string SomeName { get; set; }
public static string Normalize(string name)
{
return name.ToUpperInvariant();
}
}
public class PersonIndexProvider : IndexProvider<Person>
{
public override void Describe(DescribeContext<Person> context)
{
context
.For<PersonByName>()
.Map(person => new PersonByName { SomeName = person.Firstname });
}
}
}
@@ -0,0 +1,124 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using YesSql.Provider.SqlServer;
using YesSql.Provider.Sqlite;
using YesSql.Provider.PostgreSql;
using YesSql.Sql;
namespace YesSql.Samples.Gating
{
class Program
{
static void Main(string[] args)
{
// Uncomment to use SQL Server
var store = new Store(
new Configuration()
.UseSqlServer(@"Data Source =.; Initial Catalog = yessql; Integrated Security = True")
.SetTablePrefix("Gating")
);
// Uncomment to use Sqlite
//var store = new Store(
// new Configuration()
// .UseSqLite("Data Source=yessql.db;Cache=Shared")
// );
// Uncomment to use PostgreSql
//var store = new Store(
// new Configuration()
// .UsePostgreSql(@"Server=localhost;Port=5432;Database=yessql;User Id=root;Password=Password12!;Maximum Pool Size=1024;NoResetOnClose=true;Enlist=false;Max Auto Prepare=200")
// .SetTablePrefix("Gating")
// );
// Uncomment to disable gating
// store.Configuration.DisableQueryGating();
try
{
using (var session = store.CreateSession())
{
new SchemaBuilder(session)
.DropMapIndexTable(nameof(PersonByName))
.DropTable("Identifiers")
.DropTable("Document");
}
}
catch { }
store.InitializeAsync().GetAwaiter().GetResult();
using (var session = store.CreateSession())
{
var builder = new SchemaBuilder(session)
.CreateMapIndexTable(nameof(PersonByName), column => column
.Column<string>(nameof(PersonByName.SomeName))
);
}
store.RegisterIndexes<PersonIndexProvider>();
Console.WriteLine("Creating content...");
using (var session = store.CreateSession())
{
for (var i = 0; i < 10000; i++)
{
session.Save(new Person() { Firstname = "Steve" + i });
}
}
// Warmup
Console.WriteLine("Warming up...");
using (var session = store.CreateSession())
{
Task.Run(async () =>
{
for (var i = 0; i < 500; i++)
{
await session.Query().For<Person>().With<PersonByName>(x => x.SomeName.StartsWith("Steve100")).ListAsync();
await session.Query().For<Person>().With<PersonByName>(x => x.SomeName == "Steve200").ListAsync();
}
}).GetAwaiter().GetResult();
}
var concurrency = 20;
var counter = 0;
var MaxTransactions = 50000;
var stopping = false;
var tasks = Enumerable.Range(1, concurrency).Select(i => Task.Run(async () =>
{
Console.WriteLine($"Starting thread {i}");
await Task.Delay(100);
while (!stopping && Interlocked.Add(ref counter, 1) < MaxTransactions)
{
using (var session = store.CreateSession())
{
await session.Query().For<Person>().With<PersonByName>(x => x.SomeName.StartsWith("Steve100")).ListAsync();
await session.Query().For<Person>().With<PersonByName>(x => x.SomeName == "Steve").ListAsync();
await session.Query().For<Person>().With<PersonByName>().Where(x => x.SomeName == "Steve").ListAsync();
}
}
})).ToList();
tasks.Add(Task.Delay(TimeSpan.FromSeconds(3)));
Task.WhenAny(tasks).GetAwaiter().GetResult();
// Flushing tasks
stopping = true;
Task.WhenAll(tasks).GetAwaiter().GetResult();
stopping = false;
Console.WriteLine(counter);
}
}
}
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\YesSql.Core\YesSql.Core.csproj" />
<ProjectReference Include="..\..\src\YesSql.Provider.PostgreSql\YesSql.Provider.PostgreSql.csproj" />
<ProjectReference Include="..\..\src\YesSql.Provider.Sqlite\YesSql.Provider.Sqlite.csproj" />
<ProjectReference Include="..\..\src\YesSql.Provider.SqlServer\YesSql.Provider.SqlServer.csproj" />
</ItemGroup>
</Project>
Oops, something went wrong.

0 comments on commit fe52ee6

Please sign in to comment.