News for hackers. Stuff that matters.
Re:Why is IRC distributed across multiple servers? by LinuxBender on Sunday September 12, 2021 @07:16AM (#28500123)
I can somewhat answer this. Apologies, this became a bit long winded and I have barely touched on several historical, technical and logistical reasons.

Part of the answer is historical and part of this was technical. IRC has been around for a very long time. As such, the earlier versions of the servers and daemons could not accept tens of thousands of client connections ePoll vs Select. The connections between servers are multiplexed and not directly related to the number of people connected to the server. There was also a matter of latency. Servers in a region would keep the messages local to that region, as only people in the same channel get the messages and it was less common to have people in the same channel all over the world. This also changed with time. If there was a split, you lost other regions. This was not always the case, so of course I am over-generalizing since there were many different IRC networks designed by many different people. Being long running services, I had seen a great deal of hesitation to re-architect anything on the fly on at least some of the networks, even after ePoll and modern hardware made it possible to have tens of thousands of people on one server. Some of the smaller IRC networks indeed consolidated into fewer or a single server.

Another facet is logistics and ownership. Many of the bigger networks are comprised of servers owned and managed by different people and organizations. The servers are linked as a matter of trust. That trust can be revoked. Most of the early IRC networks were run by people doing this in their free time with their own money and/or limited resources. In some other cases some organizations prefer to have their own servers so that their own people indeed to not suffer splits for their local communication. There are a myriad of other use-cases and reasons why some organizations had their own servers. Sometimes there was a need to give LocalOps special permissions that would not be permitted network-wide. Despite the technical capability to have less servers, some organizations are not going to give up their local nodes.

One issue not mentioned is permission losses on splits. The issue with splits and permission changes has more to do with the way services are integrated into IRC, or more specifically, aren't. Services are treated like bots with higher privilege and most if not all of them were not written to be multi-master. Rather than dealing with moving services around or pushing for read-only daemons, they just lived with the possibility that there would be splits and they would eventually resolve themselves. I personally would have preferred to see a more common integration with OpenLDAP. Some of the IRC daemons can use LDAP, but it is more of an after-thought, or bolt on. This would have allowed splits to occur without losing channel permissions and clients could be configured to quickly attach to another server in another region and that is just DNS management. This could have been further improved by amending or replacing the IRC RFC's to allow SRV records. This may have been done by now for all I know. I shut down my last public server some time ago.

There is a lot more to this than I could sum up on HN. Anyway, today you can fire up an IRCd of your choice on modern hardware and accept tens of thousands if not hundreds of thousands of people on a single server if you wish. It is technically possible. I would still design the network to have multiple servers, as you will eventually hit a bottleneck. If you really want to do this, you will have to de-tune the anti-ddos counter measures to allow the thundering herd to join your standby server or make code changes to permit the thundering herd briefly on fail-over.

Re:Why is IRC distributed across multiple servers? by wpietri on Sunday September 12, 2021 @12:00PM (#28502306)
People whose only experience is with modern hardware and networks really have a hard time getting the first point. As somebody who started coding around the time IRC was created, hardware and networks are amazingly good compared to what we had at the time.

In the mid-90s, years after IRC was written, I set up a distributed system for the financial traders I was working for. Our between-cities links were 64 kb/s guranteed and could burst all the way up to 256 kb/s. And those links were not super reliable. These were connecting systems with Pentium processor running ~90 MHz with ~8 MB RAM. They did very, very little compared with even the cheapest server slice you can get with AWS.

This is one of those things, like George Washington never knowing about dinosaurs, where it's just hard to comprehend how people thought back in the olden days.

Re:Why is IRC distributed across multiple servers? by rdpintqogeogsaa on Sunday September 12, 2021 @08:50AM (#28500674)
Lots of correct and insightful information here, but I'd like to pick out one specific aspect here.

> [...] clients could be configured to quickly attach to another server in another region and that is just DNS management. This could have been further improved by amending or replacing the IRC RFC's to allow SRV records. This may have been done by now for all I know.

To set the stage: Larger IRC networks balance their global servers. A DNS A query for irc.example.com will yield a list of geographically local servers, possibly shuffled on each query as well.

I know of at least one IRC network that refuses to send even the list of all geographically local servers, only sending a subset, as a measure to avoid trivial DDoS attacks if people don't go around collecting the DNS records ahead of time. I'm told that this actually works because the thread actors are not the sophisticated kind.

Incidentally, I have also noted that some networks will shuffle the order of A records for each query because the clients cannot be trusted to select a random DNS response. Considering something this trivial already doesn't work, I dread to imagine how much a DNS SRV implementation would go wrong, considering it needs both sorting and a weighted random sampling[1] to really work.

[1] https://datatracker.ietf.org/doc/html/rfc2782 page 3 et seq.

Re:Why is IRC distributed across multiple servers? by samsquire on Sunday September 12, 2021 @08:59AM (#28500747)
On some operating systems getaddrinfo sorts the DNS response by IPv6 distance! Breaking load balancing

https://access.redhat.com/solutions/22132

Re:Why is IRC distributed across multiple servers? by toast0 on Sunday September 12, 2021 @11:00AM (#28501748)
This is not exclusive to IPv6, I've seen it on v4 as well. If you've got short DNS TTLs and can return 2-4 records out of a larger pool, that can help, but if your TTLs are longer, you have to consider the handful of recusrive DNS servers that serve a large number of users... You want to give them more records to balance that traffic better.

OTOH, current IRC usage numbers are pretty low, a beefy single server should work, except for the disruption potential of single servers. Latency can be a bit of an issue too, depending on where your users are; not great if users are in south asia and the only server is in east coast US.

Re:Why is IRC distributed across multiple servers? by wayoutthere on Sunday September 12, 2021 @08:17AM (#28500481)
As someone who ran IRC servers in the 90s the technical limitation was the number of file descriptors. I think Linux at the time was limited to 1024 and the biggest server on our network was a DEC Alpha with 4096. The entire network (DALnet at the time) was in the 20-30k user range so we absolutely needed multiple servers.
Re:Why is IRC distributed across multiple servers? by blibble on Sunday September 12, 2021 @08:58AM (#28500733)
there was also no efficient io multiplexing

an ircd with a few thousand clients was cpu bound on poll()/select()

/dev/poll and kqueue/epoll were game changing

Re:Why is IRC distributed across multiple servers? by jlokier on Sunday September 12, 2021 @05:32PM (#28505194)
It was actually possible to delegate subsets of descriptors to child processes doing the poll()/select(), making polling have the same time complexity as /dev/poll and kqueue/epoll, and avoid being CPU bound. Even better if you delegated cold subsets, and kept a hot subset in the main process.

But few knew the trick so it didn't catch on.

Re:Why is IRC distributed across multiple servers? by blibble on Sunday September 12, 2021 @05:48PM (#28505336)
mind explaining how?

with poll()/select() I don't see how you can avoid checking every FD at least once (poll's fd counter aside), vs. epoll() only returning those in the desired state

(and I don't think you could do tricks like epoll_wait() on an epoll fd)

Re:Why is IRC distributed across multiple servers? by jlokier on Sunday September 12, 2021 @06:45PM (#28505743)
Sure.

Fork some child processes, and keep an AF_UNIX socketpair() open to them so you can pass them file descriptiors with SCM_RIGHTS.

Have the main process divide up the fds it is waiting on into a "hot" subset and cold subsets of size at most N, and for each cold subset pick a child process P. fds can be moved between hot and cold at any time, and generally you will move them to hot after they have woken and been used, and move them to cold after a few consecutive poll-cycles where they were not ready. Don't move fds to cold subsets belonging to child processes that you don't want to wake, though.

When the main process is ready to "poll everything", have it iterate over each child process that is not already sleeping, and send a message over the socketpair(), containing a list of fd_set additions and removals to that child's wait-for subset, including the type of poll (read, write, etc).

For each fd where the child doesn't have the real file descriptor yet, pass that over the socketpair() as part of the message. (If threads are usable instead of processes, there's no need to send the file descriptor. But on old systems, the system threads were often implemented by userspace multiplexing with poll/select anyway, so it wasn't a good idea to use threads with this technique.)

As well as a list of changes, this message tells the child process to run poll/select on its subset, and then reply with the set of fds that are ready (and their readiness type).

After issuing all the child process messages, the main process does its own poll/select, to wait for hot fds and replies from the child processes.

The reason this has different scaling properties, despite the overheads, is that each child handles a limited size subset, messages scale with the amount of change activity not the size of sets, and ideally the "coldest" fds end up gathered together in child processes that continue to sleep between a large number of main process polls, so the number of active child processes and messages scales with the amount of change activity as well.

Keep in mind, even active fds are removed from the wait-for subset if they've recently reported they are ready and the poll loop hasn't read/written them yet. So it has similar algorithmic properties to epoll.

As a bonus in the case of select(), the fds in the child processes have smaller values than in the main process. So in addition to the number of fds polled per cycle scaling with the amount of activity instead of the total number of fds, the fd_set bitset size does not grow with the total number of fds either. In the main process the bitset size does grow, but it's possible to juggle fd values with dup2() to overcome that.

Re:Why is IRC distributed across multiple servers? by blibble on Sunday September 12, 2021 @07:50PM (#28506271)
thank you for the detailed response

that is indeed clever and I agree would practically improve the performance drastically for many (most?) workloads

worst case scenario (say all your sockets have a approximately the same chance of waking up): the behaviour devolves into the same as for poll() though?

as a broadcast medium: IRC has some annoying qualities in this regard (inline PINGs at regular intervals, events visible by nearly all that trigger socket avalanches, etc)

Re:Why is IRC distributed across multiple servers? by jlokier on Sunday September 12, 2021 @09:07PM (#28506766)
It does not devolve into poll() scaling behaviour, even in your uniform probability scenario.

To picture it, maybe it helps to consider low and high uniform probabilities. If the uniform probability is a low enough per wait call, epoll/kqueue/etc have low cost per wait call, but so does this child-select method, because most child processes don't wake on each wait call. If the uniform probability is high enough, epoll/kqueue/etc return most of the fds, scaling just like the cost of select/poll, and child-select. So epoll/kqueue/etc and child-select match at the extremes, modulo constant factors.

In general, with a constant-bounded subset size, you can say the cost of unnecessary fd polls is amortised over the necessary fd polls, because unnecessary fd polls only occur in child processes that wake due to a necessary fd poll. So the algorithmic big-O scaling of this method is still the same as epoll/kqueue/etc as the number of fds increases and the probability varies, whether it's uniform or non-uniform.

No guarantees about the constant factors, though. You'd still want to tune parameters, to have enough and not too many in each subset. Constant-bounded subset size ensures scaling but not necessarily optimal performance. You can relax the constant bound and still keep the worst-case big-O scaling, if it's adaptive in the right sort of way, to better handle non-uniform probabilities with fewer processes.

Re:Why is IRC distributed across multiple servers? by blibble on Sunday September 12, 2021 @09:33PM (#28506917)
yes I see now, thanks
Re:Why is IRC distributed across multiple servers? by throwaway20371 on Sunday September 12, 2021 @02:06PM (#28503364)
I'm pretty sure even back then you could edit the hard-coded limit in the source code and recompile. I remember us doing something like this as it was too expensive to just keep buying servers and our apps were connection-happy.
Re:Why is IRC distributed across multiple servers? by NovemberWhiskey on Sunday September 12, 2021 @10:17PM (#28507184)
I recall going down this rabbit hole about fifteen years ago. It is, in principle, possible but you're going to be recompiling everything that could conceivably use an fd_set (so probably every single piece of code that links libc...) because it's a fixed size buffer that scales with FD_SETSIZE.
Re:Why is IRC distributed across multiple servers? by wayoutthere on Monday September 13, 2021 @08:06AM (#28510438)
This was actually less of a problem than it seems in hindsight — back at that time, package managers were relatively new and not often used as were dynamic libraries, so most things were just static binaries compiled from tarballs.
Re:Why is IRC distributed across multiple servers? by NovemberWhiskey on Monday September 13, 2021 @08:26AM (#28510589)
I know 15 years ago feels like it ought to be back in the dimly-veiled prehistory of Linux but actually we were on RHEL4, which was released in 2005.
Re:Why is IRC distributed across multiple servers? by wayoutthere on Tuesday September 14, 2021 @12:33PM (#28527228)
Really? Thought they bumped it in the late 90s. I was running IRC servers mostly in the 1995-2000 timeframe and I remember the connection limit going away at one point? It’s been ages, but I largely quit using IRC once I went to college so it had to be sometime around the late 90s :)

Every network also seemed to have its own fork of ircd (and at least one rewrote it from scratch), so could have just been that the ones I used patched it in and others didn’t.

Re:Why is IRC distributed across multiple servers? by wayoutthere on Sunday September 12, 2021 @05:45PM (#28505309)
1024 was the max you could boost it to; 256 was the default as I recall. Linux 1.x was pretty bootstrappy.
Re:Why is IRC distributed across multiple servers? by Sophira on Sunday September 12, 2021 @09:39AM (#28501042)
> Services are treated like bots with higher privilege

A slight correction: Services normally link as a server to the network, which is how they get the higher privilege that they do (because only servers, not clients, get the ability to kill users from the network, etc).

And to add to this for others who may be curious: typically there is some special configuration on the IRC server side to allow the link, and some additional configuration to disallow clients from changing their nickname to names like "NickServ", etc (but to still allow the names when a server on the network broadcasts a user with that nick). Normal non-Services IRC bots, on the other hand, connect as regular clients.

Re:Why is IRC distributed across multiple servers? by duskwuff on Sunday September 12, 2021 @03:15PM (#28503959)
Services also need to perform actions which aren't possible for ordinary users, like knowing when a user connects, forcibly changing a user's nick, or changing a user's permissions in a channel without being an operator in the channel.
Re:Why is IRC distributed across multiple servers? by hrpnk on Sunday September 12, 2021 @09:10AM (#28500828)
Ah, netsplits were so eventful. I still remember the split-wars where groups would wait for a split to happen and gain operator permissions only to take over a channel on the merge [1].

[1] https://en.wikipedia.org/wiki/IRC_takeover#Riding_the_split

Re:Why is IRC distributed across multiple servers? by sterlind on Sunday September 12, 2021 @12:05PM (#28502328)
wouldn't ChanServ fix things once the split resolves?
Re:Why is IRC distributed across multiple servers? by techrat on Sunday September 12, 2021 @01:25PM (#28503018)
ChanServ is a relatively modern function of IRC. For a good while, still to this day on some networks, services did not exist.
Re:Why is IRC distributed across multiple servers? by hrpnk on Sunday September 12, 2021 @12:14PM (#28502441)
I did not experience that, but you're right: https://en.wikipedia.org/wiki/IRC_services#ChanServ
Re:Why is IRC distributed across multiple servers? by lnxg33k1 on Sunday September 12, 2021 @12:47PM (#28502707)
Not all networks have services, for example that happened a lot on IRCNet which doesn't(? maybe now has?)
Re:Why is IRC distributed across multiple servers? by rain1 on Sunday September 12, 2021 @07:39AM (#28500259)
thanks, really appreciate this comment.
Re:Why is IRC distributed across multiple servers? by LinuxBender on Sunday September 12, 2021 @07:49AM (#28500322)
My pleasure. I am sure others could add a great deal more. There is a very long history and there are many pieces of history I am leaving out. A big part I left out is the individual server rate limits vs. network link rate limits and network topology and that is both a technical and logistical issue.
Re:Why is IRC distributed across multiple servers? by spinax on Sunday September 12, 2021 @08:25AM (#28500522)
One positive thing I'd add - as a user - under logistics is high availability. Life is messy, servers go down planned or unplanned for whatever reasons - IRC networks are in a sense truly 'federated' in that the client will get a new server on reconnect attempts much like webservers behind a load balancer. You never have to worry about your 'home instance' being unavailable, as they're all your home instance. (I speak about the public networks like Libera or OFTC)