Tuesday, January 22, 2019

Is my use of proxying doing what I think it does?

Hi,

Im trying to make a service for myself where I can have a single endpoint which points to a cluster of docker containers and each container is a different websocket server for a different app.

Here's how I am currently implementing it, the part I am confused about is step 5:

  1. user makes request to someapplication.mysocketservice.com
  2. the request follows the DNS record and resolves an ip address from one of the many cluster servers.
  3. Each server has one daemon container, and then a various amount of application containers.
  4. the daemon container is the only one that can receive traffic on port 443 (for secure websockets!) so it then has to proxy the request to the correct application container based on the Host subdomain (so it looks for 'someapplication' and finds the local ip address of the server which has that container, and also finds the correct port)
  5. Once it resolves the local ip, and port it does the following: (nodejs)

const server = require('http').createServer(app) const httpProxy = require('http-proxy') // other logic... server.on('upgrade', (req, socket, head) => { const { applicationIP, applicationPORT } = resolvePortAndIp(req, socket, head) const proxy = new httpProxy.createProxy({ target: { host: applicationIP, port: applicationPORT, }, }) proxy.ws(req, socket, head) }) 

and this successfully proxies my websocket connection request to the proper container, however what I am confused about is: once the user has connected to the application container, do all future socket messages go directly through the application container?

Is there any overhead remaining on the daemon server after it successfully proxies the request? Ideally the daemon server would simply act as a resolver for the correct container, ie: I want the daemon server to have very low memory/cpu usage so that the other containers running on the same server can use up the rest of the servers resources.



No comments:

Post a Comment