8000 Introduce InitPoolTimeout · cnblogs/EnyimMemcachedCore@60682fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 60682fa

Browse files
committed
Introduce InitPoolTimeout
1 parent 853f283 commit 60682fa

File tree

6 files changed

+271
-217
lines changed

6 files changed

+271
-217
lines changed

Enyim.Caching/Configuration/ISocketPoolConfiguration.cs

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,75 @@
33

44
namespace Enyim.Caching.Configuration
55
{
6-
/// <summary>
7-
/// Defines an interface for configuring the socket pool for the <see cref="T:MemcachedClient"/>.
8-
/// </summary>
9-
public interface ISocketPoolConfiguration
10-
{
11-
/// <summary>
12-
/// Gets or sets a value indicating the minimum amount of sockets per server in the socket pool.
13-
/// </summary>
14-
/// <returns>The minimum amount of sockets per server in the socket pool.</returns>
15-
int MinPoolSize
16-
{
17-
get;
18-
set;
19-
}
6+
/// <summary>
7+
/// Defines an interface for configuring the socket pool for the <see cref="T:MemcachedClient"/>.
8+
/// </summary>
9+
public interface ISocketPoolConfiguration
10+
{
11+
/// <summary>
12+
/// Gets or sets a value indicating the minimum amount of sockets per server in the socket pool.
13+
/// </summary>
14+
/// <returns>The minimum amount of sockets per server in the socket pool.</returns>
15+
int MinPoolSize
16+
{
17+
get;
18+
set;
19+
}
2020

21-
/// <summary>
22-
/// Gets or sets a value indicating the maximum amount of sockets per server in the socket pool.
23-
/// </summary>
24-
/// <returns>The maximum amount of sockets per server in the socket pool.</returns>
25-
int MaxPoolSize
26-
{
27-
get;
28-
set;
29-
}
21+
/// <summary>
22+
/// Gets or sets a value indicating the maximum amount of sockets per server in the socket pool.
23+
/// </summary>
24+
/// <returns>The maximum amount of sockets per server in the socket pool.</returns>
25+
int MaxPoolSize
26+
{
27+
get;
28+
set;
29+
}
3030

31-
/// <summary>
32-
/// Gets or sets a value that specifies the amount of time after which the connection attempt will fail.
33-
/// </summary>
34-
/// <returns>The value of the connection timeout.</returns>
35-
TimeSpan ConnectionTimeout
36-
{
37 F438 -
get;
38-
set;
39-
}
31+
/// <summary>
32+
/// Gets or sets a value that specifies the amount of time after which the connection attempt will fail.
33+
/// </summary>
34+
/// <returns>The value of the connection timeout.</returns>
35+
TimeSpan ConnectionTimeout
36+
{
37+
get;
38+
set;
39+
}
4040

41-
/// <summary>
42-
/// Gets or sets a value that specifies the amount of time after which the getting a connection from the pool will fail.
43-
/// </summary>
44-
/// <returns>The value of the queue timeout.</returns>
45-
TimeSpan QueueTimeout
46-
{
47-
get;
48-
set;
49-
}
41+
/// <summary>
42+
/// Gets or sets a value that specifies the amount of time after which the getting a connection from the pool will fail.
43+
/// </summary>
44+
/// <returns>The value of the queue timeout.</returns>
45+
TimeSpan QueueTimeout
46+
{
47+
get;
48+
set;
49+
}
5050

51-
/// <summary>
52-
/// Gets or sets a value that specifies the amount of time after which receiving data from the socket will fail.
53-
/// </summary>
54-
/// <returns>The value of the receive timeout.</returns>
55-
TimeSpan ReceiveTimeout
56-
{
57-
get;
58-
set;
59-
}
51+
/// <summary>
52+
/// Gets or sets a value that specifies the amount of time after which receiving data from the socket will fail.
53+
/// </summary>
54+
/// <returns>The value of the receive timeout.</returns>
55+
TimeSpan ReceiveTimeout
56+
{
57+
get;
58+
set;
59+
}
6060

61-
/// <summary>
62-
/// Gets or sets a value that specifies the amount of time after which an unresponsive (dead) server will be checked if it is working.
63-
/// </summary>
64-
/// <returns>The value of the dead timeout.</returns>
65-
TimeSpan DeadTimeout
66-
{
67-
get;
68-
set;
69-
}
61+
/// <summary>
62+
/// Gets or sets a value that specifies the amount of time after which an unresponsive (dead) server will be checked if it is working.
63+
/// </summary>
64+
/// <returns>The value of the dead timeout.</returns>
65+
TimeSpan DeadTimeout
66+
{
67+
get;
68+
set;
69+
}
7070

71-
INodeFailurePolicyFactory FailurePolicyFactory { get; set; }
72-
}
71+
TimeSpan InitPoolTimeout { get; set; }
72+
73+
INodeFailurePolicyFactory FailurePolicyFactory { get; set; }
74+
}
7375
}
7476

7577
#region [ License information ]

Enyim.Caching/Configuration/MemcachedClientConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public MemcachedClientConfiguration(
8080

8181
SocketPool.QueueTimeout = options.SocketPool.QueueTimeout;
8282
_logger.LogInformation($"{nameof(SocketPool.QueueTimeout)}: {SocketPool.QueueTimeout}");
83+
84+
SocketPool.InitPoolTimeout = options.SocketPool.InitPoolTimeout;
8385
}
8486

8587
Protocol = options.Protocol;

Enyim.Caching/Configuration/MemcachedClientOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void AddServer(string address, int port)
3030
Servers.Add(new Server { Address = address, Port = port });
3131
}
3232

33-
public void AddDefaultServer() => AddServer("memcached", 11211);
33+
public void AddDefaultServer() => AddServer("memcached", 11211);
3434

3535
public void AddPlainTextAuthenticator(string zone, string userName, string password)
3636
{
@@ -68,6 +68,7 @@ public class SocketPoolOptions
6868
public TimeSpan ReceiveTimeout { get; set; } = new TimeSpan(0, 0, 10);
6969
public TimeSpan DeadTimeout { get; set; } = new TimeSpan(0, 0, 10);
7070
public TimeSpan QueueTimeout { get; set; } = new TimeSpan(0, 0, 0, 0, 100);
71+
public TimeSpan InitPoolTimeout { get; set; } = new TimeSpan(0, 1, 0);
7172

7273
public void CheckPoolSize()
7374
{

Enyim.Caching/Configuration/SocketPoolConfiguration.cs

Lines changed: 100 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,93 +6,106 @@
66

77
namespace Enyim.Caching.Configuration
88
{
9-
public class SocketPoolConfiguration : ISocketPoolConfiguration
10-
{
11-
private int minPoolSize = 10;
12-
private int maxPoolSize = 20;
13-
private TimeSpan connectionTimeout = new TimeSpan(0, 0, 10);
14-
private TimeSpan receiveTimeout = new TimeSpan(0, 0, 10);
15-
private TimeSpan deadTimeout = new TimeSpan(0, 0, 10);
16-
private TimeSpan queueTimeout = new TimeSpan(0, 0, 0, 0, 100);
17-
private INodeFailurePolicyFactory policyFactory = new FailImmediatelyPolicyFactory();
18-
19-
int ISocketPoolConfiguration.MinPoolSize
20-
{
21-
get { return this.minPoolSize; }
22-
set { this.minPoolSize = value; }
23-
}
24-
25-
/// <summary>
26-
/// Gets or sets a value indicating the maximum amount of sockets per server in the socket pool.
27-
/// </summary>
28-
/// <returns>The maximum amount of sockets per server in the socket pool. The default is 20.</returns>
29-
/// <remarks>It should be 0.75 * (number of threads) for optimal performance.</remarks>
30-
int ISocketPoolConfiguration.MaxPoolSize
31-
{
32-
get { return this.maxPoolSize; }
33-
set { this.maxPoolSize = value; }
34-
}
35-
36-
TimeSpan ISocketPoolConfiguration.ConnectionTimeout
37-
{
38-
get { return this.connectionTimeout; }
39-
set
40-
{
41-
if (value < TimeSpan.Zero)
42-
throw new ArgumentOutOfRangeException("value", "value must be positive");
43-
44-
this.connectionTimeout = value;
45-
}
46-
}
47-
48-
TimeSpan ISocketPoolConfiguration.ReceiveTimeout
49-
{
50-
get { return this.receiveTimeout; }
51-
set
52-
{
53-
if (value < TimeSpan.Zero)
54-
throw new ArgumentOutOfRangeException("value", "value must be positive");
55-
56-
this.receiveTimeout = value;
57-
}
58-
}
59-
60-
TimeSpan ISocketPoolConfiguration.QueueTimeout
61-
{
62-
get { return this.queueTimeout; }
63-
set
64-
{
65-
if (value < TimeSpan.Zero)
66-
throw new ArgumentOutOfRangeException("value", "value must be positive");
67-
68-
this.queueTimeout = value;
69-
}
70-
}
71-
72-
TimeSpan ISocketPoolConfiguration.DeadTimeout
73-
{
74-
get { return this.deadTimeout; }
75-
set
76-
{
77-
if (value < TimeSpan.Zero)
78-
throw new ArgumentOutOfRangeException("value", "value must be positive");
79-
80-
this.deadTimeout = value;
81-
}
82-
}
83-
84-
INodeFailurePolicyFactory ISocketPoolConfiguration.FailurePolicyFactory
85-
{
86-
get { return this.policyFactory; }
87-
set
88-
{
89-
if (value == null)
90-
throw new ArgumentNullException("value");
91-
92-
this.policyFactory = value;
93-
}
94-
}
95-
}
9+
public class SocketPoolConfiguration : ISocketPoolConfiguration
10+
{
11+
private int minPoolSize = 10;
12+
private int maxPoolSize = 20;
13+
private TimeSpan connectionTimeout = new TimeSpan(0, 0, 10);
14+
private TimeSpan receiveTimeout = new TimeSpan(0, 0, 10);
15+
private TimeSpan deadTimeout = new TimeSpan(0, 0, 10);
16+
private TimeSpan queueTimeout = new TimeSpan(0, 0, 0, 0, 100);
17+
private TimeSpan _initPoolTimeout = new TimeSpan(0, 1, 0);
18+
private INodeFailurePolicyFactory policyFactory = new FailImmediatelyPolicyFactory();
19+
20+
int ISocketPoolConfiguration.MinPoolSize
21+
{
22+
get { return this.minPoolSize; }
23+
set { this.minPoolSize = value; }
24+
}
25+
26+
/// <summary>
27+
/// Gets or sets a value indicating the maximum amount of sockets per server in the socket pool.
28+
/// </summary>
29+
/// <returns>The maximum amount of sockets per server in the socket pool. The default is 20.</returns>
30+
/// <remarks>It should be 0.75 * (number of threads) for optimal performance.</remarks>
31+
int ISocketPoolConfiguration.MaxPoolSize
32+
{
33+
get { return this.maxPoolSize; }
34+
set { this.maxPoolSize = value; }
35+
}
36+
37+
TimeSpan ISocketPoolConfiguration.ConnectionTimeout
38+
{
39+
get { return this.connectionTimeout; }
40+
set
41+
{
42+
if (value < TimeSpan.Zero)
43+
throw new ArgumentOutOfRangeException("value", "value must be positive");
44+
45+
this.connectionTimeout = value;
46+
}
47+
}
48+
49+
TimeSpan ISocketPoolConfiguration.ReceiveTimeout
50+
{
51+
get { return this.receiveTimeout; }
52+
set
53+
{
54+
if (value < TimeSpan.Zero)
55+
throw new ArgumentOutOfRangeException("value", "value must be positive");
56+
57+
this.receiveTimeout = value;
58+
}
59+
}
60+
61+
TimeSpan ISocketPoolConfiguration.QueueTimeout
62+
{
63+
get { return this.queueTimeout; }
64+
set
65+
{
66+
if (value < TimeSpan.Zero)
67+
throw new ArgumentOutOfRangeException("value", "value must be positive");
68+
69+
this.queueTimeout = value;
70+
}
71+
}
72+
73+
TimeSpan ISocketPoolConfiguration.InitPoolTimeout
74+
{
75+
get { return _initPoolTimeout; }
76+
set
77+
{
78+
if (value < TimeSpan.Zero)
79+
throw new ArgumentOutOfRangeException("value", "value must be positive");
80+
81+
_initPoolTimeout = value;
82+
}
83+
}
84+
85+
TimeSpan ISocketPoolConfiguration.DeadTimeout
86+
{
87+
get { return this.deadTimeout; }
88+
set
89+
{
90+
if (value < TimeSpan.Zero)
91+
throw new ArgumentOutOfRangeException("value", "value must be positive");
92+
93+
this.deadTimeout = value;
94+
}
95+
}
96+
97+
INodeFailurePolicyFactory ISocketPoolConfiguration.FailurePolicyFactory
98+
{
99+
get { return this.policyFactory; }
100+
set
101+
{
102+
if (value == null)
103+
throw new ArgumentNullException("value");
104+
105+
this.policyFactory = value;
106+
}
107+
}
108+
}
96109
}
97110

98111
#region [ License information ]

0 commit comments

Comments
 (0)
0