0

I am looking for a bit of guidance here, as after spending lots of time browsing various tutorials and SO answers, I have failed to find something that would help me move forward, although what I want to do is probably a fairly common use case.

I have a GO server, and a WS powered by Gorilla. What I want to do is exchange multiple sources of unrelated data via that WS connection.

Let me try to elaborate :

Say, I have one stream of data that goes as follows : {type: "data_type", payload: "payload"}. That data is processed by one of the Web Components (WC) on the front end. Now, I have many such Web Components on one page on the front end, that respectively need to be fed data of that type. The data as described is NOT common to all these Web Components. That means one of these WC rely on one source of data as typed above, another one of these WC rely on the same type of data, but with obviously different values. These WC "operate" separately.

I am not sure how to go about this.

  • Should the data flow all be managed by one single WS connection ? It would mean in this case, the WS data would need an additional identifier as follows : {web_component_id: "id", type: "data_type", payload: "payload"}

Wouldn't that have an effect on memory consumption on the UI ?

In this case, that means the web server would open a new WS path associated with each one of the Web Components that consume its respective WS data ? Something as follows :

http.HandleFunc("/ws/web_component_id", func(w http.ResponseWriter, r *http.Request) {
  serveWs(pool, w, r)
})

In this case here, it means there would be as many WS connections as there are WC fed with their respective data. That means up to a 1000 simultaneous WS connections potentially. What would be the effect on performance ? If I understood correctly, based on this guy's post about his 3 million WS connections, the effect on performance in my case with 1000 connections, would be negligible.

Is it correct to think of my WC as the Clients the author of the above tutorial describes ?

John Doe
  • 1,092
  • 3
  • 12
  • 25
  • How would tagging messages with a component id have an effect on memory consumption on the UI? – Charlie Tumahai Feb 09 '23 at 06:21
  • @CeriseLimón i'm not sure, i anticipate this possibility. So, are you saying that's the approach you would take ? (1st bullet point) – John Doe Feb 09 '23 at 08:34
  • @CeriseLimón if all connections are handled by one single WS, that means the frequency of messages is higher for that WS. Say, with 1000 WC that receive messages each, I could have 1 message every ms, or more. Wouldn't that affect memory consumption or something ? – John Doe Feb 09 '23 at 09:26
  • 1
    Use a single connection. – Charlie Tumahai Feb 09 '23 at 15:14
  • Thanks. I'll go for that solution, test it, and see how it goes. – John Doe Feb 09 '23 at 22:14
  • As an additional comment, coinbase seems to recommend to have as many WS channels as data subscription types. See 2nd bullet point : https://docs.cloud.coinbase.com/exchange/docs/websocket-best-practices. And someone here (number 7) recommends to monitor memory usage : https://climbtheladder.com/10-websocket-best-practices/ . That's why I was asking. – John Doe Feb 09 '23 at 23:28

0 Answers0