This is another good quote from a blog post titled The Downfall of Imperative Programming: “Did you notice that in the definition of ‘data race’ there’s always talk of mutation?”
We should grow things (software applications) by adding more small communicating objects, rather than making larger and larger non-communicating objects.
Concentrating on the communication provides a higher level of abstraction than concentrating on the function APIs used within the system. Black-box equivalence says that two systems are equivalent if they cannot be distinguished by observing their communication patterns. Two black-boxes are equivalent if they have identical input/output behavior.
When we connect black boxes together we don't care what programming languages have been used inside the black boxes, we don't care how the code inside the black boxes has been organized, we just have to obey the communication protocols.
Erlang programs are the exception. Erlang programs are intentionally structured as communicating processes — they are the ultimate micro-services.
Large Erlang applications have a flat “bus like” structure. They are structured as independent parallel applications hanging off a common communication bus. This leads to architectures that are easy to understand and debug and collaborations which are easy to program.
~ From this post by Joe Armstrong, author of the book Programming Erlang: Software for a Concurrent World
In the “Maintaining the Erlang View of the World” section of his book Programming Erlang: Software for a Concurrent World, Joe Armstrong writes, “The Erlang view of the world is that everything is a process, and that processes can interact only by exchanging messages. Having such a view of the world imposes conceptual integrity on our designs, making them easier to understand.”
Strictly speaking, Amdahl’s Law isn’t only about speeding up serial programs by using parallel processing techniques, but in practice that’s often the case. Here’s a description from Wikipedia:
“Amdahl's law is often used in parallel computing to predict the theoretical speedup when using multiple processors. For example, if a program needs 20 hours using a single processor core, and a particular part of the program which takes one hour to execute cannot be parallelized, while the remaining 19 hours (p = 0.95) of execution time can be parallelized, then regardless of how many processors are devoted to a parallelized execution of this program, the minimum execution time cannot be less than that critical one hour. Hence, the theoretical speedup is limited to at most 20 times (1/(1 − p) = 20). For this reason parallel computing is relevant only for a low number of processors and very parallelizable programs.”
This was a nice Twitter post by Jamie Allen of Lightbend (nee Typesafe) about how to create applications that scale and are resilient. (There might be a misspelling on #2. :)
(Image from this Twitter page.)
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.10, “How to create a Twitter client in Scala.”
You want to create a client to connect to Twitter to access the information you want, such as showing timelines and trends.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.12, “Examples of how to use parallel collections in Scala.”Back to top
You want to improve the performance of algorithms by using parallel collections.Back to top
When creating a collection, use one of the Scala’s parallel collection classes, or convert an existing collection to a parallel collection. In either case, test your algorithm to make sure you see the benefit you’re expecting.Back to top
Table of Contents
- Run one task, but block
- Run one thing, but don’t block, use callback
- The onSuccess and onFailure callback methods
- Creating a method to return a Future[T]
- How to use multiple Futures in a for loop
- A future and ExecutionContext
- Callback methods
- For-comprehensions (combinators: map, flatMap, filter, foreach, recoverWith, fallbackTo, andThen)
- See Also
- The Scala Cookbook
You want a simple way to run one or more tasks concurrently in a Scala application, including a way to handle their results when the tasks finish. For instance, you may want to make several web service calls in parallel, and then work with their results after they all return.Back to top
Future gives you a simple way to run an algorithm concurrently. A future starts running concurrently when you create it and returns a result at some point, well, in the future. In Scala, it’s said that a future returns “eventually.”
I’ve read a lot of irrational claims about how functional programming helps with concurrency, but if a compiler can do what this says, at least it’s a clear, rational example of how FP can help with concurrency. It’s taken from an article titled, Functional programming for the rest of us.