Http://getakka.net/docs/concepts/terminology
Terminology and concepts
In this chapter we attempt-establish a common terminology to define a solid-ground for-communicating about concurrent, Distributed systems which akka.net targets. Please note: For many of these terms, there are no single agreed definition. We simply seek to give working definitions, that'll be used in the scope of the akka.net documentation.
Concurrency vs. Parallelism
Concurrency and parallelism is related concepts, but there is small differences. Concurrency means that, or more tasks is making progress even though they might not being executing simultaneously. This can for example is realized with time slicing where parts of tasks is executed sequentially and mixed with parts of Other tasks. Parallelism on the other hand arise when the execution can be truly simultaneous.
Concurrency
Parallelism
Asynchronous vs. synchronous
A method call was considered synchronous if the caller cannot make progress until the method returns a value or throws an E Xception. On the other hand, an asynchronous call allows the caller to progress after a finite number of steps, and the completion O F The method is signalled via some additional mechanism (it might is a registered callback, a future, or a message).
A synchronous API may use the blocking to implement Synchrony, but this is not a necessity. A very CPU intensive task might give a similar behavior as blocking. In general, it's preferred to use asynchronous APIs, as they guarantee, the system was able to progress. Actors is asynchronous by Nature:an actor can progress after a message send without waiting for the actual delivery to H Appen.
Non-blocking vs. blocking
We talk on blocking if the delay of one thread can indefinitely delay some of the other threads. A good example is a resource which can being used exclusively by one thread using mutual exclusion. If A thread holds the resource indefinitely (for example accidentally running an infinite loop) and other threads waitin G on the resource can not progress. In contrast, non-blocking means this no thread is able to indefinitely delay others.
Non-blocking operations was preferred to blocking ones, as the overall progress of the system was not trivially guaranteed When it contains blocking operations.
Deadlock vs. starvation vs. Live-lock
Deadlock arises when several participants is waiting on each other to reach a specific the state to being able to progress. As none of them can progress without some other participant to reach a certain state (a "Catch-22" problem) all affected s Ubsystems stall. Deadlock was closely related to blocking, as it was necessary that a participant thread being able to delay the progression of Other threads indefinitely.
In the case of deadlock, no participants can do progress, while in contrast starvation happens, when there is Participa NTS that can make progress, but there might is one or more that cannot. Typical scenario is the case of a naive scheduling algorithm, always selects high-priority tasks over low-priority one S. If the number of incoming high-priority tasks is constantly high enough, no low-priority ones would be ever finished.
Livelock is similar to deadlock as none of the participants make progress. The difference though is so instead of being frozen in a state of waiting for others to progress, the participants Conti nuously change their state. An example scenario when the participants has a identical resources available. They each try to get the resource, but they also check if the other needs the resource, too. If the resource is requested by the other participant, they try to get the other instance of the resource. In the unfortunate case it might happen that the participants "bounce" between the resources, never acquiring it, But always yielding to the other.
Race Condition
We call it a Race condition if an assumption about the ordering of a set of events might being violated by external non- Deterministic effects. Race conditions often arise when multiple threads has a shared mutable state, and the operations of the thread in the state m Ight be interleaved causing unexpected behavior. While the is a common case, the shared State was not necessary to the race conditions. One example could is a client sending unordered packets (e.g UDP datagrams) P1, P2 to a server. As the packets might potentially travel via different network routes, it's possible that the server receives P2 first and P1 afterwards. If the messages contain no information about their sending order it's impossible to determine by the server that they wer E sent in a different order. Depending on the meaning of the packets this can cause race conditions.
Note
The only guarantee this akka.net provides about messages sent between a given pair of actors are that their order are always Preserved. See Message Delivery Reliability
Non-blocking Guarantees (Progress Conditions)
As discussed in the previous sections blocking are undesirable for several reasons, including the dangers of deadlocks and Reduced throughput in the system. In the following sections we discuss various non-blocking properties with different strength.
Wait-freedom
A method is Wait-free if every call was guaranteed to the finish in a finite number of steps. If a method is bounded wait-free then the number of steps have a finite upper bound.
From this definition it follows that wait-free methods is never blocking, therefore deadlock can not happen. Additionally, as each participant can progress after a finite number of steps (when the call finishes), Wait-free methods is free of starvation.
Lock-freedom
Lock-freedom is a weaker property than Wait-freedom. In the case of Lock-free calls, infinitely often some method finishes in a finite number of steps. This definition implies, that no deadlock are possible for lock-free calls. On the other hand, the guarantee. Some call finishes in a finite number of steps are not enough to guarantee this all O f them eventually finish. In other words, lock-freedom are not enough to guarantee the lack of starvation.
Obstruction-freedom
Obstruction-freedom is the weakest non-blocking guarantee discussed here. A method is called obstruction-free if there are a point in time after which it executes in isolation (other threads make n o steps, e.g.: Become suspended), it finishes in a bounded number of steps. All Lock-free objects was obstruction-free, but the opposite was generally not true.
Optimistic concurrency control (OCC) methods is usually obstruction-free. The OCC approach is this every participant tries to execute it operation on the shared object, but if a participant Detec TS conflicts from others, it rolls back the modifications, and tries again according to some schedule. If There is a point in time, where one of the participants are the only one trying, the operation would succeed.
Recommended literature
- The Art of multiprocessor programming, M. Herlihy and N Shavit, 2008. ISBN 978-0123705914
- Java Concurrency in practice, B. Goetz, T. Peierls, J. Bloch, J. Bowbeer, D. Holmes and D. Lea, 2006. ISBN 978-0321349606
Concurrency vs. Parallelism