AppConfig.Cache.RedisServers = "127.0.0.1:6379";//,127.0.0.1:6380 - c123456,127.0.0.1:6381 - c123456,127.0.0.1:6382 - c123456,127.0.0.1:6383 - c123456";
//AppConfig.Cache.RedisServers = "redis.txt";
//AppConfig.Cache.RedisServersBak = "redis.bak.txt";
int readCount = 100000, userDBCount = 1;
ThreadPool.SetMaxThreads(1000, 1000);
new ThreadRun(1, readCount, userDBCount).Start();
new ThreadRun(4, readCount, userDBCount).Start();
new ThreadRun(8, readCount, userDBCount).Start();
new ThreadRun(10, readCount, userDBCount).Start();
new ThreadRun(20, readCount, userDBCount).Start();
new ThreadRun(50, readCount, userDBCount).Start();
new ThreadRun(100, readCount, userDBCount).Start();
new ThreadRun(200, readCount, userDBCount).Start();
new ThreadRun(500, readCount, userDBCount).Start();
new ThreadRun(1000, readCount, userDBCount).Start();
new ThreadRun(2000, readCount, userDBCount).Start();
new ThreadRun(5000, readCount, userDBCount).Start();
new ThreadRun(2000, readCount, userDBCount).Start();
new ThreadRun(2000, readCount, userDBCount).Start();
new ThreadRun(500, readCount, userDBCount).Start();
new ThreadRun(200, readCount, userDBCount).Start();
new ThreadRun(100, readCount, userDBCount).Start();
new ThreadRun(50, readCount, userDBCount).Start();
new ThreadRun(20, readCount, userDBCount).Start();
new ThreadRun(10, readCount, userDBCount).Start();
new ThreadRun(8, readCount, userDBCount).Start();
new ThreadRun(4, readCount, userDBCount).Start();
new ThreadRun(1, readCount, userDBCount).Start();
CacheManage.RedisInstance.Clear();//操作对象
Console.WriteLine("End");
Console.WriteLine(CacheManage.RedisInstance.WorkInfo);
Console.WriteLine(CacheManage.RedisInstance.CacheInfo.ToJson(false, false));
----------------------------------------------------------
public class ThreadRun
{
int threadCount, setOrReadCount, useDBCount;
CacheManage cache;
public ThreadRun(int threadCount, int setOrReadCount, int useDBCount)
{
cache = CacheManage.RedisInstance;//操作对象
cache.Clear();
this.threadCount = threadCount;
this.setOrReadCount = setOrReadCount;
this.useDBCount = useDBCount;
}
System.Diagnostics.Stopwatch gloWatch = new System.Diagnostics.Stopwatch();
int runEndCount = 0;
bool isEnd = false;
public void Start()
{
AppConfig.Cache.RedisUseDBCount = useDBCount;
gloWatch.Start();
for (int i = 0; i < threadCount; i++)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadStart), setOrReadCount / threadCount);
}
while (!isEnd)
{
Thread.Sleep(10);
}
}
public void ThreadStart(object readCount)
{
string rndKey = Guid.NewGuid().ToString().Substring(0, 5);
int max = (int)readCount;
for (int i = 0; i < max; i++)
{
string key = rndKey + "key" + i;
if(cache.Set(key, Guid.NewGuid().ToString()))
{
}
else
{
Console.WriteLine("Set 失败 key :" + key);
}
}
Interlocked.Increment(ref runEndCount);
if (runEndCount >= threadCount && !isEnd)
{
isEnd = true;
//gloWatch.Stop();
//Ng 2000ms
//x 1000ms
long t = gloWatch.ElapsedMilliseconds;
Console.