Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
5ee8505b
Commit
5ee8505b
authored
Jun 17, 2018
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
convert main code to benchmarkdotnet
parent
cad9dacd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
44 deletions
+72
-44
BasicTest.csproj
BasicTest/BasicTest.csproj
+4
-0
Program.cs
BasicTest/Program.cs
+66
-42
SocketManager.cs
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
+2
-2
No files found.
BasicTest/BasicTest.csproj
View file @
5ee8505b
...
@@ -11,6 +11,10 @@
...
@@ -11,6 +11,10 @@
<LangVersion>latest</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.10.14" />
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
<!--<PackageReference Include="StackExchange.Redis" Version="1.2.7-alpha-00002" />-->
<!--<PackageReference Include="StackExchange.Redis" Version="1.2.7-alpha-00002" />-->
...
...
BasicTest/Program.cs
View file @
5ee8505b
using
System
;
using
System
;
using
System.Diagnostics
;
using
BenchmarkDotNet.Attributes
;
using
System.Threading
;
using
BenchmarkDotNet.Columns
;
using
System.Threading.Tasks
;
using
BenchmarkDotNet.Configs
;
using
BenchmarkDotNet.Diagnosers
;
using
BenchmarkDotNet.Jobs
;
using
BenchmarkDotNet.Running
;
using
BenchmarkDotNet.Validators
;
using
StackExchange.Redis
;
using
StackExchange.Redis
;
namespace
BasicTest
namespace
BasicTest
{
{
internal
static
class
Program
static
class
Program
{
{
public
static
async
Task
Main
()
static
void
Main
()
{
{
Thread
.
CurrentThread
.
Name
=
nameof
(
Main
);
// tell BenchmarkDotNet not to force GC.Collect after benchmark iteration
using
(
var
conn
=
await
ConnectionMultiplexer
.
ConnectAsync
(
"127.0.0.1:6379,syncTimeout=2000"
))
// (single iteration contains of multiple (usually millions) of invocations)
{
// it can influence the allocation-heavy Task<T> benchmarks
int
expected
=
0
;
var
gcMode
=
new
GcMode
{
Force
=
false
};
try
{
conn
.
ConnectionFailed
+=
(
sender
,
e
)
=>
Console
.
WriteLine
(
$"
{
e
.
ConnectionType
}
,
{
e
.
FailureType
}
:
{
e
.
Exception
.
Message
}
"
);
var
customConfig
=
ManualConfig
var
db
=
conn
.
GetDatabase
(
3
);
.
Create
(
DefaultConfig
.
Instance
)
// copies all exporters, loggers and basic stuff
.
With
(
JitOptimizationsValidator
.
FailOnError
)
// Fail if not release mode
.
With
(
MemoryDiagnoser
.
Default
)
// use memory diagnoser
.
With
(
StatisticColumn
.
OperationsPerSecond
)
// add ops/s
.
With
(
Job
.
Default
.
With
(
gcMode
));
var
batch
=
db
.
CreateBatch
();
var
summary
=
BenchmarkRunner
.
Run
<
Benchmark
>(
customConfig
);
var
del
=
batch
.
KeyDeleteAsync
(
"abc"
);
Console
.
WriteLine
(
summary
);
var
set
=
batch
.
StringSetAsync
(
"abc"
,
"Does SE.Redis work on System.IO.Pipelines?"
);
}
var
s
=
batch
.
StringGetAsync
(
"abc"
);
}
batch
.
Execute
();
/// <summary>
/// The tests
/// </summary>
public
class
Benchmark
:
IDisposable
{
ConnectionMultiplexer
connection
;
IDatabase
db
;
/// <summary>
/// Create
/// </summary>
public
Benchmark
()
{
connection
=
ConnectionMultiplexer
.
Connect
(
"127.0.0.1:6379,syncTimeout=200000"
);
db
=
connection
.
GetDatabase
(
3
);
}
void
IDisposable
.
Dispose
()
{
connection
?.
Dispose
();
db
=
null
;
connection
=
null
;
}
await
del
;
await
set
;
const
int
COUNT
=
10000
;
Console
.
WriteLine
(
await
s
);
const
int
COUNT
=
10000
;
/// <summary>
var
rand
=
new
Random
(
12345
);
/// Run INCRBY lots of times
RedisKey
counter
=
"counter"
;
/// </summary>
var
watch
=
Stopwatch
.
StartNew
();
[
Benchmark
(
Description
=
"INCRBY"
,
OperationsPerInvoke
=
COUNT
)]
db
.
KeyDelete
(
counter
,
CommandFlags
.
FireAndForget
);
public
int
Execute
()
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
{
{
var
rand
=
new
Random
(
12345
);
int
x
=
rand
.
Next
(
50
);
RedisKey
counter
=
"counter"
;
expected
+=
x
;
db
.
KeyDelete
(
counter
,
CommandFlags
.
FireAndForget
);
db
.
StringIncrement
(
counter
,
x
,
CommandFlags
.
FireAndForget
);
int
expected
=
0
;
}
for
(
int
i
=
0
;
i
<
COUNT
;
i
++)
int
actual
=
(
int
)
await
db
.
StringGetAsync
(
counter
);
{
watch
.
Stop
();
int
x
=
rand
.
Next
(
50
);
Console
.
WriteLine
(
$"
{
expected
}
vs
{
actual
}
,
{
watch
.
ElapsedMilliseconds
}
ms for
{
COUNT
}
incrby"
);
expected
+=
x
;
}
db
.
StringIncrement
(
counter
,
x
,
CommandFlags
.
FireAndForget
);
catch
(
Exception
ex
)
{
Console
.
WriteLine
(
$"expected when fail:
{
expected
}
"
);
Console
.
WriteLine
(
ex
.
Message
);
}
}
}
int
actual
=
(
int
)
db
.
StringGet
(
counter
);
if
(
actual
!=
expected
)
throw
new
InvalidOperationException
(
$"expected:
{
expected
}
, actual:
{
actual
}
"
);
return
actual
;
}
}
}
}
}
}
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
View file @
5ee8505b
...
@@ -175,8 +175,8 @@ internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, C
...
@@ -175,8 +175,8 @@ internal SocketToken BeginConnect(EndPoint endpoint, ISocketCallback callback, C
var
formattedEndpoint
=
Format
.
ToString
(
endpoint
);
var
formattedEndpoint
=
Format
.
ToString
(
endpoint
);
var
t
=
SocketConnection
.
ConnectAsync
(
endpoint
,
PipeOptions
,
var
t
=
SocketConnection
.
ConnectAsync
(
endpoint
,
PipeOptions
,
//
SocketConnectionOptions.SyncReader | SocketConnectionOptions.SyncWriter,
SocketConnectionOptions
.
SyncReader
|
SocketConnectionOptions
.
SyncWriter
,
SocketConnectionOptions
.
None
,
//
SocketConnectionOptions.None,
onConnected
:
conn
=>
EndConnectAsync
(
conn
,
multiplexer
,
log
,
callback
),
onConnected
:
conn
=>
EndConnectAsync
(
conn
,
multiplexer
,
log
,
callback
),
socket
:
socket
);
socket
:
socket
);
GC
.
KeepAlive
(
t
);
// make compiler happier
GC
.
KeepAlive
(
t
);
// make compiler happier
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment