SlideShare a Scribd company logo
1 of 44
Download to read offline
5-я конференция .NET разработчиков
21 октября 2012
www.dotnetconf.ru




       Краткое введение в Erlang/OTP

                               Александр Карпич
                                    «Планар»
                                twitter.com/_ymn
Веб сегодня
●
    Большое количество
    пользователей
●
    Множество долгоживущих
    соединений
●
    Многопроцессорные
    конфигурации оборудования

         Краткое введение в Erlang/OTP Александр Карпич
                                      ,                   2
Больше интерактива!
●
    Аудио/видео стримминг
●
    Системы обмена сообщениями
●
    Мобильные приложения




         Краткое введение в Erlang/OTP Александр Карпич
                                      ,                   3
Инструменты:
●
    C++
●
    Java
●
    .NET
●
    Node.JS
●
    Всякие Python, Perl, Ruby

           Краткое введение в Erlang/OTP Александр Карпич
                                        ,                   4
Проблемы реализации
●
    Утечки памяти
●
    Утечки ресурсов
●
    Сложность параллельного
    программирования
●
    Проблемы с масштабированием

          Краткое введение в Erlang/OTP Александр Карпич
                                       ,                   5
Серебряной пули нет




 Краткое введение в Erlang/OTP Александр Карпич
                              ,                   6
Но есть инструмент, позволяющий
    решать многие проблемы



       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   7
Краткое введение в Erlang/OTP Александр Карпич
                             ,                   8
●
    25 лет использования в продакшн
●
    Придуман ленивыми инженерами,
    которые хотели проводить выходные дома
●
    Erlang — не академическая поделка вроде
    Haskell
●
    Разрабатывался и тестировался в «боевых»
    условиях


            Краткое введение в Erlang/OTP Александр Карпич
                                         ,                   9
Кто использует?




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   10
«You probably use systems based
    on Erlang/OTP every day
      without knowing it.»

                                                Mike Williams


       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   11
Кто использует




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   12
Что написано




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   13
Killer features
• Изолированные потоки исполнения
• Обмен копируемыми сообщениями
• Иммутабельные данные




       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   14
Решение проблем
• Иммутабельные данные решают
  проблему утечек ресурсов
• Данные умирают вместе с
  процессами
• Специфическая обработка ошибок



       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   15
Обработка ошибок
• Проверка входящих параметров?
• Исключения?
• POSIX Сигналы?




       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   16
Есть идея получше




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   17
Let it fail!




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   18
Worker/Supervisor




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   19
one_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   20
one_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   21
one_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   22
all_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   23
all_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   24
all_for_one




Краткое введение в Erlang/OTP Александр Карпич
                             ,                   25
Учим Erlang за 40 минут




   Краткое введение в Erlang/OTP Александр Карпич
                                ,                   26
Типы
• Числа — 42, 3.14, 9.1E-31
• Атомы — ok, true, blablabla
• Кортежи — {1, true, {msg, 123}, 42}
• Списки — [1, 2, [3, 4]]
• Строки — «abc», [97, 98, 99]
• Булева логика — true, false

         Краткое введение в Erlang/OTP Александр Карпич
                                      ,                   27
Переменные
• Имена начинаются с большой буквы
• Одиночное присваивание

1> A = 42.
42
2> A = 43.
** exception error: no match of right hand side value 43



             Краткое введение в Erlang/OTP Александр Карпич
                                          ,                   28
Pattern matching


fib(0) → 0;
fib(1) → 1;
fib(N) when N>1 → fib(N-1) + fib(N-2).




         Краткое введение в Erlang/OTP Александр Карпич
                                      ,                   29
Hello World!

-module(hello).
-export([start/0]).

start() ->
   io:format("Hello world!~n").




            Краткое введение в Erlang/OTP Александр Карпич
                                         ,                   30
Краткое введение в Erlang/OTP Александр Карпич
                             ,                   31
Создаем процесс



Pid = spawn(mod, func, [A, B, C]).




     Краткое введение в Erlang/OTP Александр Карпич
                                  ,                   32
Отправляем сообщение



               Pid ! Msg.




  Краткое введение в Erlang/OTP Александр Карпич
                               ,                   33
Принимаем сообщение



          receive
            Msg → Msg
          end.


  Краткое введение в Erlang/OTP Александр Карпич
                               ,                   34
Hello World!
-module(hello).
-export([start/0, loop/0]).

start() ->
    Pid = spawn(hello, loop, []),
    Pid ! hello.

loop() ->
    receive
         hello ->
             io:format("Hello, World!~n"),
             loop()
    end.

                 Краткое введение в Erlang/OTP Александр Карпич
                                              ,                   35
Сравнение с другими языками




   Краткое введение в Erlang/OTP Александр Карпич
                                ,                   36
Erlang vs. C/C++
• Более продуктивен
• Более надежен
• Более краток
• Модель акторов
• На порядок медленнее



       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   37
Erlang vs. Java
• Проектировался для
  многопроцессорных конфигураций
• Легко масштабируется
• Горячая замена кода
• Меньше библиотек



       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   38
Недостатки
• На порядок медленнее C
• Работа со строками
• Динамическая типизация
• Непривычный синтаксис




       Краткое введение в Erlang/OTP Александр Карпич
                                    ,                   39
Расширяем возможности




 Краткое введение в Erlang/OTP Александр Карпич
                              ,                   40
Краткое введение в Erlang/OTP Александр Карпич
                             ,                   41
Материалы для обучения




 Краткое введение в Erlang/OTP Александр Карпич
                              ,                   42
• http://learnyousomeerlang.com/
• Armstrong — «Programming Erlang:
  Software for Concurrent World»
• Cesarini, Thompson — «Erlang
  Programming»
• erlang@conference.jabber.ru
• http://erlang-russian.org/

        Краткое введение в Erlang/OTP Александр Карпич
                                     ,                   43
Спасибо за внимание

          Александр Карпич
                «Планар»
        avkarpich@gmail.com
           twitter.com/_ymn




  Краткое введение в Erlang/OTP Александр Карпич
                               ,                   44

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Краткое введение в Erlang/OTP