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

General questions #1

Closed
antonioaguilar opened this issue Apr 30, 2017 · 5 comments
Closed

General questions #1

antonioaguilar opened this issue Apr 30, 2017 · 5 comments
Assignees

Comments

@antonioaguilar
Copy link

I have been testing the combination of ws-tcp-relay and websocket-nats using a simple web client.

In my particular scenario, I'm using Docker to launch several ws-tcp-relay instances and connect them to a single NATS server. Then, I have a webapp that uses websocket-nats to connect to a ws-tcp-relay instance randomly and open a websocket session.

I have some general questions about ws-tcp-relay and I'm wondering if you can share some insight.

  1. do you have any info on how many connections a single ws-tcp-relay instance can handle?

  2. at what point does ws-tcp-relay relays the NATS connection?, when a client first connects to the relay? [via nats.connect('ws://localhost:4223')] or when the client first subscribes to a NATS topic?

  3. does ws-tcp-relay keeps the relay session to NATS alive? or is this the responsibility of the client using websocket-nats?

I'm interested in evaluating the scalability of ws-tcp-relay in combination with websocket-nats and I'm wondering if you might have any suggestions or feedback.

Thanks,

A.

@isobit
Copy link
Owner

isobit commented May 1, 2017

  1. Unfortunately I haven't done any stress testing; I haven't yet tried to use this in a large scale project, so that's a bit of uncharted territory. This code is extremely simple though, so I imagine a single instance can handle however many concurrently open connections golang.org/x/net/websocket can handle.
  2. Connections are opened as soon as a websocket opening handshake is received (this is handled by golang.org/x/net/websocket). ws-tcp-relay doesn't know anything about NATS since all it does is stream data between websockets and TCP. With regard to websocket-nats, this indeed happens during nats.connect(...), which internally opens the websocket.
  3. Connections are kept open as long as both the websocket and TCP connections remain open. Either the client or server can terminate the connection at any time, so for usage with NATS, gnatsd should handle timeout and keep-alive. Otherwise, it appears that golang.org/x/net/websocket does not implement ping/pong messages, so it may be worth investigating replacing that with something like github.com/gorilla/websocket.

That all being said, your approach sounds like the right way to go, although I would do the "connect to a ws-tcp-relay instance randomly" part using a load balancer rather than in the client. I would be interested to see how you're setting up your Docker instances, it may be helpful for others to include a simple Dockerfile in the project. Also, would it be easier if I published binaries?

@antonioaguilar
Copy link
Author

Hi @isobit, thank you for your prompt response. I'll be happy to do some stress testing ;-). Below are some Bash scripts I'm using to get Docker to launch 10 instances of the relay server:

First, you need to launch NATS using Docker:

#!/usr/bin/env bash

docker run -d --rm --name="nats-server" --memory=128M -p 4222:4222 -p 8222:8222 nats
#!/usr/bin/env bash

SERVERS=10
NATS_SERVER_IP="0.0.0.0"
RELAY_SERVER_PORT=6001
COUNT=0

while [ $(($COUNT < $SERVERS)) == 1 ];
do

  docker run -it --rm --name="nats-relay-$COUNT" --memory=128M -p $RELAY_SERVER_PORT:$RELAY_SERVER_PORT golang sh -c "go get github.com/joshglendenning/ws-tcp-relay && exec ws-tcp-relay -p $RELAY_SERVER_PORT $NATS_SERVER_IP:4222"

  echo -e "[$COUNT] - WS-TCP RELAY [$RELAY_SERVER_PORT] STARTED";

  COUNT=$(($COUNT + 1))
  RELAY_SERVER_PORT=$(($RELAY_SERVER_PORT + 1))

done

then you can use docker stats to see the containers running.

I'm in the process of documenting my setup and I will be happy to share it when ready.

@isobit isobit self-assigned this May 19, 2017
@Tzelon
Copy link

Tzelon commented Jun 6, 2017

Hey, I'm very interested in stress testing. please share your results
Thank you!

@antonioaguilar
Copy link
Author

Here is the Docker image that I'm using for the testing. Unfortunately, I didn't get to do stress testing so far because I only have one application that connects via WebSocket.

@Tzelon
Copy link

Tzelon commented Jun 7, 2017

Thank you for the update. I will try to make stress testing and will update.

@isobit isobit closed this as completed Oct 10, 2018
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

No branches or pull requests

3 participants