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
2c76086f
Commit
2c76086f
authored
Mar 27, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Booksleeve test suite: Batches, Performance, Program
parent
5b5d43cc
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
349 additions
and
342 deletions
+349
-342
Batches.cs
MigratedBookSleeveTestSuite/Batches.cs
+59
-67
Performance.cs
MigratedBookSleeveTestSuite/Performance.cs
+93
-82
Program.cs
MigratedBookSleeveTestSuite/Program.cs
+197
-193
No files found.
MigratedBookSleeveTestSuite/Batches.cs
View file @
2c76086f
//
using NUnit.Framework;
//
using System;
//
using System.Collections.Generic;
//
using System.Linq;
//
using System.Text;
//
using System.Threading.Tasks;
using
NUnit.Framework
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
//namespace Tests
//{
// [TestFixture]
// public class Batches
// {
// [Test]
// public void TestBatchNotSent()
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(0, "batch");
// conn.Strings.Set(0, "batch", "batch-not-sent");
// var tasks = new List<Task>();
// using (var batch = conn.CreateBatch())
// {
// tasks.Add(batch.Keys.Remove(0, "batch"));
// tasks.Add(batch.Sets.Add(0, "batch", "a"));
// tasks.Add(batch.Sets.Add(0, "batch", "b"));
// tasks.Add(batch.Sets.Add(0, "batch", "c"));
// }
// Assert.AreEqual("batch-not-sent", conn.Wait(conn.Strings.GetString(0, "batch")));
// }
// }
namespace
Tests
{
[
TestFixture
]
public
class
Batches
{
[
Test
]
public
void
TestBatchNotSent
()
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
var
conn
=
muxer
.
GetDatabase
(
0
);
conn
.
KeyDeleteAsync
(
"batch"
);
conn
.
StringSetAsync
(
"batch"
,
"batch-not-sent"
);
var
tasks
=
new
List
<
Task
>();
var
batch
=
conn
.
CreateBatch
();
// [Test]
// public void TestBatchSentTogether()
// {
// TestBatchSent(true);
// }
// [Test]
// public void TestBatchSentApart()
// {
// TestBatchSent(false);
// }
// private void TestBatchSent(bool together)
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(0, "batch");
// conn.Strings.Set(0, "batch", "batch-sent");
// var tasks = new List<Task>();
// using (var batch = conn.CreateBatch())
// {
// tasks.Add(batch.Keys.Remove(0, "batch"));
// tasks.Add(batch.Sets.Add(0, "batch", "a"));
// tasks.Add(batch.Sets.Add(0, "batch", "b"));
// tasks.Add(batch.Sets.Add(0, "batch", "c"));
// batch.Send(together);
// }
// var result = conn.Sets.GetAllString(0, "batch");
// tasks.Add(result);
// Task.WhenAll(tasks.ToArray());
tasks
.
Add
(
batch
.
KeyDeleteAsync
(
"batch"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"a"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"b"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"c"
));
// var arr = result.Result;
// Array.Sort(arr);
// Assert.AreEqual(3, arr.Length);
// Assert.AreEqual("a", arr[0]);
// Assert.AreEqual("b", arr[1]);
// Assert.AreEqual("c", arr[2]);
// }
// }
// }
//}
Assert
.
AreEqual
(
"batch-not-sent"
,
(
string
)
conn
.
StringGet
(
"batch"
));
}
}
[
Test
]
public
void
TestBatchSent
()
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
var
conn
=
muxer
.
GetDatabase
(
0
);
conn
.
KeyDeleteAsync
(
"batch"
);
conn
.
StringSetAsync
(
"batch"
,
"batch-sent"
);
var
tasks
=
new
List
<
Task
>();
var
batch
=
conn
.
CreateBatch
();
tasks
.
Add
(
batch
.
KeyDeleteAsync
(
"batch"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"a"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"b"
));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"c"
));
batch
.
Execute
();
var
result
=
conn
.
SetMembersAsync
(
"batch"
);
tasks
.
Add
(
result
);
Task
.
WhenAll
(
tasks
.
ToArray
());
var
arr
=
result
.
Result
;
Array
.
Sort
(
arr
,
(
x
,
y
)
=>
string
.
Compare
(
x
,
y
));
Assert
.
AreEqual
(
3
,
arr
.
Length
);
Assert
.
AreEqual
(
"a"
,
(
string
)
arr
[
0
]);
Assert
.
AreEqual
(
"b"
,
(
string
)
arr
[
1
]);
Assert
.
AreEqual
(
"c"
,
(
string
)
arr
[
2
]);
}
}
}
}
MigratedBookSleeveTestSuite/Performance.cs
View file @
2c76086f
//using System;
//using System.Diagnostics;
//using System.Text;
//using System.Threading.Tasks;
//using NUnit.Framework;
using
System
;
using
System.Diagnostics
;
using
System.Text
;
using
System.Threading.Tasks
;
using
NUnit.Framework
;
using
StackExchange.Redis
;
//namespace Tests
//{
// [TestFixture]
// public class Performance
// {
// [Test]
// public void VerifyPerformanceImprovement()
// {
// int asyncTimer, sync, op = 0, asyncFaF, syncFaF;
// using (var conn = Config.GetUnsecuredConnection())
// {
// // do these outside the timings, just to ensure the core methods are JITted etc
// for (int db = 0; db < 5; db++ )
// conn.Keys.Remove(db, "perftest");
namespace
Tests
{
[
TestFixture
]
public
class
Performance
{
[
Test
]
public
void
VerifyPerformanceImprovement
()
{
int
asyncTimer
,
sync
,
op
=
0
,
asyncFaF
,
syncFaF
;
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
// do these outside the timings, just to ensure the core methods are JITted etc
for
(
int
db
=
0
;
db
<
5
;
db
++)
{
muxer
.
GetDatabase
(
db
).
KeyDeleteAsync
(
"perftest"
);
}
// var timer = Stopwatch.StartNew();
// for (int i = 0; i < 100; i++)
// {
// // want to test multiplex scenario; test each db, but to make it fair we'll
// // do in batches of 10 on each
// for (int db = 0; db < 5; db++)
// for (int j = 0; j < 10; j++)
// conn.Strings.Increment(db, "perftest");
// }
// asyncFaF = (int)timer.ElapsedMilliseconds;
// Task<string>[] final = new Task<string>[5];
// for (int db = 0; db < 5; db++)
// final[db] = conn.Strings.GetString(db, "perftest");
// conn.WaitAll(final);
// timer.Stop();
// asyncTimer = (int)timer.ElapsedMilliseconds;
// Console.WriteLine("async to completion (local): {0}ms", timer.ElapsedMilliseconds);
// for (int db = 0; db < 5; db++)
// Assert.AreEqual("1000", final[db].Result, "async, db:" + db);
// }
// using (var conn = new Redis(Config.LocalHost, 6379))
// {
// // do these outside the timings, just to ensure the core methods are JITted etc
// for (int db = 0; db < 5; db++) {
// conn.Db = db;
// conn.Remove("perftest");
// }
var
timer
=
Stopwatch
.
StartNew
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
// want to test multiplex scenario; test each db, but to make it fair we'll
// do in batches of 10 on each
for
(
int
db
=
0
;
db
<
5
;
db
++)
{
var
conn
=
muxer
.
GetDatabase
(
db
);
for
(
int
j
=
0
;
j
<
10
;
j
++)
conn
.
StringIncrementAsync
(
"perftest"
);
}
}
asyncFaF
=
(
int
)
timer
.
ElapsedMilliseconds
;
Task
<
RedisValue
>[]
final
=
new
Task
<
RedisValue
>[
5
];
for
(
int
db
=
0
;
db
<
5
;
db
++)
final
[
db
]
=
muxer
.
GetDatabase
(
db
).
StringGetAsync
(
"perftest"
);
muxer
.
WaitAll
(
final
);
timer
.
Stop
();
asyncTimer
=
(
int
)
timer
.
ElapsedMilliseconds
;
Console
.
WriteLine
(
"async to completion (local): {0}ms"
,
timer
.
ElapsedMilliseconds
);
for
(
int
db
=
0
;
db
<
5
;
db
++)
Assert
.
AreEqual
(
1000
,
(
long
)
final
[
db
].
Result
,
"async, db:"
+
db
);
}
// var timer = Stopwatch.StartNew();
// for (int i = 0; i < 100; i++)
// {
// // want to test multiplex scenario; test each db, but to make it fair we'll
// // do in batches of 10 on each
// for (int db = 0; db < 5; db++) {
// conn.Db = db;
// op++;
// for (int j = 0; j < 10; j++) {
// conn.Increment("perftest");
// op++;
// }
// }
// }
// syncFaF = (int)timer.ElapsedMilliseconds;
// string[] final = new string[5];
// for (int db = 0; db < 5; db++) {
// conn.Db = db;
// final[db] = Encoding.ASCII.GetString(conn.Get("perftest"));
// }
// timer.Stop();
// sync = (int)timer.ElapsedMilliseconds;
// Console.WriteLine("sync to completion (local): {0}ms", timer.ElapsedMilliseconds);
// for (int db = 0; db < 5; db++)
// Assert.AreEqual("1000", final[db], "async, db:" + db);
// }
// int effectiveAsync = ((10 * asyncTimer) + 3) / 10;
// int effectiveSync = ((10 * sync) + (op * 3)) / 10;
// Console.WriteLine("async to completion with assumed 0.3ms LAN latency: " + effectiveAsync);
// Console.WriteLine("sync to completion with assumed 0.3ms LAN latency: " + effectiveSync);
// Console.WriteLine("fire-and-forget: {0}ms sync vs {1}ms async ", syncFaF, asyncFaF);
// Assert.Less(effectiveAsync, effectiveSync, "Everything");
// Assert.Less(asyncFaF, syncFaF, "Fire and Forget");
// }
// }
//}
using
(
var
conn
=
new
Redis
(
Config
.
LocalHost
,
6379
))
{
// do these outside the timings, just to ensure the core methods are JITted etc
for
(
int
db
=
0
;
db
<
5
;
db
++)
{
conn
.
Db
=
db
;
conn
.
Remove
(
"perftest"
);
}
var
timer
=
Stopwatch
.
StartNew
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
// want to test multiplex scenario; test each db, but to make it fair we'll
// do in batches of 10 on each
for
(
int
db
=
0
;
db
<
5
;
db
++)
{
conn
.
Db
=
db
;
op
++;
for
(
int
j
=
0
;
j
<
10
;
j
++)
{
conn
.
Increment
(
"perftest"
);
op
++;
}
}
}
syncFaF
=
(
int
)
timer
.
ElapsedMilliseconds
;
string
[]
final
=
new
string
[
5
];
for
(
int
db
=
0
;
db
<
5
;
db
++)
{
conn
.
Db
=
db
;
final
[
db
]
=
Encoding
.
ASCII
.
GetString
(
conn
.
Get
(
"perftest"
));
}
timer
.
Stop
();
sync
=
(
int
)
timer
.
ElapsedMilliseconds
;
Console
.
WriteLine
(
"sync to completion (local): {0}ms"
,
timer
.
ElapsedMilliseconds
);
for
(
int
db
=
0
;
db
<
5
;
db
++)
Assert
.
AreEqual
(
"1000"
,
final
[
db
],
"async, db:"
+
db
);
}
int
effectiveAsync
=
((
10
*
asyncTimer
)
+
3
)
/
10
;
int
effectiveSync
=
((
10
*
sync
)
+
(
op
*
3
))
/
10
;
Console
.
WriteLine
(
"async to completion with assumed 0.3ms LAN latency: "
+
effectiveAsync
);
Console
.
WriteLine
(
"sync to completion with assumed 0.3ms LAN latency: "
+
effectiveSync
);
Console
.
WriteLine
(
"fire-and-forget: {0}ms sync vs {1}ms async "
,
syncFaF
,
asyncFaF
);
Assert
.
Less
(
effectiveAsync
,
effectiveSync
,
"Everything"
);
Assert
.
Less
(
asyncFaF
,
syncFaF
,
"Fire and Forget"
);
}
}
}
MigratedBookSleeveTestSuite/Program.cs
View file @
2c76086f
This diff is collapsed.
Click to expand it.
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