Permalink
Browse files

Drastically improve performance when ConnectionLifetime was less then…

… a hour due to a bug in ConnectionPool where all connection are exceed its livetime after one use.

Add minor performance improvement with dose not calc Lifetime on each check, instead cal it once since it dose not change after that.
  • Loading branch information...
lanwin committed Nov 11, 2010
1 parent de04140 commit dcb7912b97efaab231af8fdacb1679626825b9f1
@@ -61,7 +61,7 @@ protected RawConnection CreateRawConnection()
var endPoint = GetNextEndPoint();
try
{
- return new RawConnection(endPoint, Builder.ConnectionTimeout);
+ return new RawConnection(endPoint, Builder.ConnectionTimeout, Builder.ConnectionLifetime);
}catch(SocketException exception){
throw new MongoConnectionException("Failed to connect to server " + endPoint, ConnectionString, endPoint, exception);
}
@@ -119,7 +119,7 @@ private bool IsAlive(RawConnection connection)
return false;
if(Builder.ConnectionLifetime != TimeSpan.Zero)
- if(connection.CreationTime.Add(Builder.ConnectionLifetime) < DateTime.Now)
+ if(connection.Lifetime < DateTime.UtcNow)
return false;
return true;
@@ -19,14 +19,16 @@ internal class RawConnection : IDisposable
/// </summary>
/// <param name="endPoint">The end point.</param>
/// <param name="connectionTimeout">The connection timeout.</param>
- public RawConnection(MongoServerEndPoint endPoint,TimeSpan connectionTimeout)
+ /// <param name="connectionLifetime">The connection lifetime.</param>
+ public RawConnection(MongoServerEndPoint endPoint,TimeSpan connectionTimeout,TimeSpan connectionLifetime)
{
if(endPoint == null)
throw new ArgumentNullException("endPoint");
EndPoint = endPoint;
CreationTime = DateTime.UtcNow;
-
+ Lifetime = connectionLifetime != TimeSpan.Zero ? CreationTime.Add(connectionLifetime) : DateTime.MaxValue;
+
_client.NoDelay = true;
_client.ReceiveTimeout = (int)connectionTimeout.TotalMilliseconds;
_client.SendTimeout = (int)connectionTimeout.TotalMilliseconds;
@@ -79,6 +81,12 @@ public bool IsConnected
/// <value>The creation time.</value>
public DateTime CreationTime { get; private set; }
+ /// <summary>
+ /// Gets or sets the lifetime time.
+ /// </summary>
+ /// <value>The lifetime time.</value>
+ public DateTime Lifetime { get; private set; }
+
/// <summary>
/// Gets or sets the end point.
/// </summary>

0 comments on commit dcb7912

Please sign in to comment.