dandanI have a question about DNS SRV setup for xmpp server for a cluster of XMPP servers. Anyone able to help?
Link Mauvedandan, ask your question, if someone can answer they’ll do so.
Link MauveThey can’t if you don’t ask.
dandanThe question is that I have a cluster of 2 nodes (very simple) deployed on AWS.
dandanI have setup DNS SRV records correctly (hopefully) for all servers.
dandanNow the question is that in case I do not use a load balancer for my servers, to what address should my clients connect to?
dandanFor instance if my configuration is as below:
0 5 5223 server1.mydomain.com
0 5 5223 server2.mydomain.com
then to what address should my clients connect?
dandanshould they connect to server1.mydomain.com or server2.mydomain.com?
Zashthey should pick one of them with about 50/50 chance
dandanYes but that would be up to the client then and different from what load balancer is.
dandanAs far as I have understood, these records are supposed to do the work of load balancer.
Zashbut what you pasted amounts to 50/50 load balancing
Link Mauvedandan, without any software required in front of your server.
dandanWhat do you mean Link Mauve?
dandanAh sure. Yes. I mean no load balancing will be needed in that case. But how the client should decide what server to choose? The client has no idea about the load.
Zashdandan: if you want more control then use a load balancer
Link Mauvedandan, it will pick one at random, throw a coin, and go for that one.
moparisthebestThe client literally flips a coin
Link Mauveflip*, that’s the word.
Link MauveThanks. ^^
dandanOk then. I see.
Zashbut if it for whatever reason can't establish a connection to the chosen one it should try the other
dandanI see. Well is it really realiable? I mean a NLB seems to be a better solution, or?
ZashNo idea what "NLB" is
dandanNetwork Load Balancer
ZashIt's up to you
Zashmore moving parts etc
dandanIf this is totally random by the client side, so why the wight is decided on the server side in DNS record?
moparisthebestdandan: refer to the algorithm here https://tools.ietf.org/html/rfc2782
dandanI mean 50%, 30%, etc.
Zashdandan: that's what the second number is
Link Mauvedandan, because the administrator might have provisioned different size of servers.
Link MauveSo they prefer clients to flip a four-faced coin and go 25% of the time to one physical server, 75% of the time to another one.
Link MauveOr any other possible combinaison.
Zashdandan: in your example you have 5 and 5 as weight. so each entry should have a 5/10 = 50% chance of being selected first
dandanYes I know. This is an example.
dandanOK. Then so if I have 4 servers of shared load of 50%, 30% and 20% then I should flip a dice of 3 sides with respective probabilities?
Zashif you set up SRV records like that, yes
dandanOK thanks. One more question if you don't mind.
dandanIs it OK not to set DNS SRV records and just go for load balancer?
Zashaltho for xmpps you do need them
dandanI am asking because for instance Openfire will complain when DNS SRV records are not set.
Link MauveFor normal _xmpp-client record (non-xmpps), you need either a SRV record or a A record, if the user will only ever connect to a single server (or load-balancer).
GuusOpenfire will warn, but will operate fine.
Link MauveYou can set both but the end result will be identical.
dandanYes I have observed that it work as it should but I was wondering if this is recommended to set DNS SRV records or not.
dandanYes sure. The result will be identical as you said.
Link MauveYou only need a SRV record if you plan to use xmpps (XEP-0368), or if you want to use the inherent “load” balancing SRV provides with multiple records.
Guusor if you want to run a cluster
dandanI run a cluster.
Guusor if you run on a server for which the host name doesn't match the XMPP domain name
Zashor if you wanna use a non-standard port or point at a different machine/A record
dandanand want it to be scalable.
Zash(what Guus said)
Guusgenerally, DNS SRV records are good.
GuusOpenfire should give you concrete examples of DNS SRV records suitable for your instance.
Zashdandan: If I were you I'd worry about using a separate load balancer later if it turns out you need one
Guusbut a general grasp of the concept is good to have, so that you can make informed decisions.
dandanYes I know. But I mean if I use a load balancer then I don't need to set DNS SRV records that are recommended by Openfire.
ZashIt's easy to change DNS
moparisthebestdandan: what's the point of a cluster if you put a single point of failure load balancer in front?
dandanWell, I might be wrong, but by having a cluster I will be able to have fail-over config and scale the system.
Guusdandan, it won't fail over a failing loadbalancer.
moparisthebestHe said AWS, isn't it cheaper to run 1 big server vs 2 small?
dandanThe load balancer in AWS AFAIK is not a single point failure system since the load balancer itself will be scaled. I might be wrong though.
GuusOh, I dropped in half way through the conversation - I missed that.
Link MauveFail-over is also definitely possible with SRV records, if the coin flipped by the client leads it to a dead end^Wserver, it will fallback to the other one(s).
Guusbut yeah, DNS SRV records are less complex by an order of magnitude
Guusthat's generally good.
Guusa lot cheaper too, presumably
Zashyou can have
1 5 5222 first-choice.example.com
2 5 5222 second-choice.example.com
moparisthebestdandan: are you running them both in the same AWS datacenter too?
dandanThen choose randomly between them?
moparisthebestdandan: so single point of failure again
Zashdandan: no, they get tried in order of the priority (first number)
moparisthebestWhole AWS datacenters fail often
Guusdandan i suggest you read up on DNS SRV. They're pretty versatile, and easy to work with. You can always invest in load balancers if you feel that DNS SRV doesn't suit your needs.
Guuswikipedia comes with a handy example
GuusOk, I'm off to bed
dandanZash the question is that how the client will know that for instance the first server is loaded and chose the second one?
Zashdandan: it doesn't
Zashdandan: it sorts the records by priority and if there are multiple with the same priority it'll shuffle them and pick by weight. if the connection fails it removes that one and tries the whole thing again (roughly)
Zashthe RFC moparisthebest linked explains how it works, I recommend you read it
Zashand as I said, if you need more control then use a load balancer
moparisthebestBut you probably don't, and regardless don't run all your services in the same DC if you are after reliability
dandanYes you are right.
dandanI will read the link that moparisthebest sent.
Zashload balancing and high availability at the same time is non-trivial. most xmpp clustering solutions are focused on load balancing afaik
dandanDefinitely need to read more about it.
dandanZash you mean that the clients have knowledge about all servers that a DNS SRV record has been assigned to it?
ZashI don't understand the question
dandanLike your example, a client will also have the list of all serves you listed?
Zashclient would query for the SRV records, receive a list
dandanfirst-choice, second-choice ?
ZashIf you query for _xmpp-client._tcp.example.com you get an aswer with all the SRV records there
dandanAha ok. That is what I wanted to know. Is there any special command for querying in XMPP client libraries like Smack for instance or this should be done in other ways?
Zashthen it follows the sorting algorithm and tries to connect until it gets a connection or runs out of options
ZashI know nothing of Smack, can't help you with that.
dandanOK. Thanks a lot all of you for your kind help.
guus.der.kinderenSmack does SRV lookup by default
guus.der.kinderenIt'll actually warn you if you're connecting to a domain that has no SRV records