Commit 83e7d4e7 authored by Marc Gravell's avatar Marc Gravell

attempt to repro #923

parent 0c0b9b6b
using System; using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using StackExchange.Redis; using StackExchange.Redis;
...@@ -10,96 +6,47 @@ namespace TestConsole ...@@ -10,96 +6,47 @@ namespace TestConsole
{ {
internal static class Program internal static class Program
{ {
private static void Main() private static async Task Main()
{ {
Console.WriteLine($"{Environment.OSVersion} / {Environment.Version} / {(Environment.Is64BitProcess ? "64" : "32")}"); using (var conn = Create())
Console.WriteLine(RuntimeInformation.FrameworkDescription);
DateTime stop = DateTime.UtcNow.AddSeconds(30);
int i = 0;
do
{ {
Console.WriteLine(i++); var sub = conn.GetSubscriber();
RunCompetingBatchesOnSameMuxer(); sub.Subscribe("foo", (channel, value) => Console.WriteLine($"{channel}: {value}"));
} while (DateTime.UtcNow < stop); sub.Ping();
Console.WriteLine($"Completed {i} iterations, {2 * i * IterationCount * InnerCount} operations");
await RunPub().ConfigureAwait(false);
}
await Console.Out.WriteLineAsync("Waiting a minute...").ConfigureAwait(false);
await Task.Delay(60 * 1000).ConfigureAwait(false);
} }
private static ConnectionMultiplexer Create() private static ConnectionMultiplexer Create()
{ {
var options = new ConfigurationOptions var options = new ConfigurationOptions
{ {
KeepAlive = 5,
EndPoints = { "localhost:6379" }, EndPoints = { "localhost:6379" },
SyncTimeout = int.MaxValue, SyncTimeout = int.MaxValue,
// CommandMap = CommandMap.Create(new HashSet<string> { "subscribe", "psubscsribe", "publish" }, false), // CommandMap = CommandMap.Create(new HashSet<string> { "subscribe", "psubscsribe", "publish" }, false),
}; };
var muxer = ConnectionMultiplexer.Connect(options); var muxer = ConnectionMultiplexer.Connect(options);
muxer.ConnectionFailed += (s, a) => Console.WriteLine($"Failed: {a.ConnectionType}, {a.EndPoint}, {a.FailureType}, {a.Exception}");
muxer.ConnectionRestored += (s, a) => Console.WriteLine($"Restored: {a.ConnectionType}, {a.EndPoint}, {a.FailureType}, {a.Exception}");
muxer.GetDatabase().Ping(); muxer.GetDatabase().Ping();
return muxer; return muxer;
} }
private const int IterationCount = 500, InnerCount = 20; public static async Task RunPub()
public static void RunCompetingBatchesOnSameMuxer()
{
using (var muxer = Create())
{
var db = muxer.GetDatabase();
Thread x = new Thread(state => BatchRunPings((IDatabase)state))
{
Name = nameof(BatchRunPings)
};
Thread y = new Thread(state => BatchRunIntegers((IDatabase)state))
{
Name = nameof(BatchRunIntegers)
};
var watch = Stopwatch.StartNew();
x.Start(db);
y.Start(db);
x.Join();
y.Join();
watch.Stop();
Console.WriteLine($"{watch.ElapsedMilliseconds}ms");
Console.WriteLine(muxer.GetCounters().Interactive);
Console.WriteLine($"Service Counts: {SocketManager.Shared}");
}
}
private static RedisKey Me([CallerMemberName]string caller = null) => caller;
private static void BatchRunIntegers(IDatabase db)
{ {
var key = Me(); using (var conn = Create())
db.KeyDelete(key);
db.StringSet(key, 1);
Task[] tasks = new Task[InnerCount];
for (int i = 0; i < IterationCount; i++)
{ {
var batch = db.CreateBatch(); var pub = conn.GetSubscriber();
for (int j = 0; j < tasks.Length; j++) for (int i = 0; i < 100; i++)
{ {
tasks[j] = batch.StringIncrementAsync(key); await pub.PublishAsync("foo", i).ConfigureAwait(false);
} }
batch.Execute();
db.Multiplexer.WaitAll(tasks);
if (i % 1000 == 0) Console.WriteLine(i);
}
var count = (long)db.StringGet(key);
Console.WriteLine($"tally: {count}");
}
private static void BatchRunPings(IDatabase db) await Console.Out.WriteLineAsync("Waiting a minute...").ConfigureAwait(false);
{ await Task.Delay(60 * 1000).ConfigureAwait(false);
Task[] tasks = new Task[InnerCount];
for (int i = 0; i < IterationCount; i++)
{
var batch = db.CreateBatch();
for (int j = 0; j < tasks.Length; j++)
{
tasks[j] = batch.ExecuteAsync("echo", "echo" + j);
}
batch.Execute();
db.Multiplexer.WaitAll(tasks);
if (i % 1000 == 0) Console.WriteLine(i);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment