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

Test for async-await. #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion progaudi.tarantool.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.9
VisualStudioVersion = 15.0.26430.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "progaudi.tarantool", "src\progaudi.tarantool\progaudi.tarantool.csproj", "{DD007E9F-FB2D-4351-AAB7-F2D367B295C4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "progaudi.tarantool.tests", "tests\progaudi.tarantool.tests\progaudi.tarantool.tests.csproj", "{4C681801-9A6B-4CE9-8EAA-23F80917F046}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "progaudi.benchmark.async-await", "src\progaudi.benchmark.async-await\progaudi.benchmark.async-await.csproj", "{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +43,18 @@ Global
{4C681801-9A6B-4CE9-8EAA-23F80917F046}.Release|x64.Build.0 = Release|Any CPU
{4C681801-9A6B-4CE9-8EAA-23F80917F046}.Release|x86.ActiveCfg = Release|Any CPU
{4C681801-9A6B-4CE9-8EAA-23F80917F046}.Release|x86.Build.0 = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|x64.ActiveCfg = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|x64.Build.0 = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|x86.ActiveCfg = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Debug|x86.Build.0 = Debug|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|Any CPU.Build.0 = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|x64.ActiveCfg = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|x64.Build.0 = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|x86.ActiveCfg = Release|Any CPU
{5EA5C959-4A4F-4186-A2DC-F6028EF056C0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 22 additions & 0 deletions src/progaudi.benchmark.async-await/Benchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
using ProGaudi.Tarantool.Client;
using ProGaudi.Tarantool.Client.Model.Responses;

namespace ProGaudi.Tarantool.Benchmark.Async_Await
{
[CoreJob]
public class Benchmark
{
private readonly Box _box;

public Benchmark()
{
this._box = Box.Connect("localhost", 3301).GetAwaiter().GetResult();
}

[Benchmark]
public async Task<DataResponse<int[]>> Call() => await _box.Call<int>("test_for_benchmarking");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
``` ini

BenchmarkDotNet=v0.10.7, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i5-4590 CPU 3.30GHz (Haswell), ProcessorCount=4
Frequency=3215209 Hz, Resolution=311.0218 ns, Timer=TSC
dotnet cli version=1.0.0
[Host] : .NET Core 4.6.25211.01, 64bit RyuJIT
Core : .NET Core 4.6.25211.01, 64bit RyuJIT

Job=Core Runtime=Core

```
| Method | Mean | Error | StdDev |
|------- |---------:|---------:|---------:|
| Call | 448.1 us | 16.68 us | 47.86 us |
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Method;Job;AnalyzeLaunchVariance;EvaluateOverhead;MaxAbsoluteError;MaxRelativeError;MinInvokeCount;MinIterationTime;RemoveOutliers;Affinity;Jit;Platform;Runtime;AllowVeryLargeObjects;Concurrent;CpuGroups;Force;RetainVm;Server;Clock;EngineFactory;Toolchain;InvocationCount;IterationTime;LaunchCount;RunStrategy;TargetCount;UnrollFactor;WarmupCount;Mean;Error;StdDev
Call;Core;False;Default;Default;Default;Default;Default;Default;15;RyuJit;X64;Core;False;True;False;True;False;False;Default;Default;Default;1;Default;Default;Default;Default;16;Default;448.1 us;16.68 us;47.86 us
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' />
<title>Benchmark</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
<pre><code>
BenchmarkDotNet=v0.10.7, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i5-4590 CPU 3.30GHz (Haswell), ProcessorCount=4
Frequency=3215209 Hz, Resolution=311.0218 ns, Timer=TSC
dotnet cli version=1.0.0
[Host] : .NET Core 4.6.25211.01, 64bit RyuJIT
Core : .NET Core 4.6.25211.01, 64bit RyuJIT
</code></pre>
<pre><code>Job=Core Runtime=Core
</code></pre>

<table>
<thead><tr><th>Method</th><th>Mean</th><th>Error</th><th>StdDev</th>
</tr>
</thead><tbody><tr><td>Call</td><td>448.1 us</td><td>16.68 us</td><td>47.86 us</td>
</tr></tbody></table>
</body>
</html>
9 changes: 9 additions & 0 deletions src/progaudi.benchmark.async-await/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using BenchmarkDotNet.Running;

namespace ProGaudi.Tarantool.Benchmark.Async_Await
{
public static class Program
{
public static void Main() => BenchmarkRunner.Run<Benchmark>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RootNamespace>ProGaudi.Tarantool.Benchmark.Async_Await</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.7" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\progaudi.tarantool\progaudi.tarantool.csproj" />
</ItemGroup>

</Project>
40 changes: 17 additions & 23 deletions src/progaudi.tarantool/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public Box(ClientOptions options)
Metrics = new Metrics(_logicalConnection);
}

public async Task Connect()
public Task Connect()
{
await _logicalConnection.Connect();
return _logicalConnection.Connect();
}

public static async Task<Box> Connect(string replicationSource)
Expand All @@ -38,13 +38,7 @@ public Metrics Metrics
get;
}

public bool IsConnected
{
get
{
return _logicalConnection.IsConnected();
}
}
public bool IsConnected => _logicalConnection.IsConnected();

public static Task<Box> Connect(string host, int port)
{
Expand All @@ -69,15 +63,15 @@ public ISchema GetSchema()
return new Schema(_logicalConnection);
}

public async Task Call_1_6(string functionName)
public Task Call_1_6(string functionName)
{
await Call_1_6<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
return Call_1_6<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
}

public async Task Call_1_6<TTuple>(string functionName, TTuple parameters)
public Task Call_1_6<TTuple>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
{
await Call_1_6<TTuple, TarantoolTuple>(functionName, parameters);
return Call_1_6<TTuple, TarantoolTuple>(functionName, parameters);
}

public Task<DataResponse<TResponse[]>> Call_1_6<TResponse>(string functionName)
Expand All @@ -86,42 +80,42 @@ public Task<DataResponse<TResponse[]>> Call_1_6<TResponse>(string functionName)
return Call_1_6<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
}

public async Task<DataResponse<TResponse[]>> Call_1_6<TTuple, TResponse>(string functionName, TTuple parameters)
public Task<DataResponse<TResponse[]>> Call_1_6<TTuple, TResponse>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
where TResponse : ITarantoolTuple
{
var callRequest = new CallRequest<TTuple>(functionName, parameters, false);
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
return _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
}

public async Task Call(string functionName)
public Task Call(string functionName)
{
await Call<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
return Call<TarantoolTuple, TarantoolTuple>(functionName, TarantoolTuple.Empty);
}

public async Task Call<TTuple>(string functionName, TTuple parameters)
public Task Call<TTuple>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
{
await Call<TTuple, TarantoolTuple>(functionName, parameters);
return Call<TTuple, TarantoolTuple>(functionName, parameters);
}

public Task<DataResponse<TResponse[]>> Call<TResponse>(string functionName)
{
return Call<TarantoolTuple, TResponse>(functionName, TarantoolTuple.Empty);
}

public async Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple parameters)
public Task<DataResponse<TResponse[]>> Call<TTuple, TResponse>(string functionName, TTuple parameters)
where TTuple : ITarantoolTuple
{
var callRequest = new CallRequest<TTuple>(functionName, parameters);
return await _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
return _logicalConnection.SendRequest<CallRequest<TTuple>, TResponse>(callRequest);
}

public async Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple parameters)
public Task<DataResponse<TResponse[]>> Eval<TTuple, TResponse>(string expression, TTuple parameters)
where TTuple : ITarantoolTuple
{
var evalRequest = new EvalRequest<TTuple>(expression, parameters);
return await _logicalConnection.SendRequest<EvalRequest<TTuple>, TResponse>(evalRequest);
return _logicalConnection.SendRequest<EvalRequest<TTuple>, TResponse>(evalRequest);
}

public Task<DataResponse<TResponse[]>> Eval<TResponse>(string expression)
Expand Down
32 changes: 16 additions & 16 deletions src/progaudi.tarantool/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Task<IEnumerable<TResult>> Pairs<TValue, TResult>(TValue value, Iterator
throw new NotImplementedException();
}

public async Task<DataResponse<TTuple[]>> Select<TKey, TTuple>(TKey key, SelectOptions options = null)
public Task<DataResponse<TTuple[]>> Select<TKey, TTuple>(TKey key, SelectOptions options = null)
where TKey : ITarantoolTuple
where TTuple : ITarantoolTuple
{
Expand All @@ -56,33 +56,33 @@ public async Task<DataResponse<TTuple[]>> Select<TKey, TTuple>(TKey key, SelectO
options?.Iterator ?? Iterator.Eq,
key);

return await LogicalConnection.SendRequest<SelectRequest<TKey>, TTuple>(selectRequest);
return LogicalConnection.SendRequest<SelectRequest<TKey>, TTuple>(selectRequest);
}

///Note: there is no such method in specification http://tarantool.org/doc/book/box/box_index.html.
///But common sense, and sources https://github.com/tarantool/tarantool/blob/1.7/src/box/lua/index.c says that that method sould be
public async Task<DataResponse<TTuple[]>> Insert<TTuple>(TTuple tuple)
public Task<DataResponse<TTuple[]>> Insert<TTuple>(TTuple tuple)
where TTuple : ITarantoolTuple
{
var insertRequest = new InsertRequest<TTuple>(SpaceId, tuple);

return await LogicalConnection.SendRequest<InsertReplaceRequest<TTuple>, TTuple>(insertRequest);
return LogicalConnection.SendRequest<InsertReplaceRequest<TTuple>, TTuple>(insertRequest);
}

///Note: there is no such method in specification http://tarantool.org/doc/book/box/box_index.html.
///But common sense, and sources https://github.com/tarantool/tarantool/blob/1.7/src/box/lua/index.c says that that method sould be
public async Task<DataResponse<TTuple[]>> Replace<TTuple>(TTuple tuple)
public Task<DataResponse<TTuple[]>> Replace<TTuple>(TTuple tuple)
where TTuple : ITarantoolTuple
{
var replaceRequest = new ReplaceRequest<TTuple>(SpaceId, tuple);

return await LogicalConnection.SendRequest<InsertReplaceRequest<TTuple>, TTuple>(replaceRequest);
return LogicalConnection.SendRequest<InsertReplaceRequest<TTuple>, TTuple>(replaceRequest);
}

public async Task<TTuple> Min<TTuple>()
public Task<TTuple> Min<TTuple>()
where TTuple : ITarantoolTuple
{
return await Min<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
return Min<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
}

public async Task<TTuple> Min<TTuple, TKey>(TKey key)
Expand All @@ -101,10 +101,10 @@ public async Task<TTuple> Min<TTuple, TKey>(TKey key)
return minResponse.Data.SingleOrDefault();
}

public async Task<TTuple> Max<TTuple>()
public Task<TTuple> Max<TTuple>()
where TTuple : ITarantoolTuple
{
return await Max<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
return Max<TTuple, TarantoolTuple>(TarantoolTuple.Empty);
}

public async Task<TTuple> Max<TTuple, TKey>(TKey key = null)
Expand Down Expand Up @@ -135,7 +135,7 @@ public uint Count<TKey>(TKey key = null, Iterator it = Iterator.Eq)
throw new NotImplementedException();
}

public async Task<DataResponse<TTuple[]>> Update<TTuple, TKey>(TKey key, UpdateOperation[] updateOperations)
public Task<DataResponse<TTuple[]>> Update<TTuple, TKey>(TKey key, UpdateOperation[] updateOperations)
where TKey : ITarantoolTuple
where TTuple : ITarantoolTuple
{
Expand All @@ -145,27 +145,27 @@ public async Task<DataResponse<TTuple[]>> Update<TTuple, TKey>(TKey key, UpdateO
key,
updateOperations);

return await LogicalConnection.SendRequest<UpdateRequest<TKey>, TTuple>(updateRequest);
return LogicalConnection.SendRequest<UpdateRequest<TKey>, TTuple>(updateRequest);
}

public async Task Upsert<TKey>(TKey key, UpdateOperation[] updateOperations)
public Task Upsert<TKey>(TKey key, UpdateOperation[] updateOperations)
where TKey : ITarantoolTuple
{
var updateRequest = new UpsertRequest<TKey>(
SpaceId,
key,
updateOperations);

await LogicalConnection.SendRequestWithEmptyResponse(updateRequest);
return LogicalConnection.SendRequestWithEmptyResponse(updateRequest);
}

public async Task<DataResponse<TTuple[]>> Delete<TKey, TTuple>(TKey key)
public Task<DataResponse<TTuple[]>> Delete<TKey, TTuple>(TKey key)
where TKey : ITarantoolTuple
where TTuple : ITarantoolTuple
{
var deleteRequest = new DeleteRequest<TKey>(SpaceId, Id, key);

return await LogicalConnection.SendRequest<DeleteRequest<TKey>, TTuple>(deleteRequest);
return LogicalConnection.SendRequest<DeleteRequest<TKey>, TTuple>(deleteRequest);
}

public Task Alter(IndexCreationOptions options)
Expand Down
4 changes: 2 additions & 2 deletions src/progaudi.tarantool/LogicalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public async Task SendRequestWithEmptyResponse<TRequest>(TRequest request, TimeS
await SendRequestImpl<TRequest, EmptyResponse>(request, timeout);
}

public async Task<DataResponse<TResponse[]>> SendRequest<TRequest, TResponse>(TRequest request, TimeSpan? timeout = null)
public Task<DataResponse<TResponse[]>> SendRequest<TRequest, TResponse>(TRequest request, TimeSpan? timeout = null)
where TRequest : IRequest
{
return await SendRequestImpl<TRequest, DataResponse<TResponse[]>>(request, timeout);
return SendRequestImpl<TRequest, DataResponse<TResponse[]>>(request, timeout);
}

public static byte[] ReadFully(Stream input)
Expand Down
6 changes: 6 additions & 0 deletions tarantool/testdata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@ function clear_data(spaceNames)
for _, spaceName in ipairs(spaceNames) do
truncate_space(spaceName)
end
end

local test_int = 0
function test_for_benchmarking()
test_int = test_int + 1
return test_int
end