the tale of the fénix architecture

174
The tale of the F´ enix architecture Narrated by Jo˜ ao Cachopo

Upload: ptjug

Post on 17-May-2015

1.479 views

Category:

Technology


0 download

DESCRIPTION

Apresentação de João Cachopo - 2º encontro PT.JUG.

TRANSCRIPT

Page 1: The tale of the Fénix architecture

The tale of the Fenix architecture

Narrated by Joao Cachopo

Page 2: The tale of the Fénix architecture
Page 3: The tale of the Fénix architecture
Page 4: The tale of the Fénix architecture
Page 5: The tale of the Fénix architecture
Page 6: The tale of the Fénix architecture
Page 7: The tale of the Fénix architecture
Page 8: The tale of the Fénix architecture
Page 9: The tale of the Fénix architecture
Page 10: The tale of the Fénix architecture
Page 11: The tale of the Fénix architecture
Page 12: The tale of the Fénix architecture
Page 13: The tale of the Fénix architecture
Page 14: The tale of the Fénix architecture
Page 15: The tale of the Fénix architecture
Page 16: The tale of the Fénix architecture
Page 17: The tale of the Fénix architecture
Page 18: The tale of the Fénix architecture
Page 19: The tale of the Fénix architecture
Page 20: The tale of the Fénix architecture
Page 21: The tale of the Fénix architecture
Page 22: The tale of the Fénix architecture
Page 23: The tale of the Fénix architecture
Page 24: The tale of the Fénix architecture
Page 25: The tale of the Fénix architecture
Page 26: The tale of the Fénix architecture
Page 27: The tale of the Fénix architecture
Page 28: The tale of the Fénix architecture
Page 29: The tale of the Fénix architecture
Page 30: The tale of the Fénix architecture

12.000 students

1.000 teachers

700 admin staff

Page 31: The tale of the Fénix architecture

12.000 students

1.000 teachers

700 admin staff

Page 32: The tale of the Fénix architecture

12.000 students

1.000 teachers

700 admin staff

Page 33: The tale of the Fénix architecture

12.000 students

1.000 teachers

700 admin staff

Page 34: The tale of the Fénix architecture

Fenix Team Size

2001

72002

172003

262004

232005

242006

142007

122008

11

Page 35: The tale of the Fénix architecture

Fenix needed an appropriate

Software Architecture

Page 36: The tale of the Fénix architecture
Page 37: The tale of the Fénix architecture
Page 38: The tale of the Fénix architecture
Page 39: The tale of the Fénix architecture

The first architecture of Fenix

Page 40: The tale of the Fénix architecture

BrowserWeb Server

HTTP

Page 41: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Page 42: The tale of the Fénix architecture

Load Balancer

Page 43: The tale of the Fénix architecture
Page 44: The tale of the Fénix architecture
Page 45: The tale of the Fénix architecture
Page 46: The tale of the Fénix architecture

Web server

Page 47: The tale of the Fénix architecture

Web server architecture

Page 48: The tale of the Fénix architecture

Data Access

Domain

Presentation Logic

Page 49: The tale of the Fénix architecture

Anemic DomainData Access

Services

Presentation Logic

Page 50: The tale of the Fénix architecture

Anemic DomainData Access

ViewsServices

Presentation Logic

Page 51: The tale of the Fénix architecture

Anemic DomainData Access

ViewsServices

JSPs + Struts + Tiles

Page 52: The tale of the Fénix architecture

Anemic DomainOJB + DAOs

ViewsServices

JSPs + Struts + Tiles

Page 53: The tale of the Fénix architecture

Services ∼ Transaction Scripts

The architecture was the law!

Page 54: The tale of the Fénix architecture

Students worked independently

The architecture was the law!

Page 55: The tale of the Fénix architecture
Page 56: The tale of the Fénix architecture
Page 57: The tale of the Fénix architecture
Page 58: The tale of the Fénix architecture

It worked great!

The system grew quickly

Yet, developers had lots of work. . .

Page 59: The tale of the Fénix architecture

It worked great!

The system grew quickly

Yet, developers had lots of work. . .

Page 60: The tale of the Fénix architecture
Page 61: The tale of the Fénix architecture
Page 62: The tale of the Fénix architecture

This architecture is still actual

s/OJB/Hibernate/

s/Struts/JSF/

Page 63: The tale of the Fénix architecture

This architecture is still actual

s/OJB/Hibernate/

s/Struts/JSF/

Page 64: The tale of the Fénix architecture
Page 65: The tale of the Fénix architecture
Page 66: The tale of the Fénix architecture
Page 67: The tale of the Fénix architecture

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

Page 68: The tale of the Fénix architecture

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

Page 69: The tale of the Fénix architecture

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

Page 70: The tale of the Fénix architecture

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

Page 71: The tale of the Fénix architecture

How to solve these?

Page 72: The tale of the Fénix architecture

Avoiding the PhD. . .

Page 73: The tale of the Fénix architecture
Page 74: The tale of the Fénix architecture
Page 75: The tale of the Fénix architecture
Page 76: The tale of the Fénix architecture
Page 77: The tale of the Fénix architecture

The second architecture of Fenix

Page 78: The tale of the Fénix architecture

Goals

Simplify development

Better performance

Page 79: The tale of the Fénix architecture

Why the performance problems?

Page 80: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Latency �

Page 81: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Latency Latency�

Page 82: The tale of the Fénix architecture

Fenix has a Rich Domain Model!

Page 83: The tale of the Fénix architecture

Rich Domain Models

Many classes

Many relationships

Complex behaviors

Page 84: The tale of the Fénix architecture

Fenix Domain Model in 2003

∼ 230 domain classes

∼ 700 services

Page 85: The tale of the Fénix architecture
Page 86: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Latency Latency�

Page 87: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Latency 1000 × Latency�

Page 88: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Latency 1000 × Latency�

Page 89: The tale of the Fénix architecture
Page 90: The tale of the Fénix architecture

DAOs may help

Teacher readTeacherByUsername(String username);

ExecDegree readByDegreeInitialsAndNameDegreeCurricularPlanAndExecutionYear(...);

Page 91: The tale of the Fénix architecture

DAOs may help

Teacher readTeacherByUsername(String username);

ExecDegree readByDegreeInitialsAndNameDegreeCurricularPlanAndExecutionYear(...);

Page 92: The tale of the Fénix architecture

Today?

Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Page 93: The tale of the Fénix architecture

Today? Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Page 94: The tale of the Fénix architecture

Today? Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Page 95: The tale of the Fénix architecture
Page 96: The tale of the Fénix architecture
Page 97: The tale of the Fénix architecture
Page 98: The tale of the Fénix architecture

Assumptions

Page 99: The tale of the Fénix architecture

OOP is the right thingTM

Page 100: The tale of the Fénix architecture

We have lots of memory

Page 101: The tale of the Fénix architecture

Much more reads than writes

Page 102: The tale of the Fénix architecture

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Page 103: The tale of the Fénix architecture

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Page 104: The tale of the Fénix architecture

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Page 105: The tale of the Fénix architecture

Rich Domain Model

Presentation Logic

Page 106: The tale of the Fénix architecture

DML + Java + JVSTM

Presentation Logic

Page 107: The tale of the Fénix architecture

DML Compiler + JVSTM

DML + Java

Presentation Logic

Page 108: The tale of the Fénix architecture

Fenix Framework

DML + Java

Presentation Logic

Page 109: The tale of the Fénix architecture

Fenix Framework

Application Domain

Presentation Logic

Page 110: The tale of the Fénix architecture

Fenix Framework

Application Domain

Presentation Logic

Page 111: The tale of the Fénix architecture

Fenix Framework

Fenix Application

Page 112: The tale of the Fénix architecture

Fenix Framework

Page 113: The tale of the Fénix architecture

DML Compiler + JVSTM

Page 114: The tale of the Fénix architecture

What do we get?

Persistent

Transactional

Page 115: The tale of the Fénix architecture

A pure OO domain model

Persistent

Transactional

Page 116: The tale of the Fénix architecture

A pure OO domain model

Persistent

Transactional

Page 117: The tale of the Fénix architecture

A pure OO domain model

Persistent

Transactional

Page 118: The tale of the Fénix architecture

Browser Web Server Database

HTTP SQL

Page 119: The tale of the Fénix architecture

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Page 120: The tale of the Fénix architecture

SQL

Domain Logic

Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Page 121: The tale of the Fénix architecture

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Page 122: The tale of the Fénix architecture

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Page 123: The tale of the Fénix architecture

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

How?

Page 124: The tale of the Fénix architecture
Page 125: The tale of the Fénix architecture

Multi

-thre

aded

Page 126: The tale of the Fénix architecture
Page 127: The tale of the Fénix architecture

Java Versioned

Software Transactional Memory

Page 128: The tale of the Fénix architecture

Java Versioned

Software Transactional Memory

Page 129: The tale of the Fénix architecture

Concurrent programming

Locks?

Transactions

Atomicity

Isolation

Page 130: The tale of the Fénix architecture

Concurrent programming

Locks? Transactions

Atomicity

Isolation

Page 131: The tale of the Fénix architecture

Concurrent programming

Locks? Transactions

Atomicity

Isolation

Page 132: The tale of the Fénix architecture

One entity/JVM

Strict serializability

Reads never fail

Page 133: The tale of the Fénix architecture

SQL

Only for writes!

Page 134: The tale of the Fénix architecture

First/second level cache?

Page 135: The tale of the Fénix architecture

Optimistic locking?

Page 136: The tale of the Fénix architecture

Implementing a domain model

Page 137: The tale of the Fénix architecture

Domain classes are special. . .

Page 138: The tale of the Fénix architecture

Domain model

=

Structure + Constraints + Processes

Page 139: The tale of the Fénix architecture

Structure

=

Values + Entities + Associations

Page 140: The tale of the Fénix architecture

In Java?

Page 141: The tale of the Fénix architecture

0: aload_01: arraylength2: ifle 535: aload_06: astore_17: aload_18: arraylength9: istore_210: iconst_011: istore_312: iload_313: iload_214: if_icmpge 4417: aload_118: iload_319: aaload

20: astore 422: getstatic #2;25: aload 427: invokevirtual #3;30: getstatic #2;33: ldc #4;35: invokevirtual #3;38: iinc 3, 141: goto 1244: getstatic #2;47: invokevirtual #5;50: goto 6153: getstatic #2;56: ldc #6;58: invokevirtual #7;61: return

Page 142: The tale of the Fénix architecture

public class Echo {public static void main(String[] args) {if (args.length > 0) {for (String arg : args) {System.out.print(arg);System.out.print(" ");

}System.out.println();

} else {System.out.println("Sorry, nothing to echo!");

}}

}

Page 143: The tale of the Fénix architecture
Page 144: The tale of the Fénix architecture
Page 145: The tale of the Fénix architecture

name

Client

balance

Accountowner

1..1

accounts

0..*owns

Page 146: The tale of the Fénix architecture

class Client {

private String name;

public Client(String name) {this.name = name;

}

public String getName() {return name;

}}

Page 147: The tale of the Fénix architecture

class Client {

Set<Account> accounts = new HashSet<Account>();

}

Page 148: The tale of the Fénix architecture

@Entityclass Client {

@Id@GeneratedValue(strategy=GenerationType.AUTO)private Long id;

@Versionprivate Long objVersion;

@OneToMany(mappedBy = "owner")Set<Account> accounts = new HashSet<Account>();

}

Page 149: The tale of the Fénix architecture

What about bi-directionality?

Page 150: The tale of the Fénix architecture

C1 A1

C2A2

Page 151: The tale of the Fénix architecture

C1 A1

C2

A2

Page 152: The tale of the Fénix architecture

C1 A1

C2A2

Page 153: The tale of the Fénix architecture
Page 154: The tale of the Fénix architecture
Page 155: The tale of the Fénix architecture

With the DML

Page 156: The tale of the Fénix architecture

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

relation Owns {Client playsRole owner { multiplicity 1..1; }Account playsRole account { multiplicity 0..*; }

}

Page 157: The tale of the Fénix architecture

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

relation Owns {Client playsRole owner { multiplicity 1..1; }Account playsRole account { multiplicity 0..*; }

}

Page 158: The tale of the Fénix architecture

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

relation Owns {Client playsRole owner { multiplicity 1..1; }Account playsRole account { multiplicity 0..*; }

}

Page 159: The tale of the Fénix architecture

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

relation Owns {Client playsRole owner { multiplicity 1..1; }Account playsRole account { multiplicity 0..*; }

}

Page 160: The tale of the Fénix architecture

class A {...

}

A

...

AState

DML Compiler

Page 161: The tale of the Fénix architecture

Semantics?

Persistent

Transactional

Bi-directional

Page 162: The tale of the Fénix architecture

Using the Fenix Framework

Page 163: The tale of the Fénix architecture

Config config = new Config() {{domainModelPath = "/bank.dml";dbAlias = "//localhost:3306/ff-bank";dbUsername = "test";dbPassword = "test";

}};

FenixFramework.initialize(config);

Page 164: The tale of the Fénix architecture

Config config = new Config() {{domainModelPath = "/bank.dml";dbAlias = "//localhost:3306/ff-bank";dbUsername = "test";dbPassword = "test";

}};

FenixFramework.initialize(config);

Page 165: The tale of the Fénix architecture

Fenix domain

Sep

2005

Dec

2005

Mar

2006

Jun

2006

Sep

2006

Dec

2006

Mar

2007

Jun

2007

0

227324

704

1098

# classes

# associations

Page 166: The tale of the Fénix architecture

Fenix transactional workload

Writes ∼ 1%

Conflicts ∼ 1%

Some txs > 10.000.000 reads

readswrites > 1.000

Page 167: The tale of the Fénix architecture

Total transactions

Oct

2006

Nov

2006

Dec

2006

Jan

2007

Feb

2007

Mar

2007

Apr

2007

May

2007

Jun

2007

0

6969741

13939482

20909223

27878965

Page 168: The tale of the Fénix architecture

Daily txs in February

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 280

666473

1332946

1999419

2665893

Page 169: The tale of the Fénix architecture

The enrollment’s day

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 240

131039

262078

393117

524157

Page 170: The tale of the Fénix architecture

Preliminary results

Client/Account example

FF throughput = 30 × Hibernate

Page 171: The tale of the Fénix architecture

The future?

Page 172: The tale of the Fénix architecture
Page 173: The tale of the Fénix architecture
Page 174: The tale of the Fénix architecture

Thank you.

Q & A