Created
October 12, 2012 21:45
-
-
Save mythz/3881715 to your computer and use it in GitHub Desktop.
Test Redis Throughput
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "<your.redis-hostname>"; | |
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 bytes SENT {0} / RECV {1} in {2}ms\n".Print( | |
bytesSent, bytesRecv, swTotal.ElapsedMilliseconds); | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment