tomcat - Chat Server Load Balancing -


i've read the document on clustering , load balancing apache tomcat servers, i'm confused on how work communication.

let's i'm creating chat app allows users talk 1 through server. if 2 users on same server, that's great, if 1 user on 1 server , other on another? how servers communicate?

i guess point using multiple servers reduce load, if users communicate via server , each user on separate server, 2 servers become each other's client , load not decrease.

my point it's same amount of data into/out of each server, how work when there 1 million users?

you're looking @ 2 different requirements:

  1. load balancing: expose single network address multiple web (or other protocol) servers.
  2. communicating state (the messages) between multiple servers.

the first requirement straightforward: use hardware or software load balancer, or use single apache web server in front of multiple java servers.

the second requirement issue.

let's think hypothetical chat server on single system. when message received, request parsed, , new message placed in memory recipient. there need handling of common situations: user logs off in middle of session, example. need figure out how pass received messages users' browsers. browser can poll ("send me messages after #n user x") or server may able push received messages using 1 of several techniques. if have chat server running on top of web server, should familiar.

the sticky part is: how do on multiple machines? off top of head, can think of couple of ways scale ok:

  • keep track of server recipient on. use transport mechanism send message server can shoved memory if sender had been local. see "message queuing" or "enterprise service bus."
  • decouple message handling communication: designate 1 or more servers active conversations. have recipient server send message servers; use notification mechanism (good) or polling (not good) alert recipient servers there's chat message waiting sent out. special feature: use distributed hash table distribute message mailboxes pool of servers; if 1 or more servers fail, dht can automatically adjust.
  • use broadcast: each server broadcasts other servers if recipient not local. every server receives notification; 1 recipient it.

the key here can no longer make use of shared memory between multiple machines. have use 1 of several possible mechanisms move message between servers. you're unlikely use general-purpose, relatively high overhead protocol (like http) this; there lots of tools more efficient, , can implement @ several levels of abstraction, using shared cache tool terracotta, peer-to-peer network protocol jxta, enterprise service bus activemq, etc. depending on how want put on user's browser, can run message queuing software directly on client system -- notification there's new message can go directly user instead of intermediate mailbox.

the clear optimization support mechanism move user active conversations same server, won't work load balancing mechanisms. there ought way force affinity between particular server user, can't think of easy one.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -