Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxConnLifetime #223

Merged
merged 4 commits into from
Aug 22, 2017
Merged

MaxConnLifetime #223

merged 4 commits into from
Aug 22, 2017

Conversation

zhenlineo
Copy link
Contributor

@zhenlineo zhenlineo commented Aug 16, 2017

Added maxConnectionLifeTime into config.
When this config option is set to a non-negative value, the connection will be closed rather than reused when it is obtained from the connection pool.

@zhenlineo zhenlineo changed the title 1.5 conn pool MaxConnLifeTime Aug 16, 2017
_maxConnLifeTime = maxConnLifeTime;
}

public bool IsConnectionReusable(IPooledConnection connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we change this method's name to be more self describing such as ResetAndRestartIdleTimer because it has side effects aside from checks.

Copy link
Contributor Author

@zhenlineo zhenlineo Aug 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was that the outside of this object should not care about Idle timer or life time. The contract was that once this method returns true, then this connection can be reused, a.k.a. putting back to the connection pool. So I would prefer the name stays this IsConnectionReusable


try
{
connection.ClearConnection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not specific for this PR, but if in the middle of a huge resultset streaming, calling RESET may stop the server from streaming more data but it will not help client's consuming pending network buffers - which may take considerable time. Shall we have a means of timeout-ing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we do not provide any API method to stop streaming. Internally our current sessoin.close will also not stop any streaming but buffering all unconsumed results into memory. So we do not need to worry about timing out now.

But this is interesting when we want to add cancellation token into our async methods.

return true;
}

public async Task<bool> IsConnectionReusableAsync(IPooledConnection connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same two comments applies for this method.

var connectionSettings = new ConnectionSettings(uri, AuthTokens.None, Config.DefaultConfig);
var poolSettings = new ConnectionPoolSettings(1, 1, TimeSpan.MaxValue, TimeSpan.MaxValue);
var connectionSettings = new ConnectionSettings(AuthTokens.None, Config.DefaultConfig);
var poolSettings = new ConnectionPoolSettings(1, 1, Config.Infinite, Config.Infinite, Config.Infinite);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may elaborate on what TimeSpan value makes it Infinite. I see the point that we accept -1 as an Infinite, but since we define the type of setting timeout values as TimeSpans, any TimeSpan value less than zero, zero itself or even TimeSpan.MaxValue could be perceived as infinite values. Not a big overhead when set something different than -1, but we shall be more natural.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found System.Threading.TimeOut static class which declares InfiniteTimeSpan static field which is also using -1. No change needed then, but we may point out this in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current decision is that we treat all negative values as Infinite, which is stated in the API docs of Config for these TimeSpan settings.
The Config.Infinite value is internal and as you figured out I get this number from some standard lib.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

{
if (IsConnectionIdleDetectionEnabled())
{
connection.IdleTimer.Start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a bit strange that validator resets timers. Can this happen in the connection pool instead?
Same happens in HasBeenIdleForTooLong.

/// <param name="timeSpan">The max timespan that a connection can be reused after has been created for.</param>
/// <returns>An <see cref="IConfigBuilder"/> instance for further configuration options.</returns>
/// <remarks>Must call <see cref="ToConfig"/> to generate a <see cref="Config"/> instance.</remarks>
IConfigBuilder WithMaxConnectionLifeTime(TimeSpan timeSpan);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should publicly visible name be Lifetime and not LifeTime?

@zhenlineo zhenlineo merged commit 29e7f28 into neo4j:1.5 Aug 22, 2017
@zhenlineo zhenlineo deleted the 1.5-conn-pool branch August 22, 2017 10:03
@zhenlineo zhenlineo changed the title MaxConnLifeTime MaxConnLifetime Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants