The Architect's Two Hats

115
The Architect’s Two Hats Ben Stopford Architect High Performance Computing RBS

description

This presentation, given on the Software Architecture course at the University of Brunel, discusses the interplay between architecture and design. How the designer and architect are really different roles and ones that often have competing goals.

Transcript of The Architect's Two Hats

Page 1: The Architect's Two Hats

The Architect’s Two Hats

Ben StopfordArchitect

High Performance ComputingRBS

Page 2: The Architect's Two Hats

Once upon a time

Page 3: The Architect's Two Hats

In a land far far away

Page 4: The Architect's Two Hats

There was a designer

Page 5: The Architect's Two Hats
Page 6: The Architect's Two Hats

And an architect

Page 7: The Architect's Two Hats
Page 8: The Architect's Two Hats

And they didn’t really get on

Page 9: The Architect's Two Hats

OK – that’s not entirely true – but they have competing objectives

Page 10: The Architect's Two Hats

This is the story of the architect’s two hats

Page 11: The Architect's Two Hats

So what are the two hats all about?

Page 12: The Architect's Two Hats

Design

The internal structure of software at a code level.

Controlling the complexity of the software as it grows.

Keeping it comprehensible and fungible. Basically everything that Steve has been telling

you so far.

Page 13: The Architect's Two Hats

Architecture

The non functional stuff that fights against design.

The stuff we do because we have to. Because we need to build systems that are fast

and resilient. This includes everything from machine

specifications to grid infrastructures

Page 14: The Architect's Two Hats

So lets look at how design works in industry

Page 15: The Architect's Two Hats

We’ll look at architecture for performance a bit later,

right now lets look at design

Page 16: The Architect's Two Hats

Software Design

Page 17: The Architect's Two Hats

Why do we need to worry about Design?

Software evolves over time. Unmanaged change leads to spaghetti code

bases where classes are highly coupled to one another.

This makes them brittle and difficult to understand

Page 18: The Architect's Two Hats

So how to we avoid this?

Page 19: The Architect's Two Hats

We design our solution well so that it is easy to understand and change

Page 20: The Architect's Two Hats

And we all know how to do that right?

I’m going to play with you a bit now….

Page 21: The Architect's Two Hats

We Design our System Up Front

Page 22: The Architect's Two Hats

… with UML

Page 23: The Architect's Two Hats

AND…

We get to spot problems early on in the project lifecycle.

Why is that advantageous?

Page 24: The Architect's Two Hats

Why? Because it costs less to get the design right early on, see:

Low cost of change early in lifecycle

Page 25: The Architect's Two Hats

So we have a plan for how to build our application before we start

coding.

All we need to do is follow the plan!!

Page 26: The Architect's Two Hats

Well…..

That’s what we used to do…

…but problems kept cropping up…

Page 27: The Architect's Two Hats

It was really hard to get the design right up front.

The problems we face are hard. The human brain is bad at predicting all the

implications of a complex solution up front. When we came to implementing solutions, our

perspective would inevitably change and so would our design.

Page 28: The Architect's Two Hats

And then…

…when we did get the design right…

…the users would go and change the requirements and we’d have to

redesign our model.

Page 29: The Architect's Two Hats

Ahhh, those pesky users, why can’t they make up their minds?

Page 30: The Architect's Two Hats

So…

…in summary…

Page 31: The Architect's Two Hats

We find designing up front hard…

Page 32: The Architect's Two Hats

...and a bit bureaucratic

Page 33: The Architect's Two Hats

…and when we do get it right the users generally go and change the

requirements…

Page 34: The Architect's Two Hats

…and it all changes in the next release anyway.

Page 35: The Architect's Two Hats

So are we taking the right approach

Page 36: The Architect's Two Hats

Software is supposed to be soft.

That means it is supposed to be easy to change.

Page 37: The Architect's Two Hats

So is fixing the design up front the right way to do it?

Page 38: The Architect's Two Hats

But we’ve seen that changing the design later in the project life cycle is

expensive!

Page 39: The Architect's Two Hats

So does the cost curve have to look like this?

Page 40: The Architect's Two Hats

Can we design our systems so that we CAN change them later in the

lifecycle?

Page 41: The Architect's Two Hats

The Cost of Change in an Agile application

Page 42: The Architect's Two Hats

How

Page 43: The Architect's Two Hats

By designing for change

** But not designing for any specific changes

*** And writing lots and lots of tests

Page 44: The Architect's Two Hats

Agile Development facilitates this

Code Base

Test

Test

Test

Page 45: The Architect's Two Hats

Dynamic Design

Similar to up-front design except that it is done little and often.

Design just enough to solve the problem we are facing now, and NO MORE.

Refactor it later when a more complex solution is needed.

Page 46: The Architect's Two Hats

This means that your system’s design will constantly evolve.

Page 47: The Architect's Two Hats

So what does this imply for the Designer?

Page 48: The Architect's Two Hats

It implies that the designer must constantly steer the application so that it remains easy to understand

and easy to change.

Page 49: The Architect's Two Hats

With everyone being responsible for the design.

Page 50: The Architect's Two Hats

So the designers role becomes about steering the applications design

through others.

Page 51: The Architect's Two Hats

Shepherding the team!

Page 52: The Architect's Two Hats

Shepherding the team

People will always develop software in their own way. You can’t change this.

You use the techniques you know to keep the team moving in the right direction.

Occasionally one will run of in some tangential direction and when you see this you move them back.

Page 53: The Architect's Two Hats

How? Encourage preferred patterns. Encourage reuse. Software Process Communication Frameworks

Page 54: The Architect's Two Hats

In industry we see the design of a system evolve. It does not all happen up front.

We use agile methods to let us get away with changing things later.

We design for change using the patterns steve has discussed. Separation of Concerns, Interfaces etc.

Page 55: The Architect's Two Hats

Now we can switch to the architects hat.

Page 56: The Architect's Two Hats

Architecting for performance

And why it can fight against good design

Page 57: The Architect's Two Hats

If speed is going to be a problem….

Then evolutionary design alone may not work

Page 58: The Architect's Two Hats

We need to seed the design with clever architectural decisions to

ensure we get the speed we need

Page 59: The Architect's Two Hats

We use patterns and frameworks that increase speed

But often at the expense of a clear programming model. i.e. these

patterns can obfuscate the implementation.

Page 60: The Architect's Two Hats

How it fits together: A project timeline

Set-up Architecture

Design: Push patterns and reuse etc

Amend Architecture

Page 61: The Architect's Two Hats

So lets look at how we architect for speed

Page 62: The Architect's Two Hats

Load Balancing

Ideal for applications that cleanly segregate into

discrete pieces of work e.g. Commercial websites.

Page 63: The Architect's Two Hats

Load Balancing: Horizontal Scalability

Page 64: The Architect's Two Hats

Load balancing is great way to get horizontal scalability without affecting

the programming model much!!

Page 65: The Architect's Two Hats

But it is limited by the time taken for a single request

i.e. it allows us to handle more load, but does not allow us to reduce the

time taken to execute single process

Page 66: The Architect's Two Hats

What if we want to make a single (possibly long running) processes

faster?

Lets look at an example

Page 67: The Architect's Two Hats

Sum the numbers between 1 and 10,000,000

int totalfor (n =1 to 10,000,000){

total+=n}

A service has a hard limit on how fast it can execute this, defined by it’s clock speed.

Load balancing won’t speed this up.

Page 68: The Architect's Two Hats

How do we speed this up programming in process intensive

cases?

Exploit the parallelism of multiple cores or machines

Page 69: The Architect's Two Hats

Make it faster, using threads and multiple cores

New Thread(){for (n =1 to 100){

total+=n}

}

New Thread(){for (n =101 to 200){

total+=n}

}…..

Page 70: The Architect's Two Hats

Larger Machines - Azul

Up to 768 processors in a single machine Each processor has up to 1GB local memory RAID 10 based disk access (redundancy for

speed) Customised JVM distributes processing over

available processors and handles garbage collection in hardware (why is this a problem?).

Expensive (£300-400K). Still has a hard limit of 768 processors.

Page 71: The Architect's Two Hats

This is scaling up

Page 72: The Architect's Two Hats

But it costs

Page 73: The Architect's Two Hats

But we can also scale out. i.e. lots of normal hardware linked together

Page 74: The Architect's Two Hats

Scaling Out is Cost Effective

Scaling out is much more cost effective per teraflop than scaling up.

Page 75: The Architect's Two Hats

But it adds complexity to the programming model

Page 76: The Architect's Two Hats

Key Point: Role of an Architect is to construct and application that performs - that often means a

distributed system

Distributed Systems can be much harder to manage than those that run

on a single machine

Why?

Page 77: The Architect's Two Hats

Because standard computing models don’t work in a distributed world.

Page 78: The Architect's Two Hats

The Trials of Distributed Computing

Page 79: The Architect's Two Hats

As we distribute our application across multiple machines, complexity is

moved from hardware to software.

Page 80: The Architect's Two Hats

The major problem is the lack of fast shared memory

Page 81: The Architect's Two Hats

Why?

Read from memory ~ 1-10μs Read across wire ~ 1-10ms

You cannot abstract such latencies away. (why not?) You must architect around them.

Page 82: The Architect's Two Hats

We can’t ignore ‘wire’ time. We need to make sure programmers think

about it.

Page 83: The Architect's Two Hats

The complexity of shared memory has been moved from the hardware domain to the software domain.

Simple problems like accessing other objects are now more time consuming

Page 84: The Architect's Two Hats

But lets step back a little and look at why we need to distribute processing

Page 85: The Architect's Two Hats

Sum the numbers between 1 and 10,000,000

int totalfor (n =1 to 10,000,000){

total+=n}

A service has a hard limit on how fast it can execute this

Page 86: The Architect's Two Hats

To execute faster: batch for parallel execution

On machine (1)int totalfor (n =1 to 100){

total+=n}

On machine (2)int totalfor (n =101 to 200){

total+=n}

Page 87: The Architect's Two Hats

Leads to concept of Grid Computing

Split work into jobs with the data they need. Send these jobs to n machines for processing.

Page 88: The Architect's Two Hats

Parallel execution on a grid

Server

Grid node

Grid node

Grid node

Grid node

Send code + data

Receive result

Code + data (1)

Code + data (2)

Code + data (3)

Code + data (4)

Processing time is 4 x synchronous case (assuming processing time >> wire time)

Page 89: The Architect's Two Hats

Grid computing solves the processing problem. i.e. we can do complex

computations very quickly by doing them in parallel.

Page 90: The Architect's Two Hats

But it complicates the programming model

Page 91: The Architect's Two Hats

Example: Report Generation

for (Report report : reports){Data data = getDataFromDB(report);format(data);present(data);

}

Page 92: The Architect's Two Hats

... so visually...

Get data DB

Format

Present

Loop For n

Page 93: The Architect's Two Hats

...but on the grid...

Start DB

Format

Present

Loop n times

Grid RunnerAsynchronous

Synchronous

Grid Callback

Grid

Page 94: The Architect's Two Hats

Note how this muddles the design

A simple loop has become a set of distributed invocations and asynchronous call backs.

Page 95: The Architect's Two Hats

Grids allow us to process computations quickly through

parallelism.

But this leads to the problem getting fast enough access to the data we

want to operate on

Page 96: The Architect's Two Hats

Problems With Data Bottlenecks

Data tends to exist in only one place (DB) This is a bottleneck in the architecture In a distributed architecture we must avoid

bottlenecks. Databases often represent one of these.

Page 97: The Architect's Two Hats

Why is the database a bottleneck?

Server

Grid node

Grid node

Grid node

Grid node

Send code

Receive result

Database

Get data

Page 98: The Architect's Two Hats

Databases are slow(ish*)

ACID (Atomic, Consistent, Isolated, Durable) Must write to disk, this is slow. What other options do you have?

Page 99: The Architect's Two Hats

We can scale up by using memory not disk

Memory access is much faster than disk access.

Page 100: The Architect's Two Hats

In memory databases

In memory databases do not have the overhead of writing to disk.

This makes them FAST. However they have drawbacks:

Durability – what happens if the power is cut or the application crashes? Is data consistent?

Scalability of memory: Memory on a single machine Maximum size of a JVM for example is a little over 3GB

(why?)

Page 101: The Architect's Two Hats

But Single Machine Data Stores Don’t Scale, even if they are in memory

Server

Grid node

Grid node

Grid node

Grid node

Send code

Receive result

In Memory Database

Get data

BOTTLENECK

Page 102: The Architect's Two Hats

What we need is a distributed data source?

Welcome to the world of distributed caching

Page 103: The Architect's Two Hats

Distributed Caching Solves This Problem by Splitting The Data Over All

Servers

1/5 data 1/5 data 1/5 data 1/5 data 1/5 data

Client Client Client Client

This is parallel processing for data access. Data requests are split across multiple machines.

Page 104: The Architect's Two Hats

Now we have removed the data bottleneck

Server

Grid node

Grid node

Grid node

Grid node

(1) Send code

(2) Receive result

Data Fabric

1/6

1/6

1/6

1/6

1/6

1/6

Page 105: The Architect's Two Hats

This gives us access to a fast shared memory across multiple machines

Page 106: The Architect's Two Hats

We are now massively parallel

With lightning fast data access.

Page 107: The Architect's Two Hats

But we can get faster than this.How??

Server

Grid node

Grid node

Grid node

Grid node

(1) Send code

(2) Receive result

Data Fabric

1/6

1/6

1/6

1/6

1/6

1/6

Page 108: The Architect's Two Hats

Data Fabric

1/6

1/6

1/6

1/6

1/6

1/6

Superimpose compute and data fabrics into one entity

Server

(1) Send code

(2) Receive result

Page 109: The Architect's Two Hats

So to speed up a system

Load balance services Run compute intensive tasks in parallel on a

grid. Avoid data bottlenecks with distributed caching

Page 110: The Architect's Two Hats

So remember the two hats

Page 111: The Architect's Two Hats

In industry we use Agile methods to evolve the systems design. It does not all happen up front.

We accept change as part of our world and use the patterns Steve has discussed to control it. Separation of Concerns, Interfaces etc.

Page 112: The Architect's Two Hats

But architecting for speed means distributed computing.

Distributed/parallel computing adds significant complexity.

It is hard to factor in later (although not impossible)

Page 113: The Architect's Two Hats

The trick is balancing them!

How much architecture is enough?

Page 114: The Architect's Two Hats

But fundamentally, you need them both!

Page 115: The Architect's Two Hats

Thanks

Slides: http://www.BenStopford.com

Vacation Placements: [email protected]