The tale of the Fénix architecture

Post on 17-May-2015

1.478 views 0 download

Tags:

description

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

Transcript of The tale of the Fénix architecture

The tale of the Fenix architecture

Narrated by Joao Cachopo

12.000 students

1.000 teachers

700 admin staff

12.000 students

1.000 teachers

700 admin staff

12.000 students

1.000 teachers

700 admin staff

12.000 students

1.000 teachers

700 admin staff

Fenix Team Size

2001

72002

172003

262004

232005

242006

142007

122008

11

Fenix needed an appropriate

Software Architecture

The first architecture of Fenix

BrowserWeb Server

HTTP

Browser Web Server Database

HTTP SQL

Load Balancer

Web server

Web server architecture

Data Access

Domain

Presentation Logic

Anemic DomainData Access

Services

Presentation Logic

Anemic DomainData Access

ViewsServices

Presentation Logic

Anemic DomainData Access

ViewsServices

JSPs + Struts + Tiles

Anemic DomainOJB + DAOs

ViewsServices

JSPs + Struts + Tiles

Services ∼ Transaction Scripts

The architecture was the law!

Students worked independently

The architecture was the law!

It worked great!

The system grew quickly

Yet, developers had lots of work. . .

It worked great!

The system grew quickly

Yet, developers had lots of work. . .

This architecture is still actual

s/OJB/Hibernate/

s/Struts/JSF/

This architecture is still actual

s/OJB/Hibernate/

s/Struts/JSF/

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

By 2003. . .

Performance problems

Domain inconsistencies

Slow development

How to solve these?

Avoiding the PhD. . .

The second architecture of Fenix

Goals

Simplify development

Better performance

Why the performance problems?

Browser Web Server Database

HTTP SQL

Latency �

Browser Web Server Database

HTTP SQL

Latency Latency�

Fenix has a Rich Domain Model!

Rich Domain Models

Many classes

Many relationships

Complex behaviors

Fenix Domain Model in 2003

∼ 230 domain classes

∼ 700 services

Browser Web Server Database

HTTP SQL

Latency Latency�

Browser Web Server Database

HTTP SQL

Latency 1000 × Latency�

Browser Web Server Database

HTTP SQL

Latency 1000 × Latency�

DAOs may help

Teacher readTeacherByUsername(String username);

ExecDegree readByDegreeInitialsAndNameDegreeCurricularPlanAndExecutionYear(...);

DAOs may help

Teacher readTeacherByUsername(String username);

ExecDegree readByDegreeInitialsAndNameDegreeCurricularPlanAndExecutionYear(...);

Today?

Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Today? Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Today? Named queries

Maintenance nightmare

Does not leverage on OOP

Lots of work

Assumptions

OOP is the right thingTM

We have lots of memory

Much more reads than writes

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Anemic DomainOJB + DAOs

ViewsServices

Presentation Logic

Rich Domain Model

Presentation Logic

DML + Java + JVSTM

Presentation Logic

DML Compiler + JVSTM

DML + Java

Presentation Logic

Fenix Framework

DML + Java

Presentation Logic

Fenix Framework

Application Domain

Presentation Logic

Fenix Framework

Application Domain

Presentation Logic

Fenix Framework

Fenix Application

Fenix Framework

DML Compiler + JVSTM

What do we get?

Persistent

Transactional

A pure OO domain model

Persistent

Transactional

A pure OO domain model

Persistent

Transactional

A pure OO domain model

Persistent

Transactional

Browser Web Server Database

HTTP SQL

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

SQL

Domain Logic

Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

SQL

Domain Logic Durability

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

Atomicity

Isolation

Consistency

How?

Multi

-thre

aded

Java Versioned

Software Transactional Memory

Java Versioned

Software Transactional Memory

Concurrent programming

Locks?

Transactions

Atomicity

Isolation

Concurrent programming

Locks? Transactions

Atomicity

Isolation

Concurrent programming

Locks? Transactions

Atomicity

Isolation

One entity/JVM

Strict serializability

Reads never fail

SQL

Only for writes!

First/second level cache?

Optimistic locking?

Implementing a domain model

Domain classes are special. . .

Domain model

=

Structure + Constraints + Processes

Structure

=

Values + Entities + Associations

In Java?

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

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!");

}}

}

name

Client

balance

Accountowner

1..1

accounts

0..*owns

class Client {

private String name;

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

}

public String getName() {return name;

}}

class Client {

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

}

@Entityclass Client {

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

@Versionprivate Long objVersion;

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

}

What about bi-directionality?

C1 A1

C2A2

C1 A1

C2

A2

C1 A1

C2A2

With the DML

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

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

}

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

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

}

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

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

}

valueType Money;

class Client {String name;

}

class Account {Money balance;

}

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

}

class A {...

}

A

...

AState

DML Compiler

Semantics?

Persistent

Transactional

Bi-directional

Using the Fenix Framework

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

}};

FenixFramework.initialize(config);

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

}};

FenixFramework.initialize(config);

Fenix domain

Sep

2005

Dec

2005

Mar

2006

Jun

2006

Sep

2006

Dec

2006

Mar

2007

Jun

2007

0

227324

704

1098

# classes

# associations

Fenix transactional workload

Writes ∼ 1%

Conflicts ∼ 1%

Some txs > 10.000.000 reads

readswrites > 1.000

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

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

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

Preliminary results

Client/Account example

FF throughput = 30 × Hibernate

The future?

Thank you.

Q & A