Permalink
Browse files

Added DiagnosticTests to measure raw throughput to/from redis

  • Loading branch information...
1 parent 1ff1e17 commit a8500ee535c5fca9e8bf4c11f17b864593107717 @mythz mythz committed Oct 12, 2012
@@ -0,0 +1,65 @@
+using System;
+using System.Diagnostics;
+using NUnit.Framework;
+using ServiceStack.Common;
+using ServiceStack.Text;
+
+namespace ServiceStack.Redis.Tests
+{
+ [Explicit("Diagnostic only Integration Test")]
+ [TestFixture]
+ public class DiagnosticTests
+ {
+ const string RedisServer = "or-redis02";
+
+ const int MessageSizeBytes = 1024 * 1024;
+ private const int Count = 10;
+
+ private byte[] RandomBytes(int Length)
+ {
+ var rnd = new Random();
+ var bytes = new byte[Length];
+ for (Int64 i = 0; i < Length; i++)
+ {
+ bytes[i] = (byte)rnd.Next(254);
+ }
+ return bytes;
+ }
+
+ [Test]
+ public void Test_Throughput()
+ {
+ var bytes = RandomBytes(MessageSizeBytes);
+ var swTotal = Stopwatch.StartNew();
+
+ var key = "test:bandwidth:" + bytes.Length;
+
+ int bytesSent = 0;
+ int bytesRecv = 0;
+
+ using (var redisClient = new RedisNativeClient(RedisServer))
+ {
+ Count.Times(x =>
+ {
+ var sw = Stopwatch.StartNew();
+
+ redisClient.Set(key, bytes);
+ bytesSent += bytes.Length;
+ "SEND {0} bytes in {1}ms".Print(bytes.Length, sw.ElapsedMilliseconds);
+
+ sw.Reset();
+ sw.Start();
+ var receivedBytes = redisClient.Get(key);
+ bytesRecv += receivedBytes.Length;
+ "RECV {0} bytes in {1}ms".Print(receivedBytes.Length, sw.ElapsedMilliseconds);
+
+ "TOTAL {0} bytes SENT {0} RECV {1} in {2}ms\n".Print(
+ bytesSent, bytesRecv, swTotal.ElapsedMilliseconds);
+ });
+ }
+ }
+
+ }
+
+
+}
@@ -171,6 +171,7 @@
<Compile Include="AlchemyClientTestsBase.cs" />
<Compile Include="AlchemyNativeClientTests.cs" />
<Compile Include="Benchmarks\RedisMqHostPoolBenchmarks.cs" />
+ <Compile Include="DiagnosticTests.cs" />
<Compile Include="RedisExtensionTests.cs" />
<Compile Include="RedisMqServerSpinServerTests.cs" />
<Compile Include="RedisMqServerSleepServerTests.cs" />

0 comments on commit a8500ee

Please sign in to comment.