Functional Functional Programm Programming ing XP XP The - - PowerPoint PPT Presentation

functional functional programm programming
SMART_READER_LITE
LIVE PREVIEW

Functional Functional Programm Programming ing XP XP The - - PowerPoint PPT Presentation

Functional Functional Programm Programming ing XP XP The Industrial Experience 2013-02-21 vers 1 1 Kar Karol ol Ostrovsk Ostrovsk M.Sc. Comenius University, Bratislava Ph.D. Chalmers Post-doc Chalmers System


slide-1
SLIDE 1 2013-02-21 vers 1

Functional Functional Programm Programming ingXP

XP

1

The Industrial Experience

slide-2
SLIDE 2

Kar Karol

  • l Ostrovsk

Ostrovský

  • M.Sc. – Comenius University, Bratislava
  • Ph.D. – Chalmers
  • Post-doc – Chalmers
  • System Designer – Dfind IT
  • On assignment for Ericsson
  • Operations & Maintenance Subsystem

2

slide-3
SLIDE 3

The Chalmers Years The Chalmers Years

  • Research in static analysis of concurrent

programming languages

  • Type systems
  • Protocol analysis
  • Main course responsible
  • Concurrent Programming Course – TDA381
  • Developed the course between 2005 and 2010

3

slide-4
SLIDE 4

The Langua The Language & Para ge & Paradigm Nerd digm Nerd

  • Language skills
  • Basic
  • Pascal
  • C/C++
  • Scheme
  • SmallTalk
  • Java
  • JR (MPD)
  • Haskell
  • Erlang
  • Ocaml
  • LaTeX
  • VAX assembler
  • Trilogy
  • Ada
  • Agda
  • Some of my own

4

slide-5
SLIDE 5

What is Program What is Programming? ming?

  • Manipulation of Structures

5

slide-6
SLIDE 6

Compositions Compositions

  • Functions

6

map reduce/fold

slide-7
SLIDE 7

Str Structures uctures

  • Types

7

[B] C

slide-8
SLIDE 8

My Fa My Favourite Slide vourite Slide

8

The Message from this Course

  • Should you forget everything from this

course, please, remember at least this saying:

3 PPVT10 – Introduction

Use the right tool for the job.

slide-9
SLIDE 9

Mobile Mobile Telecom Network Telecom Network

9

slide-10
SLIDE 10

Packet Core Packet Core Network Network

  • 3GPP
  • Defines standards (mostly protocols)
  • Interoperability is essential
  • SGSN-MME
  • Servicing GPRS Support Node (2G/3G)
  • Mobility Management Entity (4G)
  • Control signalling

− Admission control, Authentication − Mobility, roaming

  • Payload transport (not in 4G)

10

slide-11
SLIDE 11

SGSN SGSN-MME MME MkVI MkVI

  • 3 sub-racks
  • 21 blades (2+19)
  • 2 core PowerPC
  • ~ 114 simultaneously

running processes

  • Backplane: 1Gbps
  • Capacity: 3MSAU

11

slide-12
SLIDE 12

SGSN SGSN-MME MME MkVI MkVIII II

  • 3 sub-racks
  • 14 blades (2+12)
  • 6 core Intel x86
  • 12 SMT threads total
  • ~ 432 simultaneously

running processes

  • Backplane: 1 or 10Gbps
  • Capacity: 10MSAU

12

slide-13
SLIDE 13

SGSN SGSN-MME MME – Archite Architecture cture Sketch Sketch

13

...... ...

NCB FSB FSB DP DP DP AP AP AP NCB

slide-14
SLIDE 14

SGSN SGSN-MME MME – Use Use The Right Tool The Right Tool

  • Control Plane
  • Erlang

− concurrency − distribution − fault-tolerance

  • DSL

− frameworks for protocol implementation

  • User Plane
  • C
  • time-critical

14

slide-15
SLIDE 15

Erlang Erlang – The Functional Advantage The Functional Advantage

  • Protocol Programming
  • 3GPP standards
  • Domain experts not software engineers
  • DSL
  • A “library” of abstractions

− Possible in any language − Often easier in a functional language

  • A set of combinator “glues”

− Considerably more powerful in a functional language

15

slide-16
SLIDE 16

Typical Concurrency Typical Concurrency Patterns Patterns

  • One mobile – one process (replicated worker)
  • Isolation
  • Synchronisation only with resources
  • Central resources
  • Resource allocator
  • Master/coordinator – slave/worker
  • Transaction handler

16

slide-17
SLIDE 17

Distribution Distribution

  • One mobile – one process
  • Evenly distribute all phones over all blades
  • Replicate data for fault-tolerance
  • Central resources
  • Run on the master-blade
  • Replicate to all the slaves
  • Can we survive without a master?

17

slide-18
SLIDE 18

Fault Fault-tolerance tolerance

  • SGSN-MME requirement: 99.999% availability
  • Hardware
  • Faulty blades are automatically taken out of service
  • Mobile phones redistributed
  • Software
  • Fail fast – offensive programming
  • Recovery strategy

18

slide-19
SLIDE 19

Fault Fault-tolerance tolerance – Softw Software are

  • Phone process crash should never affect others
  • Automatic memory handling
  • Process monitoring
  • Recovery Strategy – escalate
  • Restart the phone process
  • Restart the whole blade
  • Restart the whole node

19

slide-20
SLIDE 20

Sieve Sieve of Er

  • f Eratos

atosthenes thenes

20

46 PPVT10 – Message Passing

Architecture

  • N+1 pipeline channels
  • One shared output channel

filter1 filter2 filterN nums eat

  • utput

print

slide-21
SLIDE 21

logging LOG

Pipeli Pipeline o ne of Proc f Processes esses

21

AP_1 AP_2 AP_N NCB

slide-22
SLIDE 22

Hask Haskell ell Patterns Patterns – Monads Monads

  • Good
  • Keeps pure and side-effecting computations apart

− Good separation of concerns − Improved compositionality − Possible performance gain

  • Gather writes together and write to DB once –

amortise the cost of transactions:

− 1 item write costs 10 − 10 items write is not 100 but only 20!

22

slide-23
SLIDE 23

Hask Haskell ell Patterns Patterns – Monads Monads

  • Bad
  • In rapid prototyping it can present a big hurdle to

jump over

  • So, it is good that Erlang does not have static types
  • Lazy evaluation is more complicated in the presence
  • f side-effects especially inter-process

communication

23

slide-24
SLIDE 24

OO OO-Design P Design Patterns atterns

  • Factory method
  • Improve memory sharing
  • Object pool
  • Bounded parallelisation of algorithms – thread pool
  • Overload protection

24

slide-25
SLIDE 25

What they do not teach you What they do not teach you

  • Software lives long
  • Especially telecom systems (decades)
  • Banking systems live even longer (think COBOL)
  • People change
  • Organisations change
  • Hardware changes
  • Requirements change
  • Documentation often does not change

25

slide-26
SLIDE 26

Softw Software are Maintenance Maintenance

  • The developer’s challenge
  • Write simple (readable) and efficient code:

1.

Write a straightforward and working solution first

2.

Optimise later (or even better skip this step)

  • Think smart but do not over-optimise
  • Optimisations complicate maintenance
  • The code is often the only reliable document
  • Types can be very good documentation

26

slide-27
SLIDE 27

Synthesis Synthesis and Analysis and Analysis

  • Emphasis on synthesis in education
  • Software development from scratch
  • Industrial systems often have a legacy
  • Software development by further iteration

− Refactoring − Code review − Software maintenance

  • Need for both analytical and synthesizing thinking

27

slide-28
SLIDE 28

Synthesis Synthesis and Analysis and Analysis

  • Roughly 30% of manpower is spent on testing
  • Analytical work
  • Do you like to break a system?
  • But testing can also be “synthesizing”
  • Testing frameworks

− Quickcheck − SGSN-MME has its own

  • Would you like to formally prove the system correct?

28

slide-29
SLIDE 29

Erlang in Pra Erlang in Practic ctice e – Pros Pros

  • Well suited for
  • Control handling of telecom traffic
  • Application layer (OSI model) applications

− Web servers, etc.

  • Domain Specific Language – framework

− Test scripting

  • Reasonably high-level (as compared to for

example C)

  • Good for software maintenance

29

slide-30
SLIDE 30

Erlang in Pra Erlang in Practic ctice e – Pros Pros

  • Dynamic typing
  • Aids rapid prototyping
  • OTP – includes useful building blocks
  • Supervisor
  • Generic server
  • Finite state machine

30

slide-31
SLIDE 31

Erlang in Pra Erlang in Practic ctice e – Cons Cons

  • Hard to find good Erlang programmers (?)
  • Management b......t
  • Long live Chalmers
  • A bit too low-level language
  • Given current HW limitations one must sometimes
  • ptimise to the point where the code is not portable

(with the same performance)

  • Raise the abstraction and provide a customisable

compiler, VM (Elixir?)

31

slide-32
SLIDE 32

Erlang in Pra Erlang in Practic ctice e – Cons Cons

  • Where is the type system?
  • A static type system of Haskell-nature would

probably be a hindrance

  • But good static analysis tools are desperately

needed

  • Types are an excellent form of documentation

32

slide-33
SLIDE 33

More T More Than True han True

33

54 PPVT10 – Introduction

Sayings

  • The greatest performance improvement of all

is when a system goes from not-working to working

  • The only thing worse than a problem that

happens all the time is a problem that doesn't happen all the time

slide-34
SLIDE 34

Functional P Functional Progra rogramming mming

  • Widespread use
  • Embedded (cars, satellites, etc.), web-apps, games,

banks, big-data, …

  • Abstractions and compositionality
  • Productivity gains

34

slide-35
SLIDE 35

The Industria The Industrial l Experienc Experience

  • It is more difficult that you expect, but
  • Usually not in complexity but size
  • Good methodical approach helps
  • Lateral thinking is an asset
  • Learn many programming paradigms
  • Learn many programming languages

35