Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Add RawBytesSetBenchmark and Sider example
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed May 27, 2015
1 parent 7fa1b0b commit 0f3d4bd
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ServiceStack.Redis/RedisNativeClient_Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void WriteToSendBuffer(byte[] cmdBytes)
var bytesCopied = 0;
while (bytesCopied < cmdBytes.Length)
{
var copyOfBytes = BufferPool.GetBuffer();
var copyOfBytes = BufferPool.GetBuffer(cmdBytes.Length);
var bytesToCopy = Math.Min(cmdBytes.Length - bytesCopied, copyOfBytes.Length);
Buffer.BlockCopy(cmdBytes, bytesCopied, copyOfBytes, 0, bytesToCopy);
cmdBuffer.Add(new ArraySegment<byte>(copyOfBytes, 0, bytesToCopy));
Expand All @@ -369,7 +369,7 @@ public void WriteToSendBuffer(byte[] cmdBytes)

private bool CouldAddToCurrentBuffer(byte[] cmdBytes)
{
if (cmdBytes.Length + currentBufferIndex < BufferPool.BufferLength)
if (cmdBytes.Length + currentBufferIndex < RedisConfig.BufferLength)
{
Buffer.BlockCopy(cmdBytes, 0, currentBuffer, currentBufferIndex, cmdBytes.Length);
currentBufferIndex += cmdBytes.Length;
Expand Down
68 changes: 68 additions & 0 deletions tests/ServiceStack.Redis.Tests/RedisBenchmarkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,72 @@ public void Compare_sort_nosort_to_smembers_mget()
}
}

[TestFixture]
public class RawBytesSetBenchmark
{
[Test]
public void Benchmark_setting_raw_bytes_8MB()
{
Stopwatch sw;
long ms1, ms2, interval;
int nBytesHandled = 0;
int nBlockSizeBytes = 8000000;
int nMaxIterations = 5;
byte[] pBuffer = new byte[(int)(nBlockSizeBytes)];

// Create Redis Wrapper
var redis = new RedisNativeClient();

// Clear DB
redis.FlushAll();

sw = Stopwatch.StartNew();
ms1 = sw.ElapsedMilliseconds;
for (int i = 0; i < nMaxIterations; i++)
{
redis.Set("eitan" + i.ToString(), pBuffer);
nBytesHandled += nBlockSizeBytes;
}

ms2 = sw.ElapsedMilliseconds;
interval = ms2 - ms1;

// Calculate rate
double dMBPerSEc = nBytesHandled / 1024.0 / 1024.0 / ((double)interval / 1000.0);
Console.WriteLine("ServiceStack.Redis: Rate {0:N4}, Total: {1}ms", dMBPerSEc, ms2);
}

[Test]
public void Benchmark_setting_raw_bytes_8MB_Sider()
{
Stopwatch sw;
long ms1, ms2, interval;
int nBytesHandled = 0;
int nBlockSizeBytes = 8000000;
int nMaxIterations = 5;
byte[] pBuffer = new byte[(int)(nBlockSizeBytes)];

// Create Redis Wrapper
var redis = new Sider.RedisClient();

// Clear DB
redis.FlushAll();

sw = Stopwatch.StartNew();
ms1 = sw.ElapsedMilliseconds;
for (int i = 0; i < nMaxIterations; i++)
{
redis.SetRaw("eitan" + i.ToString(), pBuffer);
nBytesHandled += nBlockSizeBytes;
}

ms2 = sw.ElapsedMilliseconds;
interval = ms2 - ms1;

// Calculate rate
double dMBPerSEc = nBytesHandled / 1024.0 / 1024.0 / ((double)interval / 1000.0);
Console.WriteLine("Sider: Rate {0:N4}, Total: {1}ms", dMBPerSEc, ms2);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
<Reference Include="ServiceStack.Text">
<HintPath>..\..\lib\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="Sider, Version=0.9.3.42023, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\src\packages\Sider.0.9.3\lib\net40-Client\Sider.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
Expand Down
1 change: 1 addition & 0 deletions tests/ServiceStack.Redis.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.3" targetFramework="net40" />
<package id="Sider" version="0.9.3" targetFramework="net40" />
</packages>

0 comments on commit 0f3d4bd

Please sign in to comment.