When we talk about fault tolerant distributed computing, using the state machine replication approach, it may seem obvious that a system of this kind should be capable of completely masking failures. In fact, however, this is not the case. Our ability to hide failures is really very limited.
When developers use state machine replication techniques (SMR), the usual approach is to replace components of systems or distributed services with groups of N members, and then use some sort of library that delivers the same inputs to each, in the same order. If the replicated component is deterministic, and if care is taken to initialize each component in a manner properly synchronized with respect to its peers, this is enough to guarantee that the copies will remain synchronized. Thus, we have an N-replica group that seemingly will tolerate N-1 faults.
Unfortunately, theory is one thing and reality can be quite a different matter. When people first began to experiment with SMR in the 1990's, developers quickly noticed that because software bugs are a major cause of failure, perfect replication will replicate many kinds of faults! Over time, a more nuanced approach emerged, in which the various replicas are proactively shut down and restarted in an uncoordinated way, so that on average there would still be N copies, but at any instant in time there might be N-1 copies, with one copy shutting down or rejoining. The trick is to transfer the current state of the group to the recovering member, and is solved using the virtual synchrony model, in which group membership advances through a series of epochs, reported via view upcall notifications, with state transfers performed during epoch transitions.
The benefit of this sort of staggered restart is to overcome so-called Heisenbugs. The term refers to bugs that are hard to pin down: they could cause non-deterministic behavior (in which case the replicas might diverge), or bugs that seem to shift around when the developer tries to isolate them.
A common form of Heisenbug involves situations where a thread damages a data structure, but the damage won't be noticed until much later, at which point any of a number of other threads could try to access the structure and crash. Thus the failure, when it occurs, is associated with logic remote from the true bug, and may jump about depending on scheduling order. If the developer realizes that the root cause is the earlier damage to the data structure, it generally isn't too hard to fix the problem. But if the developer is tricked into thinking the bug manifested in the code that triggered the crash, any attempts to modify that logic will probably just make things worse!
The reason that staggered restart overcomes Heisenbugs is that a restarting program will load its initial state from some form of checkpoint, hence we end up with N copies, each using different operations to reach the same coordinated state as the other N-1. If the data-structure corruption problem isn't a common thing, this joining process is unlikely to have corrupted the same data structure as did the others. With proactive restart, all N copies may be in equivalent yet rather different states. We can take this form of diversity even further by load-balancing read-requests across our N copies: each will see different read operations and this will be a further source of execution diversity, without mutating states in ways that can cause the N replicas to diverse.
With such steps, it isn't hard to build an ultra-resilient SMR service, that can remain alive even through extremely disruptive failure episodes. But can such a service "mask" failures?
The answer is yes and no.
On the "yes" side we find work by Robert Surton at Cornell, who created a clever little TCP fail-over solution called TCP-R. Using this protocol, a TCP connection can seamlessly roll from one machine (the failed server) to another. The cleverness arises because of the way that TCP itself handles acknowledgements: in Surton's approach, a service member accepts a TCP connection, reads the request (this assumes that the request size is smaller than the TCP window size, in bytes), replicates the received request using an SMR multicast, and only then allows TCP to acknowledge the bytes comprising the request.
If a failure disrupts the sequence, TCP-R allows a backup to take control over the TCP session and to reread the same bytes from the window. Thus the service is guaranteed to read the request at least once. A de-duplication step ensures that a request that happens to be read twice won't cause multiple state updates.
Replies back to the end user are handled in a similar way. The service member about to send the reply first notifies the other members, using a multicast, and only then sends the reply. If a failure occurs, one of the other members claims the TCP endpoint and finishes the interrupted send.
With TCP-R the end-user's experience is of a fully masked failure: the application sends its request, and the service definitely gets the request (unless all N members crash simultaneously, which will break the TCP session).
Lacking TCP-R, the situation is quite a bit more complex. In effect, the end-user would need to send the request, but also be prepared to re-send it if the endpoint fails without responding. For read-only requests, the service can just perform the request multiple times if it shows up multiple times, but updates are more complex. For these, the service would need logic to deduplicate requests: if the same request shows up twice, it should resend the original reply and not mutate the service state by performing the identical operation a second time. TCP-R masks the service failure from the perspective of the client, although the service itself still needs this form of deduplication logic.
On the "no" side of the coin, we need to consider the much broader range of situations that can arise in systems that use SMR for fault-tolerance. In particular, suppose that one SMR-replicated service somehow interacts with a second SMR-replicated service. Should all N members of the first replica group repeat the same request to the M members of the second group? Doing so is clearly the most general solution, but runs into the difficulty that bytes will be transferred N times to each member: a high cost if we are simply trying to mask a rare event!
Eric Cooper studied this question in his PhD thesis on a system called Circus, at Berkeley in the 1990's. Basically, he explored the range of options from sending one request from group A to group B, but reissuing the request if the sender in A failed or the receiver in B, all the way to the full N x M approach in which every member of A multicasts every request to every member of B, and the members of B thus receive N copies and must discard N-1 of them in the usual case. (TCP-R can be understood as an instance of the first approach, but with the client-side logic hidden under TCP itself, so that only the server has to be aware of the risk of redundancy, and so that it only arises when a genuine failure occurs.)
Cooper pointed out that even with high costs for redundancy, the N x M approach can often outperform any scheme that waits to sense a failure before retrying. His insight was that because detecting a failure can be slow (often 30s or more), proactively sending multiple copies of each request will generally produce extra load on the receivers, but with the benefit of ensuring a snappy response because at least some receiver will act promptly and send the desired reply with minimal delay.
Cooper's solution, Circus, is best understood as a design pattern: a methodology that the application developer is expected to implement. It involves a multicast from group A to group B, code in group B to remember recent responses to requests from A, and logic to de-duplicate the request stream, so that whether B receives a request 1 time or N times, it behaves identically and responds to A in the same manner.
In Derecho, we don't currently offer any special help for this heavily redundant approach, but all the needed functionality is available and the design pattern shouldn't be hard to instantiate. But in fact, many Derecho users are more likely to use a non-fault-tolerant approach when building a data processing pipeline. More specifically, while Derecho users would often use replication to make the processing elements of the pipeline fault-tolerant, they might decide not to pay the overhead of making the handoff of requests, stage by stage in the pipeline, ultra-reliable.
The reason for this compromise is that in the IoT settings where a "smart memory service" might be used, most sensors are rather redundant, sending photo after photo of the same car on the highway, or location after location for the cat in the apartment. The service receives this heavily duplicative input and will actually start by sorting out the good content and discarding the replicated data. Thus we suspect that most Derecho users will be more concerned with ensuring that the service itself is highly available, and less concerned with ensuring that every single message sent to the service is processed.
Indeed, in most IoT settings, freshness of data is more important that perfect processing of each and every data point. Thus, if some camera creates photo X of a vehicle on the highway, and then photo Y, and X is somehow lost because of a failure that occurs exactly as it is being sent, it often would make more sense to not fuss about X and just focus on processing request Y instead.
Microsoft has a system, Cosmos, in which a pipeline of processing is done on images and videos. It manages without fault-tolerant handoff between stages because failures are rare and, if some object is missing, there is always a simple recipe to create it again from scratch. Facebook apparently does this too. Both systems need to be extra careful with the original copies of photos and videos, but computed artifacts can always be regenerated. Thus, perfect fault tolerance isn't really needed!
Of course, one can easily imagine systems in which each piece of data sent to the service is individually of vital importance, and for those, an open question remains: is it really necessary to hand-code Cooper's Circus design pattern? Or could there be a really nice way to package the Circus concept, for example by using a higher level language to describe services and compiling them down to SMR replicas that talk to one-another redundantly?
I view this as an open research topic for Derecho, and one we may actually tackle in coming years. Until then, Derecho can certainly support a high quality of adaptation after crashes, but won't seamlessly hide crashes from the developer who works with the technology. But on the other hand, neither does any other technology of which I'm aware!
No comments:
Post a Comment
This blog is inactive as of early in 2020. Comments have been disabled, and will be rejected as spam.
Note: only a member of this blog may post a comment.