Erlang based chat (load balancing and notifications distribution) -
we going develop backend our messenger, have 1 idea want describe here, maybe can give me advice.
1) idea:
nginx - redirects request random node (round robin) -> erlang cluster - redirects actual node (we choose node minimum number of processes) -> handshake -> upgrade websocket.
every node in cluster has ets table contains number of processes every node (fields - node, num_processes). every node, every 5 secs sends number of processes nodes in cluster.
so don't need have master node, because every node can load balancing.
2) additional question:
is idea register user's active websocket connections (pids) globally gproc? need list every user send notifications through ws enduser.
1) yep - scheme. improvement can make increment load of remote node every time balance load node. keeping estimate remote node load , stops sending load 1 node 5 seconds @ time. every time receive broadcast node, overwrite local estimate - fix missing updates , ensure estimates stay within small amount of actual remote value.
2) use gproc named property {username, true}
each websocket process - let find websocket sessions user throughout cluster.
i forget underlying protocol gproc uses global registrations , cost you'll have registering/deregistering properties time throughout cluster. worked on similar system (user presence , messaging sessions , multi-node load balancing) while , ended writing ngproc in order support cheap name lookup conflict resolution after partitions. it's available open source , might provide ideas can use.
Comments
Post a Comment