Marfusios/websocket-client

Calling WebSocketClient Start() or StartOrFail() takes > 2 seconds?

LukeSawyers opened this issue · 2 comments

Hi I'm experiencing some slower-than-Id-expect behavior when starting up the WebsocketClient class
Using Setup:

_webSocket = new WebsocketClient(
    uri, () => new ClientWebSocket { Options = { KeepAliveInterval = TimeSpan.FromMilliseconds(50) } }
)
{
    IsReconnectionEnabled = true,
    ReconnectTimeout = TimeSpan.FromMilliseconds(100),
    ErrorReconnectTimeout = TimeSpan.FromMilliseconds(100)
};

And calling connecting code

public async Task ConnectAsync()
{
    try
    {
        var sw = Stopwatch.StartNew();
        await _webSocket.StartOrFail();
        sw.Stop();
    }
    catch (Exception ex)
    {
        _logger.Warn($"Error in {nameof(ConnectAsync)}", ex);
    }
}

sw.Elapsed will show ~2 sec depending on exact environment, that seems a little long, is there some way of reducing this / am I doing something wrong?

On testing with other socket clients, this seems to be more to do with the server side, please ignore this

Were the other socket clients you tested also based on ClientWebSocket ?

I'm currently running into this same issue, whereas in C++ with boost it connects significantly faster.