简体   繁体   中英

Is it enough to just enable session affinity to ensure connection goes to the right process when utilising clusters and multiple dynos?

I've enabled session affinity on Heroku via the CLI - is this enough to make sure traffic from a user hits the same process (Clustering using throng) on the correct dyno (multiple dynos)?

To be clear, I have no code to handle this. I just use socket.io as is, I don't use sticky sessions or anything . All I've done is enable session affinity.

Is this enough? How can I test it locally?

Not sure if you ever got this answered but thinking through this problem myself. Could potentially be enough, however, Socket.io calls out:

"if you are in a CORS situation (the front domain is different from the server domain) and session affinity is achieved with a cookie, you need to allow credentials:"

Source

Given you're using the default long polling then ws connection order, I think Heroku sticky sessions should be able to route your initial long-poll request to the right dyno. The two things I am unclear on:

  1. Once the long-polling request is distributed to the assigned dyno, does the upgrade to websocket connection also connect to the same dyno?
  2. Given that Heroku auto-scaler does not take websocket connections into account ( source , search for websocket), how would you auto scale the dynos to account for traffic?

On number 2, it could potentially work via the long-polling API request p95 time being used to determine server load but unsure if API latency would increase due to websocket connections/workload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM