@@ -11,16 +11,13 @@ namespace ServiceStack.Redis
11
11
{
12
12
public class RedisPoolConfig
13
13
{
14
- public const int DefaultPoolTimeoutMs = 2000 ;
15
- public const int DefaultMaxPoolSize = 50 ;
14
+ public const int DefaultMaxPoolSize = 20 ;
16
15
17
16
public RedisPoolConfig ( )
18
17
{
19
18
MaxPoolSize = DefaultMaxPoolSize ;
20
- PoolTimeout = TimeSpan . FromMilliseconds ( DefaultPoolTimeoutMs ) ;
21
19
}
22
20
23
- public TimeSpan PoolTimeout { get ; set ; }
24
21
public int MaxPoolSize { get ; set ; }
25
22
}
26
23
@@ -50,7 +47,6 @@ public partial class RedisManagerPool
50
47
51
48
public Action < IRedisNativeClient > ConnectionFilter { get ; set ; }
52
49
53
- public int PoolTimeoutMs { get ; set ; }
54
50
public int MaxPoolSize { get ; set ; }
55
51
56
52
public RedisManagerPool ( ) : this ( RedisNativeClient . DefaultHost ) { }
@@ -74,7 +70,6 @@ public RedisManagerPool(IEnumerable<string> hosts, RedisPoolConfig config)
74
70
75
71
this . OnFailover = new List < Action < IRedisClientsManager > > ( ) ;
76
72
77
- this . PoolTimeoutMs = ( int ) config . PoolTimeout . TotalMilliseconds ;
78
73
this . MaxPoolSize = config . MaxPoolSize ;
79
74
80
75
clients = new RedisClient [ MaxPoolSize ] ;
@@ -121,9 +116,13 @@ public IRedisClient GetClient()
121
116
RedisClient inActiveClient ;
122
117
while ( ( inActiveClient = GetInActiveClient ( ) ) == null )
123
118
{
124
- // wait for a connection, cry out if made to wait too long
125
- if ( ! Monitor . Wait ( clients , PoolTimeoutMs ) )
126
- throw new TimeoutException ( PoolTimeoutError ) ;
119
+ //Create new client outside of pool when max pool size exceeded
120
+ var nextIndex = poolIndex % clients . Length ;
121
+ var nextHost = Hosts [ nextIndex ] ;
122
+ var newClient = InitNewClient ( nextHost ) ;
123
+ //Don't handle callbacks for new client outside pool
124
+ newClient . ClientManager = null ;
125
+ return newClient ;
127
126
}
128
127
129
128
poolIndex ++ ;
@@ -188,21 +187,13 @@ private void InitClient(RedisClient client)
188
187
189
188
public void DisposeClient ( RedisNativeClient client )
190
189
{
191
- lock ( clients )
190
+ for ( var i = 0 ; i < clients . Length ; i ++ )
192
191
{
193
- for ( var i = 0 ; i < clients . Length ; i ++ )
194
- {
195
- var writeClient = clients [ i ] ;
196
- if ( client != writeClient ) continue ;
197
- client . Active = false ;
198
- Monitor . PulseAll ( clients ) ;
199
- return ;
200
- }
192
+ var writeClient = clients [ i ] ;
193
+ if ( client != writeClient ) continue ;
194
+ client . Active = false ;
195
+ return ;
201
196
}
202
-
203
- //Client not found in any pool, pulse both pools.
204
- lock ( clients )
205
- Monitor . PulseAll ( clients ) ;
206
197
}
207
198
208
199
/// <summary>
@@ -211,11 +202,7 @@ public void DisposeClient(RedisNativeClient client)
211
202
/// <param name="client">The client.</param>
212
203
public void DisposeWriteClient ( RedisNativeClient client )
213
204
{
214
- lock ( clients )
215
- {
216
- client . Active = false ;
217
- Monitor . PulseAll ( clients ) ;
218
- }
205
+ client . Active = false ;
219
206
}
220
207
221
208
public Dictionary < string , string > GetStats ( )
@@ -263,14 +250,12 @@ private void AssertValidPool()
263
250
public int [ ] GetClientPoolActiveStates ( )
264
251
{
265
252
var activeStates = new int [ clients . Length ] ;
266
- lock ( clients )
253
+ for ( int i = 0 ; i < clients . Length ; i ++ )
267
254
{
268
- for ( int i = 0 ; i < clients . Length ; i ++ )
269
- {
270
- activeStates [ i ] = clients [ i ] == null
271
- ? - 1
272
- : clients [ i ] . Active ? 1 : 0 ;
273
- }
255
+ var client = clients [ i ] ;
256
+ activeStates [ i ] = client == null
257
+ ? - 1
258
+ : client . Active ? 1 : 0 ;
274
259
}
275
260
return activeStates ;
276
261
}
0 commit comments