Skip to content

Commit 317721b

Browse files
committed
support ssl
1 parent a57f0e6 commit 317721b

File tree

14 files changed

+223
-525
lines changed

14 files changed

+223
-525
lines changed

PerformanceTest/Base.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using BeetleX.Redis;
2+
using CodeBenchmark;
3+
using StackExchange.Redis;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace PerformanceTest
10+
{
11+
public abstract class BeetleX_Base : IExample
12+
{
13+
public void Dispose()
14+
{
15+
16+
}
17+
18+
public virtual Task Execute()
19+
{
20+
return Task.CompletedTask;
21+
}
22+
23+
public void Initialize(Benchmark benchmark)
24+
{
25+
if (RedisDB == null)
26+
{
27+
RedisDB = new RedisDB(0, new JsonFormater());
28+
RedisDB.Host.AddWriteHost(Program.Host);
29+
}
30+
}
31+
32+
protected static RedisDB RedisDB;
33+
}
34+
35+
public abstract class StackExchangeBase : IExample
36+
{
37+
public void Dispose()
38+
{
39+
40+
}
41+
42+
public virtual Task Execute()
43+
{
44+
return Task.CompletedTask;
45+
}
46+
47+
public void Initialize(Benchmark benchmark)
48+
{
49+
if (RedisDB == null)
50+
{
51+
ConfigurationOptions options = ConfigurationOptions.Parse(Program.Host);
52+
options.AsyncTimeout = 20 * 1000;
53+
options.SyncTimeout = 20 * 1000;
54+
Redis = ConnectionMultiplexer.Connect(options);
55+
RedisDB = Redis.GetDatabase(0);
56+
}
57+
}
58+
59+
protected static ConnectionMultiplexer Redis;
60+
61+
protected static IDatabase RedisDB;
62+
}
63+
}

PerformanceTest/GET_JSON.cs

Lines changed: 50 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -1,243 +1,90 @@
11
using BeetleX.Redis;
2+
using CodeBenchmark;
23
using Northwind.Data;
34
using StackExchange.Redis;
45
using System;
56
using System.Collections.Generic;
67
using System.Text;
8+
using System.Threading.Tasks;
79

810
namespace PerformanceTest
911
{
10-
public class BeetleX_GET : TestBase
11-
{
12-
public BeetleX_GET()
13-
{
14-
RedisDB = new RedisDB(0, new JsonFormater());
15-
RedisDB.Host.AddWriteHost(Program.Host);
16-
}
17-
18-
private RedisDB RedisDB;
19-
20-
21-
protected override void OnTest()
22-
{
23-
base.OnTest();
24-
RunTest();
25-
}
2612

27-
private async void RunTest()
28-
{
29-
while (true)
30-
{
31-
for (int i = 10248; i <= 11077; i++)
32-
{
33-
await RedisDB.Get<Northwind.Data.Order>(i.ToString());
34-
if (!this.Increment())
35-
{
36-
return;
37-
}
38-
}
39-
}
40-
}
41-
}
4213

43-
44-
45-
public class BeetleX_MGET : TestBase
14+
[System.ComponentModel.Category("Redis.Get")]
15+
public class BeetleX_Get : BeetleX_Base
4616
{
47-
public BeetleX_MGET()
48-
{
49-
RedisDB = new RedisDB(0, new JsonFormater());
50-
RedisDB.Host.AddWriteHost(Program.Host);
51-
}
52-
53-
private RedisDB RedisDB;
54-
55-
56-
protected override void OnTest()
57-
{
58-
base.OnTest();
59-
RunTest();
60-
}
61-
62-
private async void RunTest()
17+
public async override Task Execute()
6318
{
64-
while (true)
65-
{
66-
for (int i = 10248; i <= 11077; i = i + 3)
67-
{
68-
var item = await RedisDB.MGet<Northwind.Data.Order, Northwind.Data.Order>
69-
(i.ToString(),
70-
(i + 1).ToString());
71-
if (!this.Increment())
72-
{
73-
return;
74-
}
75-
}
76-
}
19+
await RedisDB.Get<Northwind.Data.Order>(OrderHelper.GetOrderID().ToString());
7720
}
7821
}
7922

80-
public class StackExchange_GET : TestBase
23+
[System.ComponentModel.Category("Redis.MGet")]
24+
public class BeetleX_MGet : BeetleX_Base
8125
{
82-
public StackExchange_GET()
26+
public async override Task Execute()
8327
{
84-
ConfigurationOptions options = ConfigurationOptions.Parse(Program.Host);
85-
options.AsyncTimeout = 20 * 1000;
86-
options.SyncTimeout = 20 * 1000;
87-
Redis = ConnectionMultiplexer.Connect(options);
88-
RedisDB = Redis.GetDatabase(0);
89-
}
90-
91-
private ConnectionMultiplexer Redis;
92-
93-
private IDatabase RedisDB;
94-
95-
protected override void OnTest()
96-
{
97-
base.OnTest();
98-
RunTest();
99-
}
100-
101-
private async void RunTest()
102-
{
103-
while (true)
104-
{
105-
for (int i = 10248; i <= 11077; i++)
106-
{
107-
var data = await RedisDB.StringGetAsync(i.ToString());
108-
var item = Newtonsoft.Json.JsonConvert.DeserializeObject<Northwind.Data.Order>(data);
109-
if (!this.Increment())
110-
{
111-
return;
112-
}
113-
}
114-
}
28+
var id = OrderHelper.GetOrderID();
29+
await RedisDB.MGet<Northwind.Data.Order, Northwind.Data.Order>
30+
(id.ToString(),
31+
(id + 1).ToString());
11532
}
11633
}
11734

11835

119-
public class StackExchange_MGET : TestBase
36+
[System.ComponentModel.Category("Redis.Get")]
37+
public class StackExchange_AsyncGet :StackExchangeBase
12038
{
121-
public StackExchange_MGET()
122-
{
123-
ConfigurationOptions options = ConfigurationOptions.Parse(Program.Host);
124-
options.AsyncTimeout = 20 * 1000;
125-
options.SyncTimeout = 20 * 1000;
126-
Redis = ConnectionMultiplexer.Connect(options);
127-
RedisDB = Redis.GetDatabase(0);
128-
}
129-
130-
private ConnectionMultiplexer Redis;
131-
132-
private IDatabase RedisDB;
133-
134-
protected override void OnTest()
135-
{
136-
base.OnTest();
137-
RunTest();
138-
}
139-
140-
private async void RunTest()
39+
public async override Task Execute()
14140
{
142-
while (true)
143-
{
144-
for (int i = 10248; i <= 11077; i = i + 2)
145-
{
146-
147-
var values = await RedisDB.StringGetAsync(new RedisKey[] { i.ToString(), (i + 1).ToString() });
148-
object item1, item2;
149-
if (!values[0].IsNullOrEmpty)
150-
item1 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[0], typeof(Northwind.Data.Order));
151-
if (!values[1].IsNullOrEmpty)
152-
item2 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[1], typeof(Northwind.Data.Order));
153-
154-
if (!this.Increment())
155-
{
156-
return;
157-
}
158-
}
159-
}
41+
var i = OrderHelper.GetOrderID();
42+
var data= await RedisDB.StringGetAsync(i.ToString());
43+
var item = Newtonsoft.Json.JsonConvert.DeserializeObject<Northwind.Data.Order>(data);
16044
}
16145
}
16246

163-
164-
public class StackExchange_Sync_GET : TestBase
47+
[System.ComponentModel.Category("Redis.MGet")]
48+
public class StackExchange_AsyncMGet :StackExchangeBase
16549
{
166-
public StackExchange_Sync_GET()
50+
public async override Task Execute()
16751
{
168-
ConfigurationOptions options = ConfigurationOptions.Parse(Program.Host);
169-
options.AsyncTimeout = 20 * 1000;
170-
options.SyncTimeout = 20 * 1000;
171-
Redis = ConnectionMultiplexer.Connect(options);
172-
RedisDB = Redis.GetDatabase(0);
52+
var i = OrderHelper.GetOrderID();
53+
var values = await RedisDB.StringGetAsync(new RedisKey[] { i.ToString(), (i + 1).ToString() });
54+
object item1, item2;
55+
if (!values[0].IsNullOrEmpty)
56+
item1 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[0], typeof(Northwind.Data.Order));
57+
if (!values[1].IsNullOrEmpty)
58+
item2 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[1], typeof(Northwind.Data.Order));
17359
}
17460

175-
private ConnectionMultiplexer Redis;
176-
177-
private IDatabase RedisDB;
178-
179-
protected override void OnTest()
180-
{
181-
base.OnTest();
182-
RunTest();
183-
}
184-
185-
private void RunTest()
186-
{
187-
while (true)
188-
{
189-
for (int i = 10248; i <= 11077; i++)
190-
{
191-
var data = RedisDB.StringGet(i.ToString());
192-
var item = Newtonsoft.Json.JsonConvert.DeserializeObject<Northwind.Data.Order>(data);
193-
if (!this.Increment())
194-
{
195-
return;
196-
}
197-
}
198-
}
199-
}
20061
}
20162

202-
public class StackExchange_Sync_MGET : TestBase
63+
[System.ComponentModel.Category("Redis.Get")]
64+
public class StackExchange_SyncGet :StackExchangeBase
20365
{
204-
public StackExchange_Sync_MGET()
66+
public override Task Execute()
20567
{
206-
ConfigurationOptions options = ConfigurationOptions.Parse(Program.Host);
207-
options.AsyncTimeout = 20 * 1000;
208-
options.SyncTimeout = 20 * 1000;
209-
Redis = ConnectionMultiplexer.Connect(options);
210-
RedisDB = Redis.GetDatabase(0);
211-
}
212-
213-
private ConnectionMultiplexer Redis;
214-
215-
private IDatabase RedisDB;
216-
217-
protected override void OnTest()
218-
{
219-
base.OnTest();
220-
RunTest();
68+
var i = OrderHelper.GetOrderID();
69+
var data = RedisDB.StringGet(i.ToString());
70+
var item = Newtonsoft.Json.JsonConvert.DeserializeObject<Northwind.Data.Order>(data);
71+
return base.Execute();
22172
}
73+
}
22274

223-
private void RunTest()
224-
{
225-
while (true)
226-
{
227-
for (int i = 10248; i <= 11077; i++)
228-
{
229-
var values = RedisDB.StringGet(new RedisKey[] { i.ToString(), (i + 1).ToString() });
230-
object item1, item2;
231-
if (!values[0].IsNullOrEmpty)
232-
item1 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[0], typeof(Northwind.Data.Order));
233-
if (!values[1].IsNullOrEmpty)
234-
item2 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[1], typeof(Northwind.Data.Order));
235-
if (!this.Increment())
236-
{
237-
return;
238-
}
239-
}
240-
}
75+
[System.ComponentModel.Category("Redis.MGet")]
76+
public class StackExchange_SyncMGet : StackExchangeBase
77+
{
78+
public override Task Execute()
79+
{
80+
var i = OrderHelper.GetOrderID();
81+
var values = RedisDB.StringGet(new RedisKey[] { i.ToString(), (i + 1).ToString() });
82+
object item1, item2;
83+
if (!values[0].IsNullOrEmpty)
84+
item1 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[0], typeof(Northwind.Data.Order));
85+
if (!values[1].IsNullOrEmpty)
86+
item2 = Newtonsoft.Json.JsonConvert.DeserializeObject(values[1], typeof(Northwind.Data.Order));
87+
return base.Execute();
24188
}
24289
}
24390

PerformanceTest/OrderHelper.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace PerformanceTest
6+
{
7+
public class OrderHelper
8+
{
9+
10+
private static long mID;
11+
12+
public static int GetOrderID()
13+
{
14+
var id = System.Threading.Interlocked.Increment(ref mID);
15+
id = id % (11077 - 10248);
16+
id += 10248;
17+
return (int)id;
18+
}
19+
20+
public static Northwind.Data.Order GetOrder()
21+
{
22+
var id = System.Threading.Interlocked.Increment(ref mID);
23+
return Northwind.Data.DataHelper.Defalut.Orders[(int)(id % Northwind.Data.DataHelper.Defalut.Orders.Count)];
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)