mafinar

mafinar

Book Club - Concurrent Data Processing in Elixir

Concurrent Data Processing in Elixir is now content complete and I finally found the time I’ve been looking for to dedicate behind reading the latest Elixir books. The Programming Crystal book club proved to be as effective as it was fun; I’d like to do the same for this one.

Over the next few days I shall be reading the book and sharing my experience with everyone, along with any “code as side effects”. The format will certainly be different from the Crystal one, as I already am experienced with Elixir, but will surely have much more codes produced.

I will start reading it from tomorrow and will be thrilled to have any co-readers to talk with!

Most Liked

mafinar

mafinar

Chapter 1 - Easy Concurrency with the Task Module

Off to a great start. This chapter tells us ways to use Task. I loved how the chapter is organized, especially in terms of assumption of reader experience. As it starts, the author nicely explains the things like, how to start a REPL, create a supervised mix project etc, then after a great explanation of Synchronous vs Asynchronous tasks (I never get tired of those, they always enlighten me somehow) and Process, we get a very nice explanation and use cases for Task. And it ends with Supervisors! Everything you need to know should you attempt to learn this useful module of Elixir!

Two of my favourite functions: yield and async_stream were there! The explanation of linking and supervision too was pretty satisfactory. At the end, there was a section was dedicated to the “Let it Crash” philosophy, and thank you- WE DO HANDLE ERRORS! it’s just that our defence mechanism is different.

Most examples of this chapter was designed around solving a real-world (ish) problem, not just random “Hello World”-s and “Good bye Reality”-s, so each example and improvements had context and story, this is something I really like about code examples, you get to relate and often feel like, “Okay, so what if I did this…” and then see that getting answered in the next example. I wish the results were depicted via test cases but I also understand this is a personal preference of mine and is not shared by many people, so that’s not even a nit.

All in all, a great chapter that makes me wish I had it handy when I was learning about Tasks, Agents etc (Agent’s not covered in this chapter but I learned and used them together so…).

5/5

herminiotorres

herminiotorres

Chapter 1 - Easy Concurrency With the Task Module

  • Multi-tasking is the concept that one can split their attention into more than one or more activities simultaneously; the concurrent execution of multiple tasks (also known as processes) over a certain period of time.
  • Multi-threading is the ability of a central processing unit (CPU) (or a single core in a multi-core processor) to provide multiple threads of execution concurrently, supported by the operating system.
  • Multi-core brought parallelism and allowed tasks to run simultaneously; this architecture enabled concurrency and parallelism by supporting two or more CPUs on a single machine.

First, running code on a multi-core does not automatically make it efficient. The language needs to handle concurrency and parallelism for its own, instead of demands to an external service or solution, and the Erlang Virtual Machine(BEAM) has that for its own.

And it will use the Open Telecom Platform(OTP) Behaviours and Concepts to build concurrent and fault-tolerant applications, recover from failures, use back-pressure to deal with limited system resources, and how to handle errors, and prevent crashing.

It talks about the difference in run code synchronous and synchronous, and identifies the processing data when it makes sense to run each of them.

Task Module

It will learn how to start tasks and different ways to retrieve results.

The entire chapter will mostly show examples to use the public functions in the Task Module and how to start and retrieve the data after finishing the execution. And it will keep these in a roll and show us how to prevent, or better choice depends on our necessity.

Most cases have a timeout to run the Task and change the time or set it as an infinity. And show the %Task{} struct, like:

  • Owner - is the PID of the process that started the Task;
  • PID - is the identifier of the Task process itself;
  • Ref - is the process monitor reference.

After the Elixir 1.10 version was implemented, the async_stream function to create the entire stream pipeline process to not just run asynchronously but laziness, and has some optional parameters, it could be passing, like:

  • max_concurrency
  • ordered
  • on_timeout

Process link, no_link, and monitor:

  • Link - a linked process will be linked to another process; when this process dies, it will die the process related.
  • No Link - a no-linked process when died, die alone, and don’t tell anyone.
  • Monitor - a monitor process will monitor some process; when the process going die, it will notifier the process watching him.

Task.Supervisor

It will monitor/supervise the Task was starting in your application, prevent these tasks from being linked to your application process, and die together with some Task processes.

And explain how to use the Task Supervisor and how to add the Application Supervisor Tree.

It shows the many ways to the specification child process.

How to isolate crashes to specify the strategy to restart the child processes, and has three different values, like:

  • :temporary
  • :transient
  • :permanent
mafinar

mafinar

I have read most of the books on Elixir that was published by Manning and PragProg, except for the newer ones like Nerves (Not into that domain), LiveView (I have the book bought though).

Here are my top 3:

  1. (and always will be number 1) Elixir in Action
  2. Phoenix in Action (Very underrated book. And it helped me learn Phoenix and I loved the way Phoenix was introduced)
  3. Designing Elixir Systems with OTP and Metaprogramming Elixir (It’s a tie)

I do dream of writing a book on Functional Algorithm Design with Elixir (Or something fancy along that line) in a decade or two so naturally (and shamelessly so) that book will be my number 2 when (actually a big if) it gets published :slight_smile:

Where Next?

Popular Community topics Top

Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
mafinar
Concurrent Data Processing in Elixir is now content complete and I finally found the time I’ve been looking for to dedicate behind readin...
New
RobertKielty
My overall initial first impressions of this book are very good. I will document my local spacemacs setup to as I work through the book.
New
rustkas
To be a more productive reader when rereading a book, it is very convenient to create small rebar3 projects based on books’ samples and i...
New
Maartz
The very first time I’ve seen a line of Elixir I was in awe. Coming from Ruby the syntax was familiar. But I wanted to know what was thi...
New
mafinar
TL;DR I am reading “Domain Modeling Made Functional” and discussing and keeping a journal of what I learned from it, any co-readers welco...
New
RomanTurner
Agile Web Development with Rails 6 Chapter 11. Task F Currently reading and working through AWDR6 by Sam Ruby, David Bryant Copeland, a...
New
AstonJ
With AI set to play a big role in our industry Elixir users are lucky to have Nx, so we’re running our Nx related book club on Genetic Al...
New
PragmaticBookshelf
When the pandemic, heart disease, and personal tragedy threatened to steal everything the Tates spent years building, they found hope, he...
New
Fl4m3Ph03n1x
Learning Domain-Driven Design Building software is harder than ever. As a developer, you not only have to chase ever-changing technologic...
New

Other popular topics Top

brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
New
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
New
AstonJ
Biggest jackpot ever apparently! :upside_down_face: I don’t (usually) gamble/play the lottery, but working on a program to predict the...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New
PragmaticBookshelf
Develop, deploy, and debug BEAM applications using BEAMOps: a new paradigm that focuses on scalability, fault tolerance, and owning each ...
New