WebObjects + Scala Building Concurrent WebObjects applications with - - PowerPoint PPT Presentation

webobjects scala
SMART_READER_LITE
LIVE PREVIEW

WebObjects + Scala Building Concurrent WebObjects applications with - - PowerPoint PPT Presentation

WebObjects + Scala Building Concurrent WebObjects applications with Scala Ravi Mendis Why Concurrent Programming? 2005 The year of Dual Core 2010 Today Entry-Level Cores Threads AMD Opteron 4 4 IBM Power7 4 16 Intel Xeon 4 8


slide-1
SLIDE 1

WebObjects + Scala

Building Concurrent WebObjects applications with Scala Ravi Mendis

slide-2
SLIDE 2

Why Concurrent Programming?

slide-3
SLIDE 3

2005

The year of Dual Core

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

2010

Today

slide-7
SLIDE 7

Entry-Level

Cores Threads AMD Opteron IBM Power7 Intel Xeon

4 4 4 16 4 8

slide-8
SLIDE 8

High-End

Cores Threads AMD Opteron IBM Power7 Intel Xeon

12 12 8 32 6 12

slide-9
SLIDE 9

2011

Tomorrow

slide-10
SLIDE 10

Roadmap

Cores Threads AMD Opteron IBM Power7 Intel Xeon

16 16 ? ?? 8 16

slide-11
SLIDE 11

“By 2015 we will likely have over 100 cores on a many- core processing chip in our notebook computers.”

  • Computerworld
slide-12
SLIDE 12

Welcome to the world of Multi-cores!

slide-13
SLIDE 13

Q: How do we take advantage of multi-core processors?

slide-14
SLIDE 14

A: Concurrent Programming

slide-15
SLIDE 15

#1 Threads & Locks

slide-16
SLIDE 16

“Concurrency is hard. It involves a lot of problems that are very difficult to think about and reason about and understand”

  • Tim Bray co-inventor of XML
slide-17
SLIDE 17

#1 Threads & Locks

  • HARD to program
  • HARD to scale
  • Contentious
slide-18
SLIDE 18

java.lang.IllegalArgumentException: Cannot determine primary key for entity ASCCarveout from row: {charge = 3027.00; claimID = 321839138; }

  • at com.webobjects.eoaccess.EODatabaseChannel._fetchObject(EODatabaseChannel.java:348)
  • at com.webobjects.eoaccess.EODatabaseContext._objectsWithFetchSpecificationEditingContext

(EODatabaseContext.java:3071)

  • at com.webobjects.eoaccess.EODatabaseContext.objectsWithFetchSpecification(EODatabaseContext.java:3195)
  • at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsWithFetchSpecification(EOObjectStoreCoordinator.java:

488)

  • at com.webobjects.eocontrol.EOEditingContext.objectsWithFetchSpecification(EOEditingContext.java:4069)
  • at er.extensions.eof.ERXEC.objectsWithFetchSpecification(ERXEC.java:1211)
  • at com.webobjects.eoaccess.EODatabaseContext.objectsForSourceGlobalID(EODatabaseContext.java:4084)
  • at com.webobjects.eocontrol.EOObjectStoreCoordinator.objectsForSourceGlobalID(EOObjectStoreCoordinator.java:

634)

  • at com.webobjects.eocontrol.EOEditingContext.objectsForSourceGlobalID(EOEditingContext.java:3923)
  • at er.extensions.eof.ERXEC.objectsForSourceGlobalID(ERXEC.java:1169)
  • at com.webobjects.eoaccess.EODatabaseContext._fireArrayFault(EODatabaseContext.java:4245)
  • at com.webobjects.eoaccess.EOAccessArrayFaultHandler.completeInitializationOfObject

(EOAccessArrayFaultHandler.java:77)

  • at com.webobjects.eocontrol._EOCheapCopyMutableArray.willRead(_EOCheapCopyMutableArray.java:37)
  • at com.webobjects.eocontrol._EOCheapCopyMutableArray.count(_EOCheapCopyMutableArray.java:86)
  • at com.mpv.evaluation.ClaimEvaluator.validateClaim(ClaimEvaluator.java:398)
  • ...

...Deadlock!

slide-19
SLIDE 19

BBC2, Top Gear - Series 15, Episode 1 - June 27 ’10

slide-20
SLIDE 20

#2 Actor Model

(A Share NOTHING Model)

slide-21
SLIDE 21

Slowmation

slide-22
SLIDE 22

Demo

slide-23
SLIDE 23

html5 <video>

<video poster="/slowmation/screenshots/0/2/4/425.jpg">

  • <source type="video/ogg" src="/slowmation/videos/6/d/8/423.ogg" />
  • <source type="video/mp4" src="/slowmation/videos/d/6/4/424.mp4" />

</video>

slide-24
SLIDE 24

HTML5 Video Conversion

Screenshot (.jpg) Video (.mp4)

Video (.ogg)

Thumbnail (.jpg)

slide-25
SLIDE 25
  • actor ! THUMBNAIL
  • actor ! GRAB
  • actor ! CONVERT2H264
  • actor ! CONVERT2OGG

Slowmation Actor

(Video Processor)

slide-26
SLIDE 26

!

slide-27
SLIDE 27

Actor Messaging

  • Asynchronous
  • Non-blocking
  • Immutable Messages
  • NO shared data
slide-28
SLIDE 28

Scala

slide-29
SLIDE 29
  • Immutable/Mutable datatypes
  • Anonymous Functions (~Closures)
  • No Static variables and methods
  • Extensible

Scala

slide-30
SLIDE 30

Scala

val greeting: String = “Hello World”;

slide-31
SLIDE 31

Scala

val greeting = “Hello World”;

slide-32
SLIDE 32

Scala

val greeting = “Hello World”

slide-33
SLIDE 33

Scala

val greeting = “Hello World” // immutable var response = new String() // mutable response = “Hey!”

slide-34
SLIDE 34

Java - Static Vars

public class _Talent extends EOGenericRecord { public static final String ENTITY_NAME = "Talent"; }

slide-35
SLIDE 35

Scala - Companion Object

  • bject Talent extends EOGenericRecord {

val ENTITY_NAME = "Talent" }

slide-36
SLIDE 36

Thread-Safe

slide-37
SLIDE 37

Scala - Pattern Matching

case a => { ... }

slide-38
SLIDE 38

Scala - Pattern Matching

try { var epi: EditPageInterface = D2W.factory.editPageForNewObjectWithEntityNamed(entityName, session) } catch { case e: IllegalArgumentException => { var epf: ErrorPageInterface = D2W.factory.errorPage(session) epf.setMessage(e.toString) } }

slide-39
SLIDE 39

Scala - Case Classes

case class PING case class PONG

slide-40
SLIDE 40

Scala - Case Classes

actor ! PING actor ! PONG

slide-41
SLIDE 41

Scala - Case Classes

case PING => { ... } case PONG => { ... }

slide-42
SLIDE 42

Scala - Anonymous Functions

x => x^2

slide-43
SLIDE 43

Scala - Anonymous Functions

x, y => x + y

slide-44
SLIDE 44

Scala - Anonymous Functions

x, y => {x + y}

slide-45
SLIDE 45

Scala - Anonymous Functions

case (PING => {...}) case (PONG => {...})

slide-46
SLIDE 46

λ - Expressions

slide-47
SLIDE 47

Scala Actors - Example

case class THUMBNAIL(filepath: String) // Actor msg case class val processor = actor { loop { react() { case THUMBNAIL(filepath: String) => { ... } } } } // asynchronous processor ! THUMBNAIL(“/Library/WebServer/Documents/slowmation/screenshots/0/2/4/422.jpg”)

slide-48
SLIDE 48

#2 Actor Model

  • EASY to program
  • Scalable
  • NO Deadlocks!
slide-49
SLIDE 49

Q: Why can Scala be used with WebObjects?

slide-50
SLIDE 50

A: Scala compiles to Java Byte-code

slide-51
SLIDE 51

WebObjects + Concurrency

slide-52
SLIDE 52

Why?

slide-53
SLIDE 53

Performance

  • Exploit multi-core processors
slide-54
SLIDE 54

Ajax

  • More responsive UI
slide-55
SLIDE 55

How?

slide-56
SLIDE 56

Properties

WOAllowsConcurrentRequestHandling=true

slide-57
SLIDE 57

Java - Synchronize Static Variables

private static String greeting = “Hello”; // private public void setGreeting(String aGreeting) { synchronized(greeting) { // synchronized block greeting = aGreeting; } }

slide-58
SLIDE 58

Free!

slide-59
SLIDE 59

WO - What is Shared?

  • Application
  • Session (concurrent WO)
slide-60
SLIDE 60

Use ERXEC

  • Project Wonder
  • Automatic lock/unlock handling
slide-61
SLIDE 61

Properties

er.extensions.ERXEC.safeLocking=true

slide-62
SLIDE 62

Debugging

slide-63
SLIDE 63

Demo

slide-64
SLIDE 64

Properties

  • Dcom.sun.management.jmxremote=true
  • Dcom.sun.management.jmxremote.authenticate=false
  • Dcom.sun.management.jmxremote.ssl=false

// Specific port

  • Dcom.sun.management.jmxremote.port=20102
slide-65
SLIDE 65

Bottlenecks

slide-66
SLIDE 66
  • Shared Object-cache
  • Antithesis to Share Nothing

model

  • Uses single database connection
  • Single-Threaded

EOF - Bottleneck

slide-67
SLIDE 67

#3 STM

(Software Transactional Memory)

slide-68
SLIDE 68
  • DOESN’T work in Scala Actors!
  • EOF + Scala
slide-69
SLIDE 69
  • Use Raw SQL
  • Alternative database access
  • Squeryl
  • ...

Solutions

slide-70
SLIDE 70

Squeryl

slide-71
SLIDE 71

Demo

slide-72
SLIDE 72

Squeryl

  • POSOs
  • Actor Compatible
  • Concurrent
slide-73
SLIDE 73

“Scala as a concurrent programming language is powerful, safe and easy-to-use”

slide-74
SLIDE 74

Benchmarks

slide-75
SLIDE 75
  • ERWOAdaptor (Mina)
  • WO Worker as Actor
  • Apache bench
  • c = 5...65
  • n = 500

The Test

slide-76
SLIDE 76

Results

slide-77
SLIDE 77

Time per req. (mean)

0 ms 50 ms 100 ms 150 ms 200 ms 5 10 15 20 25 30 35 40 45 50 55 60 65

WOAdaptor ERWOScalaAdaptor ERWOAdaptor

slide-78
SLIDE 78

Requests per second

200 400 600 800 5 10 15 20 25 30 35 40 45 50 55 60 65

WOAdaptor ERWOScalaAdaptor ERWOAdaptor

slide-79
SLIDE 79

“Scala as a concurrent programming language is powerful, safe and easy-to-use”

slide-80
SLIDE 80

In life long love The key Is R&D The ladder of invention Has eternal slide extension Rung by rung You’ll climb to heaven above. Constant innovation Guarantees a satiation Of that ever changing want And deepening need Nourishment and care To think anew… Makes passions flair And lets a culture breed Between the sheets…

  • by Emma Ahmad

The R&D Imperative

slide-81
SLIDE 81

Q&A

slide-82
SLIDE 82
  • What will

YOU do with 100 cores?

http://www.computerworld.com.au/article/354261/

  • WebObjects with Scala

http://wiki.objectstyle.org/confluence/display/WO/WebObjects+with+Scala

  • Case Study: Slowmation

http://slowmation.uow.edu.au

  • Source: ERWOScalaAdaptor

http://services.wocommunity.org/wowodc/ERWOScalaAdaptor

References