137 points · by eproxus · 4y ago · 28 comments
What if we could treat an entire datacenter as a unified whole, a la an IBM mainframe, and use an Erlang style actor system for cross-region communication/coordination?
Lots of interest.
The “k8s way” here is to have your pods quiesce on rollout (old pods marked “unready” and removed from the Service), so existing connections are not torn down, but new connections get sent to the up-level pods. Then when all connections have drained from the down-level pods you terminate them. This would break down if you need to have say 1-hour websockets, but aren’t willing to wait 1h+ to roll out a new release. Is this a common requirement?
Interested to hear examples of cases where extremely long-lived connections are worth a lot of engineering pain to achieve.
To do so, we've built an application specific process migration system (this is BEAM VM processes, not OS processes) that is able to essentially live migrate processes both between nodes and software versions, allowing us to essentially replace the engine of the train while it's running, and also be able to scale up and down our clusters as needed.
We are able to roll out updates across a hundred million processes on our distributed system in half an hour with no disruption to service. These are for internal services. For external services, we built the concept of "session resumption" which allows us to sever the TCP connection, have it accepted by a new/different host, and have it continue as if the connection wasn't ever terminated.
Is this based on Alex Snoeren's TCP Connection Migration draft ? - https://datatracker.ietf.org/doc/html/draft-snoeren-tcp-migr...
Some old game server processes would support a "copyover" function. They would write the file descriptors of connected sockets to a file, restart the process, then read the list of file descriptors back into memory and resume normal use of the socket. Unsophisticated, but it works. It's completely transparent to the client because the connection is never actually closed. The worst the client might experience is some latency as their input gets buffered by the OS while the server process restarts.
Of course the connection would not persist over a physical server restart (or something like a pod being killed or whatever). I imagine it's possible to move a connection between nodes, though, with a fairly similar process.
If you define a "Server" as a logical piece of functionality not directly mapped to a OS Process, then it can be done. See https://news.ycombinator.com/item?id=32067570
Do you have a ballpark feel for the cost of just terminating connections? Is it mainly a tail latency thing where you might try to push a message down a socket that is currently reconnecting, and have to wait way longer than normal? Or a CPU/network overhead thing due to how many open connections you have, with a full restart causing a thundering herd of activity?
Now obviously when calling utilities that can be an issue, but internally to an actor if you’re careful it can let you process something the recurse into the next version of the actor.
When I was at WhatsApp, I regularly observed connections from mobile phones (S60 mostly had the longest connection times, but all clients without a working platform push service will try to remain connected) in excess of 30 days. We weren't going against the framework to keep those though, we were all in on hot loading, and didn't do any container rigamarole until the move to Facebook. Keeping alive connections alive reduces work for client and server, and some networks are terrible and getting a connection takes many attempts, but often a working connection will continue to work; of course, some networks are terrible and timeout connections after 10 seconds of idle, but usually that's temporary.
If your 'long' connections are usually around a minute, like is common in http use cases, it's not too bad to keep old servers around while they drain, but if it's an hour or more, you'd need 2x the instances while you're rolling out, if you want to rollout in less than an hour... if you rollout quickly, and want to rollout a follow on, you're going to see even more. Depending on how you manage things, maybe the old and new instances can share machines, resource usage on the old should drop off quickly, but you might not be able to actually fit many instances on one machine, or resource allocation might not allow for it.
We would still have to kill connections in use sometimes; hot loading the BEAM could be possible, but it's not built for that and I haven't met anyone crazy enough to do it. Hot loading the FreeBSD kernel hasn't been done yet either (although, I have seen it for Linux). If there was a real need to keep TCP state while updating BEAM or the OS kernel, it would probably make more sense to build a way to transfer the states (tcp and corresponding application) among machines rather than to hot load all the things; it would probably be more approachable to develop that than to add hotloading to things that didn't plan for it. I don't know how WhatsApp manages today, I left sometime ago, and I avoided getting involved with the FB hosted servers; I know we had the ability to do hot loading, but it didn't really fit in the FB deployment model, and some people didn't like having multiple deployment methods.