[ 
https://issues.apache.org/jira/browse/TINKERPOP-2268?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

MichaelZ updated TINKERPOP-2268:
--------------------------------
    Description: 
When a consumer of the Gremlin.Net client calls to execute a Gremlin query, 
i.e. "SubmitAsync," and there is no valid connection, there will be a costly 
timeout error. I have experienced 30 to 90 second timeouts.

I was on vacation, so I didn't do this earlier, but I have written a little 
patch that will refresh the connection pool when there is no valid connection, 
and it works flawlessly.  This is quick code, and there is a more elegant 
solution, but what I did is to check IsOpen on the first connection snapshot, 
and create a new pool if it was stale.  Here is is the code on the 
GremlinClient object:

private ConnectionPool _connectionPool;

//
 private readonly GremlinServer _gremlinServer = null;
 private readonly GraphSONReader _graphSONReader = null;
 private readonly GraphSONWriter _graphSONWriter = null;
 private readonly string _mimeType = null;

private readonly ConnectionPoolSettings _connectionPoolSettings = null;

private readonly Action<ClientWebSocketOptions> _webSocketConfiguration = null;
 //

public GremlinClient(GremlinServer gremlinServer, GraphSONReader graphSONReader 
= null,
 GraphSONWriter graphSONWriter = null, string mimeType = null,
 ConnectionPoolSettings connectionPoolSettings = null,
 Action<ClientWebSocketOptions> webSocketConfiguration = null)
 {
 //
 _gremlinServer = gremlinServer;
 _graphSONReader = graphSONReader;
 _graphSONWriter = graphSONWriter;
 _mimeType = mimeType;
 _connectionPoolSettings = connectionPoolSettings;
 _webSocketConfiguration = webSocketConfiguration;
 //
 NewConnectionPool();
 }

private void NewConnectionPool()
 {
 var reader = _graphSONReader ?? new GraphSON3Reader();
 var writer = _graphSONWriter ?? new GraphSON3Writer();
 var connectionFactory = new ConnectionFactory(_gremlinServer, reader, writer, 
_mimeType ?? DefaultMimeType,
 _webSocketConfiguration);
 _connectionPool =
 new ConnectionPool(connectionFactory, _connectionPoolSettings ?? new 
ConnectionPoolSettings());
 }

/// <summary>
 /// Provides whether the first available connection snapshot in pool is still 
open.
 /// </summary>
 private bool HasOpenConnection => 
(bool)_connectionPool?.FirstConnectionSnapshot?.IsOpen;

 

public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage)
 {
 if (!HasOpenConnection)
 {
 Debug.WriteLine("=====================================");
 Debug.WriteLine("new connection pool");

NewConnectionPool();
 }

using (var connection = await 
_connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))
 {
 return await connection.SubmitAsync<T>(requestMessage).ConfigureAwait(false);
 }
 }

 

  was:
When a consumer of the Gremlin.Net client calls to execute a Gremlin query, 
i.e. "SubmitAsync," and there is no valid connection, there will be a costly 
timeout error. I have experienced 30 to 90 second timeouts.

I was on vacation, so I didn't do this earlier, but I have written a little 
patch that will refresh the connection pool when there is no valid connection, 
and it works flawlessly.  This is quick code, and there is a more elegant 
solution, but what I did is to check IsOpen on the first connection snapshot, 
and create a new pool if it was stale.  Here is is the code on the 
GremlinClient object:

{{public bool HasOpenConnection => 
(bool)_connectionPool?.FirstConnectionSnapshot?.IsOpen;}}

{{public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage 
requestMessage)}}
{{ {}}
{{ if (!HasOpenConnection)}}
{{ {}}
{{ Debug.WriteLine("=====================================");}}
{{ Debug.WriteLine("new connection pool");}}
{{ var reader = _graphSONReader ?? new GraphSON3Reader();}}
{{ var writer = _graphSONWriter ?? new GraphSON3Writer();}}
{{ var connectionFactory = new ConnectionFactory(_gremlinServer, reader, 
writer, _mimeType ?? DefaultMimeType,}}
{{ _webSocketConfiguration);}}
{{ _connectionPool =}}
{{ new ConnectionPool(connectionFactory, _connectionPoolSettings ?? new 
ConnectionPoolSettings());}}
{{ }}}{{using (var connection = await 
_connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))}}
{{ {}}

{{ return await 
connection.SubmitAsync<T>(requestMessage).ConfigureAwait(false);}}
{{ }}}
{{ }}}

 

 


> Prevent Connection Failure from Hanging
> ---------------------------------------
>
>                 Key: TINKERPOP-2268
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2268
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: dotnet, driver
>         Environment: .Net Core
>            Reporter: MichaelZ
>            Priority: Major
>              Labels: patch
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> When a consumer of the Gremlin.Net client calls to execute a Gremlin query, 
> i.e. "SubmitAsync," and there is no valid connection, there will be a costly 
> timeout error. I have experienced 30 to 90 second timeouts.
> I was on vacation, so I didn't do this earlier, but I have written a little 
> patch that will refresh the connection pool when there is no valid 
> connection, and it works flawlessly.  This is quick code, and there is a more 
> elegant solution, but what I did is to check IsOpen on the first connection 
> snapshot, and create a new pool if it was stale.  Here is is the code on the 
> GremlinClient object:
> private ConnectionPool _connectionPool;
> //
>  private readonly GremlinServer _gremlinServer = null;
>  private readonly GraphSONReader _graphSONReader = null;
>  private readonly GraphSONWriter _graphSONWriter = null;
>  private readonly string _mimeType = null;
> private readonly ConnectionPoolSettings _connectionPoolSettings = null;
> private readonly Action<ClientWebSocketOptions> _webSocketConfiguration = 
> null;
>  //
> public GremlinClient(GremlinServer gremlinServer, GraphSONReader 
> graphSONReader = null,
>  GraphSONWriter graphSONWriter = null, string mimeType = null,
>  ConnectionPoolSettings connectionPoolSettings = null,
>  Action<ClientWebSocketOptions> webSocketConfiguration = null)
>  {
>  //
>  _gremlinServer = gremlinServer;
>  _graphSONReader = graphSONReader;
>  _graphSONWriter = graphSONWriter;
>  _mimeType = mimeType;
>  _connectionPoolSettings = connectionPoolSettings;
>  _webSocketConfiguration = webSocketConfiguration;
>  //
>  NewConnectionPool();
>  }
> private void NewConnectionPool()
>  {
>  var reader = _graphSONReader ?? new GraphSON3Reader();
>  var writer = _graphSONWriter ?? new GraphSON3Writer();
>  var connectionFactory = new ConnectionFactory(_gremlinServer, reader, 
> writer, _mimeType ?? DefaultMimeType,
>  _webSocketConfiguration);
>  _connectionPool =
>  new ConnectionPool(connectionFactory, _connectionPoolSettings ?? new 
> ConnectionPoolSettings());
>  }
> /// <summary>
>  /// Provides whether the first available connection snapshot in pool is 
> still open.
>  /// </summary>
>  private bool HasOpenConnection => 
> (bool)_connectionPool?.FirstConnectionSnapshot?.IsOpen;
>  
> public async Task<ResultSet<T>> SubmitAsync<T>(RequestMessage requestMessage)
>  {
>  if (!HasOpenConnection)
>  {
>  Debug.WriteLine("=====================================");
>  Debug.WriteLine("new connection pool");
> NewConnectionPool();
>  }
> using (var connection = await 
> _connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))
>  {
>  return await connection.SubmitAsync<T>(requestMessage).ConfigureAwait(false);
>  }
>  }
>  



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to