In the name of Allah(God), Most Gracious, Most Merciful.
Peace be upon you all.
Recently I have been learning about Elixir and found very informative talk on YouTube about Elixir by Mr.Brian Candarella.
Link to the video: https://youtu.be/gom6nEvtl3U
I decided to summarize his talk to make it easier to understand for non technical people. Who want to know why Elixir matters.
I will keep Mr.Brian's speech in a talk style to leave his personality in text. Everything written in from Mr.Brians perspective. All the respect and copyright belongs to Mr.Brian.
My opinion and text will be in italics text style. So let's get into the talk.
Definition of "Insanity"
Insanity is the amount of demand that is being put upon engineering team.
Some of those requirements are:
* Systems must be fast.
* Systems must scale to ever-increasing demand. As more of the world gets turned on and mobile device is getting faster internet connections.
* Global demand. There's going to be more demand put upon your applications.
* Requirements that have mix of distributed systems, mitigating downtime, self-healing systems, real-time etc. These are difficult problems to solve for the tools that we've been using for the past few years.
Erlang
Erlang it is a technology that was built by Ericsson on the telecommunications company of Sweden.
It was found in mid 80s late 90s. With good reputation and history
It was meant to handle global telecommunication systems with almost zero downtime
Systems that can monitor other systems to ensure that they're going to be bounced properly
Hot code loading. In Erlang you can actually have the system in production and you can push code deltas up without taking the production server down. It will absorb new code deltas and incorporate them into the runtime that's currently live in production.
These are really incredible and cutting-edge technologies today, that have been around for a long time. If that is the case why aren't we using them?
Why Erlang is not being used?
Mostly because of Prologue syntax
- It it's like a sentence like a like programming structure. Each line is eliminated by a comma. The statement is finished with a period.
- Something that should feel simple ends up looking difficult for those who used to more modern syntax.
Erlangs founders opinion about Elixir
Joe Armstrongs on his personal blog wrote: "what elixir brings the table is a complete different surface in text. Inspired by Ruby well, you might call a non-scary plum code syntax and loaded extra goodies"
Founding of Elixir
Elixir is created by a programmer named Jose Valine. He was Rubys core team member. He wanted to solve problems of concurrency with Ruby as the language. José Valim researched how to solve the problem and came across with Erlang and decided to write syntax on top of Erlang virtual machine. First, the syntax was Object Oriented Style. That did not work and then Jose decided to make it Functional and "light sugar".
Elixir itself really a surface level language. It doesn't do much on its own beyond once it is compiled into Erlangs virtual machine to handle all the job. Elixir is probably less involved with the nuts and bolts under the hood. Around 80%( 90% in 2018-11-21 ) of the language written in Elixir
Inherits from Erlang
These are what Elixir inherited from Erlang.
- 30 year old tested technology and used by multi-billion corporations
- Genservers which helps to manage distributed data
- Supervisors which grants self-healing function
- Scalability to meet tomorrows demand
- Pattern matching
New features in Elixir:
- Clean, familiar syntax
- Mature tooling: Mix, debug , lint server, docs, dependency resolution,and etc., all built in
- Built in unit testing
- Meta programming. Which is also referred as dynamic code creation
- Built-in documentation with doc tests
- Pipes
- Phoenix
Pattern matching:
...Simple non-technical explanation is under construction...
Pipes
Pipes allow you to clean up messes like this:
foo(bar(baz("hello world")))
You may try to clean up a little bit by doing something like this:
result = baz("hello world")
result = bar(result)
result = foo(result)
But Elixir let's you do this:
"hello world"
|> baz()
|> bar()
|> foo()
Which is kind of cool and easier to understand
Erlang VM (BEAM)
- Monitors and Schedules it's own processes just like your operating systems monitors and schedules processes. When these processes die, BEAM makes sure that the right error code is being reported.
- Can distribute processes across all available CPU cores. If the processes are kind of eating up a lot of resources, BEAM can actually distribute those processes across all available CPU cores. This is a huge performance gain if you have anything that is fairly CPU intensive and it happens automatically. So as long as you're running your application in a concurrent manner and using processes then all the processes will get split across available cores.
- Each process only about 1kb. Erlang processes are incredibly cheap compared to operations and processes so each process is a little bit over a kilobyte so you can spin up by ton of them it's been a very very fascinating diver very quickly
- Each process has its own garbage collector. This method speeds up the execution of new processes. Because everybody collects their own garbage. In other languages, there is general garbage collector which has to stop the world and do garbage collection while other processes wait until the garbage collection process finishes.
Concurrent connections cap (limit)
One Rackspace box that was able to scale up to two million concurrent connections. These connections are not just dummy connections. They were actually simulating real conversations and real message passion between each other the latency for distributing a message across all two million web sockets at that point was lucky two seconds. Such kind of
Rackspace box specs:
128 GB RAM
40 Cores
Case study - Bleachers Report
This is a case study of one company that was able to massive infrastructure savings by moving from one language over another - Elixir. Application was based on 8 year old Rails app. This application is a Sport News website where the company sends a lot of push notifications. So a big thing in the sports news world is, who pushes the sport who's pushes the sports news first.
The before they moved to Elixir/Phoenix
* 150 AWS instances
* Servers were jammed up with requests
* Large engineering team was needed per app
* Multiple complex caching strategies implemented
* Around 3 minutes to notify users about new news report
This is after, they moved to Elixir, Phoenix
- 30 AWS instances
- 10~30 ms averaged response times. This is very good response time
- Largest average spikes: 400ms
- Largest outlier spike: 800ms
- One engineer per app
- No caching needed
- Around 3 seconds to notify user about new news report
Other examples:
These are some of the well known companies which used Elixir/Phoenix to solve their problems
- Wat's App
- Ejabberd
- Riot Games
Difference from Object Oriented Programming
Here is classical OOP structure:
Which is so clean and makes so much sense.
Year or two from that time, this is what happens to it.
(source: https://files.gotocon.com/uploads/slides/conference_3/53/original/Elixir%20-%20The%20only%20sane%20choice%20in%20an%20insane%20world.pdf)
OOP gives you a lot of rope and flexibility. However, limitations are actually better there's power in limiting yourself and what what you can do. The big problem of object-oriented program is "state". You have objects that are carrying state around. They are not immediately accessible, but buried in the memory somewhere. Whereas functional programming is right there in your face
Ending notes:
So this is the end of the current article. Thank you for you interest. I will update this post by adding simplified definitions of genservers, supervisors, meta programming, and doc tests.
If you find any problems please consider those to be my shortcomings, and please feel free to contact me about those problems, i will fix them.
And I would like to express my gratitude to Mr.Brian Cardarella for sharing such a wonderful knowledge with us.