You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
+@ggreenway who was also interested in this behavior.
So the challenge here is that HTTP/3 runs on top of QUIC + UDP which is quite different from TCP. With TCP each accepted connection results in a new socket and a new file description. Closing the listening socket does not close the accepted per-connection sockets. This means that the "old" listening socket can be closed and a "new" listening socket can be opened with the new config. Meanwhile, the existing sockets will remain open to handle existing connections.
With UDP, there is no such thing. There is only a single socket which receives packets for all connections. If that socket is closed and a new one is opened with the new config, the packets will only be delivered to the new instances.
However, all is not lost... It may still be possible to make this work and the cost of a much more complex solution. Instead of relying on the operating system's sockets to send packets to the right connection, we will have to do this ourselves. Namely, we will need some method of determining if a packet we receive should be sent to the "old" code, or to the "new" code. For QUIC (in contrast to generic UDP) each packet contains a "connection ID" which is provided to the client by the server when the connection is created. This connection ID is used to allow the server to deliver this packet to the right connection in memory. Since this ID is created by the server, it could be constructed in such a way that all connection IDs created by the "old" config look different from the connections IDs created by the "new" config. If this were the case, then the old socket would be closed, and the new socket would be opened. When packets are received on the new socket, their connection IDs would be extracted from the packet and they would be parsed to see if they are "old" or "new" connection IDs. If they are "new" then they would be handled as normal. On the other hand, if they are "old" then they would be delivered to the "old" code (sent to the old QuicDispatcher).
It would be ideal if we could route the packets correctly in the kernel via EBPF, but I don't know if that is possible or not. If it's not, we could forward packets over the hot-restart communication channel between the envoy instances, but that would have an extra CPU cost.
I remember we discussed with @mattklein123 about this topic not too long ago. Since there was a refectory of listener socket factory and socket life time change made in #17259, the reuse_port listeners actually duplicate the socket during hot start. So theoretically new listener and old listener listen on the same socket as apposed to creating a new listen socket for the new listener. Essentially at startup we make a socket for each worker, then just keep using that for the life of all updates. In this way the kernel reuse socket group don't change so the packets on the same connection can land on the same worker.
I think the complexity is how to make the new listener forward packets which belong to the old listener, assuming only the new listener will be listening on READ|WRITE event. While we can still use a classic BPF filter.
Regardless of whether we can accelerate it with EBPF, we'll probably need a non-kernel solution for systems that don't support EBPF (older linux kernels, windows, mac).
I imagine we'll need some code in QUICHE to look at a packet and decline to process it, but signal that it is intended for the older envoy.
hey @danzh2010! thanks for getting back to me. We are exploring rolling out QUIC support to all our ingress stacks, one of which is based off mainly of long lived connections.
We rely on hot restart to gracefully close connections when a process restart is needed.
Couldn't you use a single bit in the CID to encode hot_restart_epoch & 0x01?
Yes, but that's the same problem again - a new 'noise' CID has 50% chance of matching it so you'd still have to support the whole forwarding to everyone just in case thing if it doesn't match the current instance's packets. But with the added cost that now you also have to transport the extra data to the CID generation extension. It could be useful in the more advanced solution later (using BPF_MAP_TYPE_REUSEPORT_SOCKARRAY, if that's even feasible), but for a first pass it seems like simultaneously overkill and insufficiently useful to be worth it.
Also, when forwarding to the other envoy, we should make sure we're only sending to active-quic-listeners with a matching listener-address (or addresses) as the original listener that got the packet.
Yes.
Anyway, finally got my manual experiment to work - it seems that if you have n UDP sockets on the same port with BPF directing packets to the right worker, and you fork so those n sockets get duplicated to the new instance, delivery is to the correct workers and next-active-listener, which (assuming your listening path has equally fast turnaround) is essentially round-robin delivery between the old and new instances. This is good news in that it's not messing with the kernel group and therefore my proposed solution will at least work.
Adapting to the BPF_MAP_TYPE_REUSEPORT_SOCKARRAY model would be significantly more complicated (and won't help in non-BPF contexts so something like my solution would still need to exist); I, for one, don't find the motivation to make that more difficult change particularly compelling at this time.
I believe it would also require a fairly large kernel-version-based behavior split, because if we do the "open another new socket" operation that's required for BPF_MAP_TYPE_REUSEPORT_SOCKARRAY to work, that would actively break the existing behavior (by mangling the group indexing) on a kernel that doesn't support specifying SOCKARRAY. I'm pretty sure there exists some kernel version at which SO_ATTACH_REUSEPORT_CBPF is available and BPF_MAP_TYPE_REUSEPORT_SOCKARRAY is not.
Anyway, finally got my manual experiment to work - it seems that if you have n UDP sockets on the same port with BPF directing packets to the right worker, and you fork so those n sockets get duplicated to the new instance, delivery is to the correct workers and next-active-listener, which (assuming your listening path has equally fast turnaround) is essentially round-robin delivery between the old and new instances. This is good news in that it's not messing with the kernel group and therefore my proposed solution will at least work.
Thanks for the experiment! Given the round-robin delivery, would it be easier to make the new listener not register with read events while the old one is draining? That means only the old listener will be receiving packets and forwarding packets with unseen CID to the new listener. How do you plan to toss packets across process? Would tossing every packets on new connections be too costly?
Yes, but that's the same problem again - a new 'noise' CID has 50% chance of matching it so you'd still have to support the whole forwarding to everyone just in case thing if it doesn't match the current instance's packets.
Could we combine the single bit in the CID with whether it's a long vs short packet header? IIRC we should only see random CIDs with long-headers, which are only used at connection setup.
But the goal of this exercise (marking something in the CID) is just performance I believe. How much computational effort is it to check whether the current process wants this packet or not? If it's very low, then I agree it's probably not worth doing and we just try the packet and forward if it isn't accepted locally.
I think it's over a unix-domain socket, possibly wrapped in protobuf (grpc?) to add metadata.
Would tossing every packets on new connections be too costly?
Yeah, I think it will have pretty high overhead. When the process starts, nearly all the packets need to end up with the parent process. By the end of draining, nearly all the packets should end up with the child. So I don't think it matters which side is reading from the socket.
When this is all working, we should consider publishing some benchmarks on the overhead during hot-restart.
But the goal of this exercise (marking something in the CID) is just performance I believe. How much computational effort is it to check whether the current process wants this packet or not? If it's very low, then I agree it's probably not worth doing and we just try the packet and forward if it isn't accepted locally.
I think pre-checking a bit would actually be more computational effort than using the existing failed-to-deliver check (in that it would be hard to avoid impacting the common path, where using the existing failed-to-deliver check only adds any processing to the uncommon path). IMO it'd be worth pre-checking with BPF but not worth pre-checking without.
Could we combine the single bit in the CID with whether it's a long vs short packet header?
I like this idea, but I'm not sure how well it would play with the BPF programming. It looks like it could work, there's a bpf_map_update_elem instruction which I think could be used to switch "unrecognized" packets from going to the current instance to going to the new instance. It's not compatible with the same simple BPF program we have right now; I think it changes the requirements to needing eBPF support, and the aforementioned need to change from just using duplicate sockets to closing the duplicate sockets, and opening new sockets sharing the same port but using a different bpf program-map (to avoid modifying the existing group).
Would tossing every packets on new connections be too costly?
Yeah, I think it will have pretty high overhead. When the process starts, nearly all the packets need to end up with the parent process. By the end of draining, nearly all the packets should end up with the child. So I don't think it matters which side is reading from the socket.
It feels like having only the parent process listening instead of both processes listening doesn't make more packets need to be tossed, given that half of the packets land on the wrong instance. And in this way we can eliminate the complexity of tossing packets back and forth. WDYT?
When this is all working, we should consider publishing some benchmarks on the overhead during hot-restart.
It feels like having only the parent process listening instead of both processes listening doesn't make more packets need to be tossed, given that half of the packets land on the wrong instance. And in this way we can eliminate the complexity of tossing packets back and forth. WDYT?
Agree, this seems reasonable. Also it conceptually plays well with the later eBPF addition, since both patterns involve "not doing the default thing" with the child socket.
Reading between the lines it appears that hot restart does not work for "plain" UDP in general and not only for QUIC (e.g. taking CIDs into considewration).
In an initial attempt to perform a hot restart while using the udp proxy listener, udp traffic ceases to work as soon as the child process starts. UDP returns to work as soon as the parent process exits.
By hot restart support for UDP I refer to the possibility of maintaining the UDP sessions between the parent and child processes (e.g. packets with the same 4-tuple of source IP/port and local IP/port are routed to the same backend within a given timeout).
Can someone please confirm that my understanding is correct?
Also, does the work addressed in this thread cover also "plain" udp or only the QUIC listeners?
Thanks very much in advance.
You are correct that hot restart doesn't work for UDP in general.
The work done in this thread only added support for QUIC (there's an interface in QUIC in which the protocol reports "I couldn't use this packet", which is used to determine whether to send the packet to the other envoy instance).
I believe the QUIC support is functional at this point. And I think nobody is working on doing the same for UDP. I'm a bit surprised at UDP ceasing to work during the hot restart transition, my expectation would have been that it would drop all existing "connections" but work immediately for new connections associating them with the new instance. (But I haven't looked closely at the code - if someone wants to try to make it functional, and it is currently as you describe, my suggestion would be to first have the parent process close the listener as soon as it knows there is a child process starting up, so as to at least not have a window of not-working-at-all, then work from there to try to do forwarding based on unrecognized tuples.)
@ravenblackx Thanks very much for your reply and the suggestion of how to proceed. Another avenue (which does not cover the exact use case of hot-restart) is to use e.g. the filesystem based xSD. At this point, however, this mechanism also seems broken for UDP.
Second-guessing my previous response a bit, if the UDP behavior were to mirror the QUIC behavior then the implementation of forwarding the packets would be forwarding from the old instance to the new instance, which would mean instead of the old instance stopping listening, you'd need the new instance to not start listening until the old instance is about to stop (which makes sense because the old instance "knows" which address-tuples are already in use and the new instance does not).
But same overall thrust that the first step would be to do just that, without the forwarding, so as to at least have UDP half-functioning during the overlapping period, which would be an improvement over not functioning at all. :)
Activity
YaoZengzeng commentedon Jan 12, 2022
I'd like to help to implement this feature, although seems not straightforward and may take some time to research 🤣
alyssawilk commentedon Jan 12, 2022
@danzh2010 @RyanTheOptimist would one of you be up for outlining what the steps might look like here?
RyanTheOptimist commentedon Jan 12, 2022
Sure, I'll take a stab!
RyanTheOptimist commentedon Jan 12, 2022
+@ggreenway who was also interested in this behavior.
So the challenge here is that HTTP/3 runs on top of QUIC + UDP which is quite different from TCP. With TCP each accepted connection results in a new socket and a new file description. Closing the listening socket does not close the accepted per-connection sockets. This means that the "old" listening socket can be closed and a "new" listening socket can be opened with the new config. Meanwhile, the existing sockets will remain open to handle existing connections.
With UDP, there is no such thing. There is only a single socket which receives packets for all connections. If that socket is closed and a new one is opened with the new config, the packets will only be delivered to the new instances.
However, all is not lost... It may still be possible to make this work and the cost of a much more complex solution. Instead of relying on the operating system's sockets to send packets to the right connection, we will have to do this ourselves. Namely, we will need some method of determining if a packet we receive should be sent to the "old" code, or to the "new" code. For QUIC (in contrast to generic UDP) each packet contains a "connection ID" which is provided to the client by the server when the connection is created. This connection ID is used to allow the server to deliver this packet to the right connection in memory. Since this ID is created by the server, it could be constructed in such a way that all connection IDs created by the "old" config look different from the connections IDs created by the "new" config. If this were the case, then the old socket would be closed, and the new socket would be opened. When packets are received on the new socket, their connection IDs would be extracted from the packet and they would be parsed to see if they are "old" or "new" connection IDs. If they are "new" then they would be handled as normal. On the other hand, if they are "old" then they would be delivered to the "old" code (sent to the old QuicDispatcher).
There is an IETF draft which describes mechanism that could be used to allocate QUIC connection IDs for load balancing purpose, of which this use case is a fairly simple subset.
https://quicwg.org/load-balancers/draft-ietf-quic-load-balancers.html
Doing the work to support this behavior would likely be split to some degree between QUICHE (where the QUIC code is implemented) and Envoy.
I hope this helps provide an overview.
ggreenway commentedon Jan 12, 2022
It would be ideal if we could route the packets correctly in the kernel via EBPF, but I don't know if that is possible or not. If it's not, we could forward packets over the hot-restart communication channel between the envoy instances, but that would have an extra CPU cost.
RyanTheOptimist commentedon Jan 12, 2022
Oh, right! I keep forgetting about BPF. Yes, good point. AIUI, Envoy has the ability today to route packets to the correct thread using BPF based on the first word of the connection id. https://github.com/envoyproxy/envoy/blob/main/source/common/quic/active_quic_listener.cc#L286
I suspect that could be extended to detect the old vs new connection ID state. I'm not familiar enough, though, with BPF to understand how we would route those to the right place in Envoy. Do you have a sense for how this would work?
danzh2010 commentedon Jan 12, 2022
I remember we discussed with @mattklein123 about this topic not too long ago. Since there was a refectory of listener socket factory and socket life time change made in #17259, the reuse_port listeners actually duplicate the socket during hot start. So theoretically new listener and old listener listen on the same socket as apposed to creating a new listen socket for the new listener. Essentially at startup we make a socket for each worker, then just keep using that for the life of all updates. In this way the kernel reuse socket group don't change so the packets on the same connection can land on the same worker.
I think the complexity is how to make the new listener forward packets which belong to the old listener, assuming only the new listener will be listening on READ|WRITE event. While we can still use a classic BPF filter.
ggreenway commentedon Jan 12, 2022
Regardless of whether we can accelerate it with EBPF, we'll probably need a non-kernel solution for systems that don't support EBPF (older linux kernels, windows, mac).
I imagine we'll need some code in QUICHE to look at a packet and decline to process it, but signal that it is intended for the older envoy.
relvira commentedon Nov 11, 2022
Hey there @alyssawilk 👋🏼 are you aware if there is any ongoing work on this issue?
Thank you! 🙇🏼
danzh2010 commentedon Nov 11, 2022
We currently are not actively working on this. @relvira do you have any use case for this feature?
relvira commentedon Nov 14, 2022
hey @danzh2010! thanks for getting back to me. We are exploring rolling out QUIC support to all our ingress stacks, one of which is based off mainly of long lived connections.
We rely on hot restart to gracefully close connections when a process restart is needed.
21 remaining items
ravenblackx commentedon Jul 31, 2023
Yes, but that's the same problem again - a new 'noise' CID has 50% chance of matching it so you'd still have to support the whole forwarding to everyone just in case thing if it doesn't match the current instance's packets. But with the added cost that now you also have to transport the extra data to the CID generation extension. It could be useful in the more advanced solution later (using
BPF_MAP_TYPE_REUSEPORT_SOCKARRAY, if that's even feasible), but for a first pass it seems like simultaneously overkill and insufficiently useful to be worth it.Yes.
Anyway, finally got my manual experiment to work - it seems that if you have n UDP sockets on the same port with BPF directing packets to the right worker, and you fork so those n sockets get duplicated to the new instance, delivery is to the correct workers and next-active-listener, which (assuming your listening path has equally fast turnaround) is essentially round-robin delivery between the old and new instances. This is good news in that it's not messing with the kernel group and therefore my proposed solution will at least work.
Adapting to the
BPF_MAP_TYPE_REUSEPORT_SOCKARRAYmodel would be significantly more complicated (and won't help in non-BPF contexts so something like my solution would still need to exist); I, for one, don't find the motivation to make that more difficult change particularly compelling at this time.I believe it would also require a fairly large kernel-version-based behavior split, because if we do the "open another new socket" operation that's required for
BPF_MAP_TYPE_REUSEPORT_SOCKARRAYto work, that would actively break the existing behavior (by mangling the group indexing) on a kernel that doesn't support specifying SOCKARRAY. I'm pretty sure there exists some kernel version at whichSO_ATTACH_REUSEPORT_CBPFis available andBPF_MAP_TYPE_REUSEPORT_SOCKARRAYis not.danzh2010 commentedon Jul 31, 2023
Thanks for the experiment! Given the round-robin delivery, would it be easier to make the new listener not register with read events while the old one is draining? That means only the old listener will be receiving packets and forwarding packets with unseen CID to the new listener. How do you plan to toss packets across process? Would tossing every packets on new connections be too costly?
ggreenway commentedon Jul 31, 2023
Could we combine the single bit in the CID with whether it's a long vs short packet header? IIRC we should only see random CIDs with long-headers, which are only used at connection setup.
But the goal of this exercise (marking something in the CID) is just performance I believe. How much computational effort is it to check whether the current process wants this packet or not? If it's very low, then I agree it's probably not worth doing and we just try the packet and forward if it isn't accepted locally.
ggreenway commentedon Jul 31, 2023
I think it's over a unix-domain socket, possibly wrapped in protobuf (grpc?) to add metadata.
Yeah, I think it will have pretty high overhead. When the process starts, nearly all the packets need to end up with the parent process. By the end of draining, nearly all the packets should end up with the child. So I don't think it matters which side is reading from the socket.
When this is all working, we should consider publishing some benchmarks on the overhead during hot-restart.
ravenblackx commentedon Aug 1, 2023
I think pre-checking a bit would actually be more computational effort than using the existing failed-to-deliver check (in that it would be hard to avoid impacting the common path, where using the existing failed-to-deliver check only adds any processing to the uncommon path). IMO it'd be worth pre-checking with BPF but not worth pre-checking without.
I like this idea, but I'm not sure how well it would play with the BPF programming. It looks like it could work, there's a
bpf_map_update_eleminstruction which I think could be used to switch "unrecognized" packets from going to the current instance to going to the new instance. It's not compatible with the same simple BPF program we have right now; I think it changes the requirements to needing eBPF support, and the aforementioned need to change from just using duplicate sockets to closing the duplicate sockets, and opening new sockets sharing the same port but using a different bpf program-map (to avoid modifying the existing group).danzh2010 commentedon Aug 1, 2023
It feels like having only the parent process listening instead of both processes listening doesn't make more packets need to be tossed, given that half of the packets land on the wrong instance. And in this way we can eliminate the complexity of tossing packets back and forth. WDYT?
+1
ravenblackx commentedon Aug 1, 2023
Agree, this seems reasonable. Also it conceptually plays well with the later eBPF addition, since both patterns involve "not doing the default thing" with the child socket.
Add capability for ActiveQuicListener to custom handle undeliverable …
eranr commentedon Jun 11, 2024
Reading between the lines it appears that hot restart does not work for "plain" UDP in general and not only for QUIC (e.g. taking CIDs into considewration).
In an initial attempt to perform a hot restart while using the udp proxy listener, udp traffic ceases to work as soon as the child process starts. UDP returns to work as soon as the parent process exits.
By hot restart support for UDP I refer to the possibility of maintaining the UDP sessions between the parent and child processes (e.g. packets with the same 4-tuple of source IP/port and local IP/port are routed to the same backend within a given timeout).
Can someone please confirm that my understanding is correct?
Also, does the work addressed in this thread cover also "plain" udp or only the QUIC listeners?
Thanks very much in advance.
ravenblackx commentedon Jun 11, 2024
You are correct that hot restart doesn't work for UDP in general.
The work done in this thread only added support for QUIC (there's an interface in QUIC in which the protocol reports "I couldn't use this packet", which is used to determine whether to send the packet to the other envoy instance).
I believe the QUIC support is functional at this point. And I think nobody is working on doing the same for UDP. I'm a bit surprised at UDP ceasing to work during the hot restart transition, my expectation would have been that it would drop all existing "connections" but work immediately for new connections associating them with the new instance. (But I haven't looked closely at the code - if someone wants to try to make it functional, and it is currently as you describe, my suggestion would be to first have the parent process close the listener as soon as it knows there is a child process starting up, so as to at least not have a window of not-working-at-all, then work from there to try to do forwarding based on unrecognized tuples.)
eranr commentedon Jun 13, 2024
@ravenblackx Thanks very much for your reply and the suggestion of how to proceed. Another avenue (which does not cover the exact use case of hot-restart) is to use e.g. the filesystem based xSD. At this point, however, this mechanism also seems broken for UDP.
ravenblackx commentedon Jun 13, 2024
Second-guessing my previous response a bit, if the UDP behavior were to mirror the QUIC behavior then the implementation of forwarding the packets would be forwarding from the old instance to the new instance, which would mean instead of the old instance stopping listening, you'd need the new instance to not start listening until the old instance is about to stop (which makes sense because the old instance "knows" which address-tuples are already in use and the new instance does not).
But same overall thrust that the first step would be to do just that, without the forwarding, so as to at least have UDP half-functioning during the overlapping period, which would be an improvement over not functioning at all. :)
ravenblackx commentedon Jun 13, 2024
I think it makes sense to close this issue as done, and open a new one for UDP support and another one for eBPF-based support.