Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior...

48
1 © 2013 The MathWorks, Inc. Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks

Transcript of Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior...

Page 1: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

1 © 2013 The MathWorks, Inc.

Scaling up MATLAB Analytics

Marta Wilczkowiak, PhD

Senior Applications Engineer

MathWorks

Page 2: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

2

Agenda

Giving access to your analytics to more users

Handling larger problems

Page 3: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

3

When Scalability is a Challenge

You have great functionality, yet people do not have

access to it

You have purchased more computers, yet you can not

execute much more functions

You hired more people, yet software gets developed at

the same scale

Page 4: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

4

Examples

Increase number of Monte Carlo simulations

Share portfolio, risk or trading apps with a few traders

Deploy pricing functions into an enterprise pricing platform

serving front, middle and back offices

Update prices nightly, or intraday, in an enterprise

database

Add strategies to a trading platform

f(x) More access

More

computational

power

Page 5: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

5

Presentation

(Client)

Logic

(Algorithm)

Data

Multi-tier Architecture

Page 6: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

6

More access

More

computational power

What We Are Looking at in This Session

Page 7: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

7

Enabling Access to MATLAB Algorithms

(Deployment)

Page 8: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

8

What Is Application Deployment?

Sharing MATLAB apps or native files with

other MATLAB users

Sharing MATLAB programs with people

who do not have MATLAB

Page 9: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

9

Tools

Page 10: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

10

Deployment options

Live MATLAB

– Apps

MATLAB Complier

– Standalone applications

– Software modules

MATLAB Production Server

Page 11: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

11

Deployment options

Live MATLAB

– Apps

MATLAB Complier

– Standalone applications

– Software modules

MATLAB Production Server

Page 12: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

12

MATLAB Apps

MATLAB Apps: Custom interactive

applications running in MATLAB

Easy to package, install and find

Support full MATLAB language

Require MATLAB to run

Page 13: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

13

Deployment options

Live MATLAB

– Apps

MATLAB Complier

– Standalone applications

– Software modules

MATLAB Production Server

Page 14: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

14

What is MATLAB Compiler?

MATLAB Compiler

MATLAB Builder NE

MATLAB Builder EX

MATLAB Builder JA

.exe .dll .NET COM Java Excel MPS

archive

Software that let’s you to:

Package your MATLAB code so that it does not require MATLAB

license

Encrypt your intellectual property

Page 15: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

15

MATLAB Compiler Runtime

MATLAB

Compiler

MATLAB

Source Code

MATLAB

Encrypted Code

MATLAB Compiler

Runtime (MCR)

Execute Single threaded access

Page 16: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

16

Typical deployment process for desktop applications

1. Create MATLAB code

MATLAB Compiler

2. Package the code 3. Share the installer

4. Install the

application

and MCR

Page 17: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

17

Desktop Applications

Potential scalability challenges

Distributing software updates to multiple users

Installing application in uncontrolled IT setup (admin

rights, different OS, etc.)

Slow data transfer from a remote location

Hardware resources on the client machines inadequate

to application demands

Distributing MCR updates to multiple users

Page 18: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

18

Scaling Up: Demand for Server Analytics

Less need for processing power and

memory

Simplified code management

Optimal access to data and

hardware resources

Security

Server

Client

Challenge:

Giving access to MATLAB

to multiple requesters

(single threaded MCR)

Page 19: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

19

Deployment options

Live MATLAB

– Apps

MATLAB Complier

– Standalone applications

– Software modules

MATLAB Production Server

Page 20: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

20

What is MATLAB Production Server?

Request

Broker

&

Program

Manager

MPS

Archive

.NET

Enterprise class framework for running packaged MATLAB programs

Lightweight client library Requests execution of algorithms

Server software Manages algorithms

& worker pool

Runtime libraries Execute algorithms

Component repository Stores deployed components

Page 21: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

21

Integrating with IT Systems

Web

Server

Application

Server

Database Server

Pricing

Risk

Analytics

Portfolio

Optimization

MATLAB Production Server

Web

Applications

Desktop

Applications

Excel®

Page 22: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

22

MATLAB Production Server Scalable and reliable way for giving access to

MATLAB algorithms

Centralised library of

algorithms

Simultaneous access to multiple users

Execution efficiency

• Access immediately

• Execute with optimised hardware and access to the data

Ease of access

• Use with different clients: web, database & application servers

• Integrate easily with application software using the lightweight client library

• Call using native data types

Simple management

• Let MPS manage the worker pool, algorithms and MCRs

• Update the algorithms automatically

• Separate the development and execution of application and algorithmic code

Page 23: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

23

Deploying Enterprise Applications

Page 24: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

24

Deploying Your Code To a Server

Considerations

Page 25: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

25

Will Clients Call the Algorithm Simultaneously?

What Interfaces the Client Can Use?

What Should the Input / Output Be ?

What are Other Dependencies of the Algorithm?

How to Keep the Algorithm Available?

What is the Response Time?

Server Deployment: Main Considerations

Client

Data

Page 26: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

26

Will Clients Call the Algorithm Simultaneously?

Desktop application Web application Database/web/application server

f(x)

Providing access to multiple MCRs

- Using MPS

- Using 3rd party or proprietary solutions (watch MCR start up and

development time)

Page 27: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

27

What Interfaces the Client Can Use

What “language” does the client speak?

Bottom line: MATLAB components can be called from any application that

has external interfaces

.dll .NET COM Java Excel

Add-In

Desktop application Web application Database/web/application server

f(x)

?

Page 28: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

28

What Should Be the Input/Output?

f(x) I O

Page 29: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

30

What Should Be the Input/Output?

Example 1

Client f(x)

MATLAB pulls data

from sources

Client sends

simple parameters

Deploy pricing functions into an enterprise pricing platform

Page 30: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

32

What Should Be the Input/Output?

Example 2

Client f(x)

Client pushes all

data to MATLAB

Add algorithms to a trading platform

Page 31: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

33

What Should Be the Input/Output?

Example 3

Bring algorithm to data

Examples

Update prices nightly, or intraday, in an enterprise database

Client f(x)

Client pushes all

data to MATLAB

Page 32: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

34

What Should Be the Input/Output?

Summary

f(x) I O

Main considerations

• What is needed

• Data types

• Is data on the client anyway?

• Need/want to use of existing enterprise I/O functions

• Marshalling time

Page 33: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

35

What are Other Dependencies of the Algorithm?

State/persistent data

function out = getNextNumber

persistent n;

if isempty(n)

n = 0;

end

n = n+1;

out = n;

0

1

2

Page 34: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

36

What are Other Dependencies of the Algorithm?

Removing state/persistent data

Refactor

Store state in

Database

MAT files

In-memory storage

Config files

Make sure they will be present in the production environment

function out = getNextNumber

persistent n;

if isempty(n)

n = 0;

end

n = n+1;

out = n;

function out = getNextNumber(n)

out = n+1;

Page 35: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

37

How to Keep the Algorithm Available

function makeExit

exit

Monitor and maintain the worker(s)

Imagine

f(x)

f(x)

Page 36: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

38

What is the Response Time

f(x)

1 min 1min is fast for daily risk report

1min is slow for interactive pricing

If the algorithm is not fast enough for the client

• Accelerate your code

• Warn the client

• Minimize call overhead

• Reduce data marshalling

• MCR start-up time

• Algorithm closer to data

Page 37: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

39

Off the Shelf Product Features

for Server-Side Deployment

MATLAB

Compiler

+Builders

MATLAB

Production

Server

Code locked

Logic out of process

Reduced MCR start up time

Simultaneous access

Monitor and maintain the worker(s)

: Built in

Page 38: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

40

Creating Production Ready MATLAB Algorithms

Prototype

Algorithm Developer

Production Code

Software Engineer

Internal collaboration

MathWorks Consulting Services

Page 39: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

41

Using More Computational Power

(Parallel Computing)

Page 40: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

42

Parallel Computing Tools Address…

Long computations

– Multiple independent

iterations

– Series of tasks

Large data problems

parfor i = 1 : n

% do something with i

end

Task 1 Task 2 Task 3 Task 4

11 26 41

12 27 42

13 28 43

14 29 44

15 30 45

16 31 46

17 32 47

17 33 48

19 34 49

20 35 50

21 36 51

22 37 52

Task-Parallel Data-Parallel

Page 41: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

43

Parallel Computing Toolbox for the Desktop

Speed up parallel applications

Take advantage of GPUs

Prototype code for your cluster

MATLAB

Desktop (Client)

Local

Desktop Computer

Page 42: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

44

Scale Up to Clusters and Clouds

MATLAB

Desktop (Client)

Local

Desktop Computer

Cluster

Computer Cluster

Scheduler

Page 43: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

45

Main Considerations for Scalability

Data transfer

Resource contention

Other overheads

Page 44: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

46

Resource Contention

Memory

HT HT

Core

HT HT

Core

HT HT

Core

HT HT

Core

Cache Memory (L3)

HT HT

Core

HT HT

Core

HT HT

Core

HT HT

Core

Cache Memory (L3)

IO Hub

Disk

Network

Performance

Page 45: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

47

Speedup vs. num. Concurrent Processes

a = bigMatrix

a*a

fft(a)

sum(a)

Performance

Page 46: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

48

Speedup vs. num. Concurrent Processes

Hyperthreaded

Cores

a = bigMatrix

a*a

fft(a)

sum(a)

Performance

Page 47: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

49

More Data

More access

More

computational power

What We Have Seen

Page 48: Scaling up MATLAB Analytics€¦ · Scaling up MATLAB Analytics Marta Wilczkowiak, PhD Senior Applications Engineer MathWorks . 2 ... .NET Enterprise class framework for running packaged

50

Scaling Up MATLAB Analytics

Rapid prototyping of ideas

Scalable algorithms

- using more computational power

- with wide access