forked from couchbase/EnyimMemcached
/
Program.cs
128 lines (97 loc) · 3.65 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Text;
using Enyim.Caching;
using Enyim.Caching.Memcached;
using System.Net;
using Enyim.Caching.Configuration;
using Membase;
using Membase.Configuration;
using System.Threading;
namespace DemoApp
{
class Program
{
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
// or just initialize the client from code
var nscc = new MembaseClientConfiguration();
nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2);
nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);
nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default"));
//nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default"));
//nscc.Credentials = new NetworkCredential("A", "11111111");
//nscc.Bucket = "content";
//nscc.BucketPassword = "content";
new MembaseClient(nscc).Store(StoreMode.Set, "4q", 1);
new MembaseClient(nscc, "data", "data").Store(StoreMode.Set, "q4", 2);
new MembaseClient(nscc, "feedback", null).Store(StoreMode.Set, "q4", 2);
Console.ReadLine();
//nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory();
//nscc.BucketPassword = "pass";
ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_"));
ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_"));
//ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_"));
//ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_"));
//ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_"));
Console.ReadLine();
return;
var mcc = new MemcachedClientConfiguration();
mcc.AddServer("192.168.2.200:11211");
mcc.AddServer("192.168.2.202:11211");
mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4);
mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4);
mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10);
StressTest(new MemcachedClient(mcc), "TesT_");
return;
var nc = new MembaseClient(nscc, "content", "content");
var stats1 = nc.Stats("slabs");
foreach (var kvp in stats1.GetRaw("curr_connections"))
Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
var nc2 = new MembaseClient(nscc, "content", "content");
var stats2 = nc2.Stats();
foreach (var kvp in stats2.GetRaw("curr_connections"))
Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value);
}
private static void StressTest(MemcachedClient client, string keyPrefix)
{
var i = 0;
var last = true;
var progress = @"-\|/".ToCharArray();
Console.CursorVisible = false;
Dictionary<bool, int> counters = new Dictionary<bool, int>() { { true, 0 }, { false, 0 } };
while (true)
{
var key = keyPrefix + i;
var state = client.Store(StoreMode.Set, key, i) & client.Get<int>(key) == i;
Action updateTitle = () => Console.Title = "Success: " + counters[true] + " Fail: " + counters[false];
if (state != last)
{
Console.ForegroundColor = state ? ConsoleColor.White : ConsoleColor.Red;
Console.Write(".");
counters[state] = 0;
last = state;
updateTitle();
}
else if (i % 200 == 0)
{
//Console.ForegroundColor = state ? ConsoleColor.White : ConsoleColor.Red;
//Console.Write(progress[(i / 200) % 4]);
//if (Console.CursorLeft == 0)
//{
// Console.CursorLeft = Console.WindowWidth - 1;
// Console.CursorTop -= 1;
//}
//else
//{
// Console.CursorLeft -= 1;
//}
updateTitle();
}
i++;
counters[state] = counters[state] + 1;
}
}
}
}