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
Hide 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
NUnit.Framework
;
//
using System;
using
System
;
//
using System.Collections.Generic;
using
System.Collections.Generic
;
//
using System.Linq;
using
System.Linq
;
//
using System.Text;
using
System.Text
;
//
using System.Threading.Tasks;
using
System.Threading.Tasks
;
//namespace Tests
namespace
Tests
//{
{
// [TestFixture]
[
TestFixture
]
// public class Batches
public
class
Batches
// {
{
// [Test]
[
Test
]
// public void TestBatchNotSent()
public
void
TestBatchNotSent
()
// {
{
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// conn.Keys.Remove(0, "batch");
var
conn
=
muxer
.
GetDatabase
(
0
);
// conn.Strings.Set(0, "batch", "batch-not-sent");
conn
.
KeyDeleteAsync
(
"batch"
);
// var tasks = new List<Task>();
conn
.
StringSetAsync
(
"batch"
,
"batch-not-sent"
);
// using (var batch = conn.CreateBatch())
var
tasks
=
new
List
<
Task
>();
// {
var
batch
=
conn
.
CreateBatch
();
// tasks.Add(batch.Keys.Remove(0, "batch"));
// tasks.Add(batch.Sets.Add(0, "batch", "a"));
tasks
.
Add
(
batch
.
KeyDeleteAsync
(
"batch"
));
// tasks.Add(batch.Sets.Add(0, "batch", "b"));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"a"
));
// tasks.Add(batch.Sets.Add(0, "batch", "c"));
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"b"
));
// }
tasks
.
Add
(
batch
.
SetAddAsync
(
"batch"
,
"c"
));
// Assert.AreEqual("batch-not-sent", conn.Wait(conn.Strings.GetString(0, "batch")));
// }
// }
// [Test]
Assert
.
AreEqual
(
"batch-not-sent"
,
(
string
)
conn
.
StringGet
(
"batch"
));
// 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());
// var arr = result.Result;
[
Test
]
// Array.Sort(arr);
public
void
TestBatchSent
()
// Assert.AreEqual(3, arr.Length);
{
// Assert.AreEqual("a", arr[0]);
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// Assert.AreEqual("b", arr[1]);
{
// Assert.AreEqual("c", arr[2]);
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
;
//using System.Diagnostics;
using
System.Diagnostics
;
//using System.Text;
using
System.Text
;
//using System.Threading.Tasks;
using
System.Threading.Tasks
;
//using NUnit.Framework;
using
NUnit.Framework
;
using
StackExchange.Redis
;
//namespace Tests
namespace
Tests
//{
{
// [TestFixture]
[
TestFixture
]
// public class Performance
public
class
Performance
// {
{
// [Test]
[
Test
]
// public void VerifyPerformanceImprovement()
public
void
VerifyPerformanceImprovement
()
// {
{
// int asyncTimer, sync, op = 0, asyncFaF, syncFaF;
int
asyncTimer
,
sync
,
op
=
0
,
asyncFaF
,
syncFaF
;
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// // do these outside the timings, just to ensure the core methods are JITted etc
// do these outside the timings, just to ensure the core methods are JITted etc
// for (int db = 0; db < 5; db++ )
for
(
int
db
=
0
;
db
<
5
;
db
++)
// conn.Keys.Remove(db, "perftest");
{
muxer
.
GetDatabase
(
db
).
KeyDeleteAsync
(
"perftest"
);
}
// var timer = Stopwatch.StartNew();
var
timer
=
Stopwatch
.
StartNew
();
// for (int i = 0; i < 100; i++)
for
(
int
i
=
0
;
i
<
100
;
i
++)
// {
{
// // want to test multiplex scenario; test each db, but to make it fair we'll
// want to test multiplex scenario; test each db, but to make it fair we'll
// // do in batches of 10 on each
// do in batches of 10 on each
// for (int db = 0; db < 5; db++)
for
(
int
db
=
0
;
db
<
5
;
db
++)
// for (int j = 0; j < 10; j++)
{
// conn.Strings.Increment(db, "perftest");
var
conn
=
muxer
.
GetDatabase
(
db
);
// }
for
(
int
j
=
0
;
j
<
10
;
j
++)
// asyncFaF = (int)timer.ElapsedMilliseconds;
conn
.
StringIncrementAsync
(
"perftest"
);
// Task<string>[] final = new Task<string>[5];
}
// for (int db = 0; db < 5; db++)
}
// final[db] = conn.Strings.GetString(db, "perftest");
asyncFaF
=
(
int
)
timer
.
ElapsedMilliseconds
;
// conn.WaitAll(final);
Task
<
RedisValue
>[]
final
=
new
Task
<
RedisValue
>[
5
];
// timer.Stop();
for
(
int
db
=
0
;
db
<
5
;
db
++)
// asyncTimer = (int)timer.ElapsedMilliseconds;
final
[
db
]
=
muxer
.
GetDatabase
(
db
).
StringGetAsync
(
"perftest"
);
// Console.WriteLine("async to completion (local): {0}ms", timer.ElapsedMilliseconds);
muxer
.
WaitAll
(
final
);
// for (int db = 0; db < 5; db++)
timer
.
Stop
();
// Assert.AreEqual("1000", final[db].Result, "async, db:" + db);
asyncTimer
=
(
int
)
timer
.
ElapsedMilliseconds
;
// }
Console
.
WriteLine
(
"async to completion (local): {0}ms"
,
timer
.
ElapsedMilliseconds
);
// using (var conn = new Redis(Config.LocalHost, 6379))
for
(
int
db
=
0
;
db
<
5
;
db
++)
// {
Assert
.
AreEqual
(
1000
,
(
long
)
final
[
db
].
Result
,
"async, db:"
+
db
);
// // 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();
using
(
var
conn
=
new
Redis
(
Config
.
LocalHost
,
6379
))
// for (int i = 0; i < 100; i++)
{
// {
// do these outside the timings, just to ensure the core methods are JITted etc
// // want to test multiplex scenario; test each db, but to make it fair we'll
for
(
int
db
=
0
;
db
<
5
;
db
++)
// // do in batches of 10 on each
{
// for (int db = 0; db < 5; db++) {
conn
.
Db
=
db
;
// conn.Db = db;
conn
.
Remove
(
"perftest"
);
// op++;
}
// for (int j = 0; j < 10; j++) {
// conn.Increment("perftest");
var
timer
=
Stopwatch
.
StartNew
();
// op++;
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
// syncFaF = (int)timer.ElapsedMilliseconds;
for
(
int
db
=
0
;
db
<
5
;
db
++)
// string[] final = new string[5];
{
// for (int db = 0; db < 5; db++) {
conn
.
Db
=
db
;
// conn.Db = db;
op
++;
// final[db] = Encoding.ASCII.GetString(conn.Get("perftest"));
for
(
int
j
=
0
;
j
<
10
;
j
++)
// }
{
// timer.Stop();
conn
.
Increment
(
"perftest"
);
// sync = (int)timer.ElapsedMilliseconds;
op
++;
// 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);
}
// }
syncFaF
=
(
int
)
timer
.
ElapsedMilliseconds
;
// int effectiveAsync = ((10 * asyncTimer) + 3) / 10;
string
[]
final
=
new
string
[
5
];
// int effectiveSync = ((10 * sync) + (op * 3)) / 10;
for
(
int
db
=
0
;
db
<
5
;
db
++)
// Console.WriteLine("async to completion with assumed 0.3ms LAN latency: " + effectiveAsync);
{
// Console.WriteLine("sync to completion with assumed 0.3ms LAN latency: " + effectiveSync);
conn
.
Db
=
db
;
// Console.WriteLine("fire-and-forget: {0}ms sync vs {1}ms async ", syncFaF, asyncFaF);
final
[
db
]
=
Encoding
.
ASCII
.
GetString
(
conn
.
Get
(
"perftest"
));
// Assert.Less(effectiveAsync, effectiveSync, "Everything");
}
// Assert.Less(asyncFaF, syncFaF, "Fire and Forget");
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