36
Productivity Gains in Erlang Productivity Gains in Erlang A Heriot-Watt and Motorola Production A Heriot-Watt and Motorola Production Commercial Users of Functional Commercial Users of Functional Programming Freiburg, Germany, October Programming Freiburg, Germany, October 4 4 th th 2007 2007 Jan Henry Nyström [email protected] jan@erlang- consulting.com Phil Trinder Phil Trinder [email protected] [email protected] David King David King [email protected] [email protected]

Productivity Gains in Erlang A Heriot-Watt and Motorola Production

  • Upload
    kaloni

  • View
    27

  • Download
    0

Embed Size (px)

DESCRIPTION

Productivity Gains in Erlang A Heriot-Watt and Motorola Production. Commercial Users of Functional Programming Freiburg, Germany, October 4 th 2007. Jan Henry Nyström [email protected] [email protected] Phil Trinder [email protected] David King [email protected]. - PowerPoint PPT Presentation

Citation preview

Page 1: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Productivity Gains in ErlangProductivity Gains in ErlangA Heriot-Watt and Motorola ProductionA Heriot-Watt and Motorola Production

Commercial Users of Functional Commercial Users of Functional Programming Freiburg, Germany, October Programming Freiburg, Germany, October

44thth 2007 2007

Jan Henry Nyströ[email protected] jan@erlang-

consulting.comPhil TrinderPhil Trinder

[email protected]@macs.hw.ac.ukDavid King David King

[email protected]@praxis-his.com

Page 2: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 2

ProjectProjectProjectProject

• High-Level Techniques for Distributed High-Level Techniques for Distributed Telecoms SoftwareTelecoms Software

• EPSRC (UK Govt) Project, Dec 2002 – Feb EPSRC (UK Govt) Project, Dec 2002 – Feb 20062006

• Collaboration between Collaboration between – Motorola UK Labs– Heriot-Watt University

Page 3: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 3

ProjectProject

• High-Level Techniques for Distributed High-Level Techniques for Distributed Telecoms SoftwareTelecoms Software

• EPSRC (UK Govt) Project, Dec 2002 – Feb EPSRC (UK Govt) Project, Dec 2002 – Feb 20062006

• Collaboration between Collaboration between – Motorola UK Labs– Heriot-Watt University

• Aim:Aim: Produce scientific evidence that high- Produce scientific evidence that high-level distributed languages like Erlang or level distributed languages like Erlang or Glasgow distributed Haskell (GdH) can Glasgow distributed Haskell (GdH) can improve distributed software robustness and improve distributed software robustness and productivity.productivity.

Page 4: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 4

Erlang ComparisonsErlang Comparisons

• A number of sequential comparisonsA number of sequential comparisons– Computer Language Shootout

• Very few distributed system comparisons Very few distributed system comparisons published!published!

• Ulf Wiger [Wiger01] reports Ulf Wiger [Wiger01] reports – Erlang systems have between 4 and 10 times less code

than C/C++/Java/PLEX systems– Similar error rates/line of code, similar productivity rates– No direct comparative measurements

Page 5: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 5

Research Questions: Potential Research Questions: Potential BenefitsBenefits• RQ1: Can robust, configurable systems be readily RQ1: Can robust, configurable systems be readily

developed?developed?• Resilience to extreme loadsResilience to extreme loads• Availability in the face of hardware & software failuresAvailability in the face of hardware & software failures• Dynamic reconfigurability on available hardwareDynamic reconfigurability on available hardware

• RQ2: Can productivity and maintainability be RQ2: Can productivity and maintainability be improved?improved?

• How do the sizes of the C++ and Erlang components How do the sizes of the C++ and Erlang components compare & what language features contribute to size compare & what language features contribute to size differential?differential?

Page 6: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 6

Research Questions: FeasibilityResearch Questions: Feasibility

High-level distributed languages:High-level distributed languages:

• Abrogate control of low-level coordination Abrogate control of low-level coordination aspects, soaspects, so

● RQ3: can the required functionality be specified?

• typically pay space and time penalties for their typically pay space and time penalties for their automatic coordination management.automatic coordination management.

● RQ4: can acceptable performance be achieved?

• RQ5: What are the costs of interoperating with RQ5: What are the costs of interoperating with conventional technology?conventional technology?

• RQ6: Is the technology practical?RQ6: Is the technology practical?

Page 7: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 7

Research StrategyResearch Strategy

• Reengineer telecoms applications in GdH and Reengineer telecoms applications in GdH and ErlangErlang– Dispatch Call Controller [NTK04,NTK05]– Data Mobility component

• Compare high-level and Java/C++ Compare high-level and Java/C++ implementations forimplementations for– Performance– Robustness– Productivity– Impact of programming language constructs

Page 8: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 8

First Product ApplicationFirst Product Application

• Communicates with Motorola mobile devicesCommunicates with Motorola mobile devices• 3000 lines of C++ 3000 lines of C++ • Uses 18,000 lines of Motorola C library functions Uses 18,000 lines of Motorola C library functions • Has a transmitter, a receiver and 2 message typesHas a transmitter, a receiver and 2 message types• Interacts with 5 other components of the systemInteracts with 5 other components of the system

Data Mobility Component (DM)Data Mobility Component (DM)

Page 9: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 9

Second ApplicationSecond Application

• Handles mobile phone callsHandles mobile phone calls• A process manages each callA process manages each call• Scalable with multiple serversScalable with multiple servers

Despatch Call Controller (DCC)Despatch Call Controller (DCC)

Page 10: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 10

Two Erlang DM ImplementationsTwo Erlang DM Implementations

1.1. Pure Erlang DMPure Erlang DM

2.2. Erlang / C DMErlang / C DM– Reuses some C DM libraries & drivers

• Both interoperate with a test harnessBoth interoperate with a test harness• CombinesCombines

– Unix Processes– Erlang processes– C Threads (Erlang/C DM)

Page 11: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 11

RQ3 Performance 1: ThroughputRQ3 Performance 1: Throughput

•Maximum DM Throughput at 100% QoS

• Pure Erlang DM is twice as fast as C++ DM

• Better process management and marshalling

• Erlang/C DM is ½ speed of C++ DM

• Still meets nominal throughput

C++ DMC++ DM Erlang/C DMErlang/C DM Pure Erlang Pure Erlang DMDM

480480 230230 940940

Platform: 167MHz, 128Mb Sun Ultra 1, SunOS 5.8

Page 12: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 12

RQ3 Performance 2: Roundtrip RQ3 Performance 2: Roundtrip TimesTimes

0

1

2

3

4

5

6

7

Query type 1 Query type 2 Broken query

C++ DM Erlang/C DM Pure Erlang DM

ms

• Pure Erlang is approximately 3 times faster

• Erlang/C is 26% - 50% slower

Page 13: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 13

Performance AnalysisPerformance Analysis

• Pure Erlang DM is faster due to fast lightweight Pure Erlang DM is faster due to fast lightweight process managementprocess management

• Erlang/C is slower due to additional Erlang/C is slower due to additional communication to C componentscommunication to C components

Page 14: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 14

0

1000

2000

3000

4000

5000

6000

7000

C++ DM Erlang/C DM Erlang DM

Kb

ERTS Moto C lib App C/C++ App Erlang

Performance 3: Memory ResidencePerformance 3: Memory Residence

• Erlang DMs use Erlang DMs use 170% more memory170% more memory• Erlang runtime sys (ERTS) has a fixed sizeErlang runtime sys (ERTS) has a fixed size

• Would be a smaller % of a larger application Would be a smaller % of a larger application

Page 15: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 15

0

200

400

600

800

1000

1200

Erlang A C++ A Pure Erlang A

Load (queries/s)

Throughput

(queries/s)

RQ1 Robustness 1: ResilienceRQ1 Robustness 1: Resilience

Page 16: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 16

When overloaded: When overloaded:

• C++ DM fails catastrophically C++ DM fails catastrophically • Pure Erlang & Erlang/C DMs:Pure Erlang & Erlang/C DMs:• Throughput degradesThroughput degrades

– Never completely fails– Handling 48 q/s at peak load (25000q/s)– Recovers automatically after load drops

RQ1 Robustness 1: ResilienceRQ1 Robustness 1: Resilience

Page 17: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 17

DCC ResilienceDCC Resilience

Page 18: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 18

Robustness 2: AvailabilityRobustness 2: Availability

Erlang DCC system:Erlang DCC system:

• Remains available Remains available despite repeated despite repeated hardware and software hardware and software failuresfailures

• Performance doesn’t Performance doesn’t

degrade with repeated degrade with repeated

failuresfailures

DCC Throughput with Repeated Failures

Page 19: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 19

Robustness 2: AvailabilityRobustness 2: Availability

5-processor DCC with Multiple Failures

Erlang DCC system:Erlang DCC system:

• Resists the Resists the simultaneous failure of simultaneous failure of multiple componentsmultiple components

• When more components When more components fail throughput drops fail throughput drops lower & recovery takes lower & recovery takes longerlonger

Page 20: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 20

Erlang DCC system:Erlang DCC system:

• Dynamically adapt to Dynamically adapt to the available hardware the available hardware resourcesresources

• 5 processor system5 processor system– Remove a processor 4

times

– Add a processor 4 times

Robustness 3: Dynamic Robustness 3: Dynamic ConfigurabilityConfigurability

DCC Throughput

with Varying Numbers of Processors

Page 21: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 21

• Shorter programs are• Faster to develop• Contain fewer errors [Wiger01]• Easier to maintain

• The metric we use is Source Lines Of Code (SLOC)

RQ2: Productivity & MaintainabilityRQ2: Productivity & Maintainability

Page 22: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 22

LangLang..

C/C+C/C+++

ErlanErlangg

TotalTotal

C++C++ 31013101 31013101

Erl./Erl./CC

247247 616616 863863

ErlanErlangg

398398 398398

LangLang..

C++C++ IDLIDL ErlanErlangg

TotalTotal

C++C++ 14.814.8KK

8383 14.914.9KK

ErlanErlangg

48824882 48824882

DM Implementations

DCC Implementations

•Erlang DCC & DM are less than 1/3rd of size of C++ version

•Consistent with Wiger & folklore

Productivity: Source Code SizesProductivity: Source Code Sizes

Page 23: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 23

0

500

1000

1500

2000

2500

3000

3500

C++ DM Erlang/C DM Pure Erlang DM

C++/C Erlang

•Erlang/C DM is 1/3rd of the size of the C++ DMErlang/C DM is 1/3rd of the size of the C++ DM•Pure Erlang DM is 1/7th of the size of the C++ DMPure Erlang DM is 1/7th of the size of the C++ DM•Erlang/C DM is 1/18th of the size of the C++ DM + Erlang/C DM is 1/18th of the size of the C++ DM + librarieslibraries

Productivity: DM Source Code SizesProductivity: DM Source Code Sizes

Page 24: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 24

Reasons for difference in Code SizeReasons for difference in Code Size

• Erlang programmers can– Rely on fault tolerance and code for the successful case – 27% of C++ DM code is defensive

• And have to their use– Automatic memory management (11% of C++ DM code)– High-level communication (23% of C++ DM code)– Telecom design pattern libraries

Page 25: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 25

0%

10%

20%

30%

40%

50%

60%

70%

80%

90%

100%

C++ A Moto Clib Erlang/C Erlang

Defensive

Defines

Includes

Type Delcarations

Communication

Memory Management

Process Management

App

DM Code BreakdownDM Code Breakdown

Page 26: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 26

void DataMobilityRxProcessor::processUnsupVer(void)

{

MSG_PTR msg_buf_ptr;

MM_DEVICE_INFO_MSG *msg_ptr;

RETURN_STATUS ret_status;

UINT16 msg_size;

// Determine size of ici message

msg_size = sizeof( MM_DEVICE_INFO_MSG);

// Create ICI message object to send to DMTX so it sends a Device Info

// message to VLR and HLR clients

IciMsg ici_msg_object( MM_DEVICE_INFO_OPC, ICI_DMTX_TASK_ID, msg_size);

// Retrieve ICI message buffer pointer

msg_buf_ptr = ici_msg_object.getIciMsgBufPtr();

// Typecast pointer from (void *) to (MM_DEVICE_INFO_MSG *)

msg_ptr = (MM_DEVICE_INFO_MSG *)msg_buf_ptr;

// Populate message buffer

SET_MM_DEVICE_INFO_DEVICE_TYPE( msg_ptr, SERVER);

SET_MM_DEVICE_INFO_NUM_VER_SUPPORTED( msg_ptr, NUM_VER_SUPPORTED);

SET_MM_DEVICE_INFO_FIRST_SUP_PROTO_VERS( msg_ptr, PROTO_VERSION_ONE);

// Send message to the DMTX task ret_status = m_ici_io_ptr->send(&ici_msg_object); // Check that message was sent successfully if (ret_status != SUCCESS) { // Report problem when sending ICI message sz_err_msg( MAJOR, SZ_ERR_MSG_ERR_OPCODE, __FILE__, __LINE__, "DataMobilityRxProcessor processUnsupVer: failure sending " " device info message to DMTX"); }

Code Difference ExampleCode Difference Example

Erlangsz_dme_dmtx:cast(device_info)

C++

Page 27: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 27

Erlang DCC ReusabilityErlang DCC Reusability

PartPart SLOCSLOC No. No. ModulesModules

PercentagePercentage

Reusable Reusable PlatformPlatform

29942994 2626 61%61%

Specific Specific ServicesServices

147147 11 3%3%

Testing & Testing & StatisticsStatistics

17411741 1111 36%36%

•Considerable potential for reuse

Page 28: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 28

SummarySummary

• Investigated high-level distributed language Investigated high-level distributed language technology for telecoms softwaretechnology for telecoms software

• Reengineered two telecoms components in Reengineered two telecoms components in Erlang Erlang

• Measured & compared the Erlang & C++ Measured & compared the Erlang & C++ componentscomponents

Page 29: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 29

• Improved resilience: Improved resilience: – Erlang DM and DCC sustain throughput at extreme loads

– Automatically recover when load drops

– C++ DM fails catastrophically (predict C++/CORBA DCC would)

• Improved availability: Improved availability: – Erlang DCC recovers from repeated & multiple failures

– Predict C++/CORBA DCC would fail catastrophically

• Dynamic ReconfigurationDynamic Reconfiguration– Erlang DCC can be dynamically reconfigured to available

hardware

– C++/CORBA DCC can also be dynamically reconfigured using CORBA

• Potential for hot-code loading (not Potential for hot-code loading (not demonstrated)demonstrated)

RQ1:Robust and Configurable RQ1:Robust and Configurable Systems Systems

Page 30: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 30

• Erlang DM and DCC:Erlang DM and DCC:– Less than 1/3rd size of C++ implementation

– Erlang DM 1/18th size of C++ DM with libraries

– Good reusability

• Reasons:Reasons:– Code for successful case – saves 27%

– Automatic memory management – saves 11%

– High-level communications – saves 23%

– Telecom design pattern libraries

RQ2:Productivity and Maintainability RQ2:Productivity and Maintainability

Page 31: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 31

• Even though Erlang abstracts over low-level Even though Erlang abstracts over low-level coordination, the required DM and DCC coordination, the required DM and DCC functionality is readily specified.functionality is readily specified.

Distributed FunctionalityDistributed Functionality

Page 32: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 32

Time:Time:• Max. throughput at 100% QoS:Max. throughput at 100% QoS:

– Pure Erlang DM is twice as fast as C++ DM

– Erlang/C is ½ as fast as C++ DM , but still exceeds throughput requirements

• Roundtrip timesRoundtrip times– Pure Erlang DM is three times as fast as C++ DM

– Erlang/C is between 26% and 50% slower as C++ DM

Space:Space:• Pure Erlang and Erlang/C both have Pure Erlang and Erlang/C both have 170% greater 170% greater

memory residencymemory residency due to (fixed size) 5Mb due to (fixed size) 5Mb runtime system runtime system

RQ4: PerformanceRQ4: Performance

Page 33: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 33

• Erlang DMs interoperate with a C test harness, Erlang DMs interoperate with a C test harness, and Erlang/C DM incorporates C drivers & library and Erlang/C DM incorporates C drivers & library functionsfunctions

• CostsCosts– Low space cost: an additional 15% residency

– High time cost: • Erlang/C roundtrip times up to 6 times pure Erlang

• Erlang/C max. throughput ¼ of pure Erlang

• Potential for incremental re-engineering of large Potential for incremental re-engineering of large systemssystems

RQ5: Interoperation CostsRQ5: Interoperation Costs

Page 34: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 34

• Erlang is available on several HW/OS Erlang is available on several HW/OS platforms, including the Sun/Solaris DM platforms, including the Sun/Solaris DM product platformproduct platform

• Is supported with training, consultancy, Is supported with training, consultancy, libraries etc.libraries etc.

RQ6: PragmaticsRQ6: Pragmatics

Page 35: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 35

• Erlang offers robustness & productivity Erlang offers robustness & productivity benefits for distributed telecoms software benefits for distributed telecoms software (RQs 1 & 2)(RQs 1 & 2)

• High-level distributed languages like Erlang High-level distributed languages like Erlang can deliver the required telecoms can deliver the required telecoms functionality and performance (RQs 3 & 4)functionality and performance (RQs 3 & 4)

• Erlang can interoperate with existing Erlang can interoperate with existing technologies and meets pragmatic technologies and meets pragmatic requirements (RQs 5 and 6)requirements (RQs 5 and 6)

ConclusionsConclusions

Page 36: Productivity Gains in Erlang A Heriot-Watt and Motorola Production

Page 36

Further InformationFurther Information• Web sites/SeminarsWeb sites/Seminars

– Project Site: www.macs.hw.ac.uk/~dsg/telecoms/• ReferencesReferences

– [NTK04] Nystrom J.H. Trinder P.W. King D.J. Evaluating Erlang for Robust

– Telecoms Software S3S’04, Chicago, July 2004.– [NTK05] Nystrom J.H. Trinder P.W. King D.J. Are High-

Level languages suitable for– Robust Telecoms Software? SafeComp’05, Fredrikstad,

Norway, Sept. 2005.– [Wiger01] Ulf Wiger, Workshop on Formal Design of

Safety Critical Embedded– Systems, Munich, March 2001

http://www.erlang.se/publications/Ulf_Wiger.pdf