caf - the c++ actor framework for scalable and …...2014/10/16  · caf - the c++ actor framework...

29
CAF - The C++ Actor Framework for Scalable and Resource-ecient Applications Dominik Charousset , Raphael Hiesgen, and Thomas C. Schmidt {dominik.charousset,raphael.hiesgen,t.schmidt}@haw-hamburg.de Dept. Computer Science Hamburg University of Applied Sciences Germany October 2014, AGERE!@SPLASH

Upload: others

Post on 21-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

CAF - The C++ Actor Framework for

Scalable and Resource-efficient Applications

Dominik Charousset, Raphael Hiesgen, and Thomas C. Schmidt{dominik.charousset,raphael.hiesgen,t.schmidt}@haw-hamburg.de

Dept. Computer ScienceHamburg University of Applied Sciences

Germany

October 2014, AGERE!@SPLASH

Page 2: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Previous Work

Implemented native actor library libcppa actor library in C++Target at both high-performance and embedded environmentsAllow millions of lightweight actors

Extended the actor model with publish/subscribe semanticsOriginal actor model only foresees 1:1 communicationInternet scale requires loose coupling

Support heterogeneous hardware componentsGPUs can outperform CPUs by orders of magnitudeTransparent integration of OpenCL allows flexible deployment

Dominik Charousset iNET – HAW Hamburg 2

Page 3: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Rebranding & Modularization

Our approach to a growing userbase with diverse requirements:Move from a monolithic library to an open frameworkSplit functionality into (optional) modulesEnable customization via extensible framework structureCentral project homepage1 linking to all activities

1http://actor-framework.org

Dominik Charousset iNET – HAW Hamburg 3

Page 4: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Agenda

1 Type-safe Message Passing

2 Scheduling Infrastructure

3 Runtime Inspection & Debugging

4 Conclusion & Outlook

Dominik Charousset iNET – HAW Hamburg 4

Page 5: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Agenda

1 Type-safe Message Passing

2 Scheduling Infrastructure

3 Runtime Inspection & Debugging

4 Conclusion & Outlook

Dominik Charousset iNET – HAW Hamburg 5

Page 6: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Problem of Dynamic Typing

The original model2 defines actors in terms of(Untyped) message passing primitivesPattern matching

) Extensive integration testing requiredCoding errors occur at runtimeNon-local dependencies are hard to track manually

2Carl Hewitt, Peter Bishop, and Richard Steiger. A Universal Modular ACTOR Formalism for ArtificialIntelligence.In Proceedings of the 3rd IJCAI, pages 235–245, San Francisco, CA, USA, 1973. Morgan KaufmannPublishers Inc.

Dominik Charousset iNET – HAW Hamburg 6

Page 7: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Type-safe Message Passing

Lift type system of C++ and make it applicable to actor interfacesCompiler statically checks protocols between actorsProtocol violation cannot occur at runtimeCompiler verifies both incoming and outgoing messages:using math =

typed_actor <

replies_to <int , int >::with <int >,

replies_to <float >::with <float , float >>;

// ...

auto ms = typed_spawn (...);

sync_send(ms, 10, 20). then(

[]( float result) {

// compiler error: result is int , not float

}

);

Dominik Charousset iNET – HAW Hamburg 7

Page 8: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Agenda

1 Type-safe Message Passing

2 Scheduling Infrastructure

3 Runtime Inspection & Debugging

4 Conclusion & Outlook

Dominik Charousset iNET – HAW Hamburg 8

Page 9: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Scalability of Scheduling

CAF aims at scaling to millions of actors on hundreds of processorsActors cannot be implemented (efficiently) as threadsRunning in userspace prohibits preemptionClassical thread pool or centralized scheduler has limitations

Central job queue is a bottleneck per seShort-lived tasks cause significant runtime overheadCould schedule actors for real-time with a priori knowledge 3

3M.L. Dertouzos and AK. Mok. Multiprocessor Online Scheduling of Hard-Real-Time Tasks.Software Engineering, IEEE Transactions on, 15(12):1497–1506, Dec 1989

Dominik Charousset iNET – HAW Hamburg 9

Page 10: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Centralized Scheduling Issue

Divide & conquer: 220 actors with libcppa (central scheduling, 2013)

2 4 6 8 10 120

5

10

15

20

25

Tim

e [s

]

Number of Cores [#]

libcppa scala erlang

libcppa reached maximum performance on 8 cores for divide & conquer algorithms

Dominik Charousset iNET – HAW Hamburg 10

Page 11: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Scheduling Approaches

Active dispatchingCentral task managementOne (or more) threads manage othersHigh communication overhead

Shared work queuesReactive task managementWorkers access one (or more) shared queuesFrequent access to shared data is a likely performance bottleneck

Individual work queuesDecentralized, reactive task managementWorkers communicate only when idleMinimizes synchronizations between threads

Dominik Charousset iNET – HAW Hamburg 11

Page 12: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Work Stealing

Decentralized scheduling using Work Stealing4

One job queue and worker per coreWorker tries stealing work items from others when idleStealing is a rare event for most work loads5

But: A priori knowledge cannot be exploited (no global view)

4Robert D. Blumofe and Charles E. Leiserson. Scheduling Multithreaded Computations by Work Stealing.J. ACM, 46(5):720–748, September 1999.5Vivek Kumar, Daniel Frampton, Stephen M. Blackburn, David Grove, and Olivier Tardieu. Work-stealingWithout the Baggage.In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languagesand Applications, OOPSLA ’12, pages 297–314, New York, NY, USA, 2012. ACM.

Dominik Charousset iNET – HAW Hamburg 12

Page 13: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Work Stealing

VictimWorker 1

ThiefWorker 2 Worker P

Queue 1 Queue 2 Queue P

Job 1

Job 2

Job 3

Job N

Job 3

Steal

Dominik Charousset iNET – HAW Hamburg 13

Page 14: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Configurable Scheduling in CAF

Framework has no a priori knowledge ! Work Stealing as defaultUsing Work Stealing, CAF scales up to at least 64 coresDevelopers can deploy custom scheduler usingtemplate <class Policy = work_stealing >

void set_scheduler(size_t num_workers = ...,

size_t max_msgs = indefinite );

max_msgs restricts # of messages actors can consume at onceLow value increases fairness and avoids burstsHigh value minimizes queue access, usually maximizing throughput

Policy can be implemented to exploit a priori knowledge, if possible

Dominik Charousset iNET – HAW Hamburg 14

Page 15: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Scheduling Infrastructure

Divide & conquer: 220 actors with CAF

4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 640

5

10

15

20

25 ActorFoundry CAF Charm Erlang Scala

Tim

e [s

]

Number of Cores [#]Dominik Charousset iNET – HAW Hamburg 15

Page 16: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Scheduling Infrastructure

Mixed operations under work load with CAF

4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 640

50

100

150

200

250

300

350

ActorFoundry CAF Charm Erlang ScalaTi

me

[s]

Number of Cores [#]Dominik Charousset iNET – HAW Hamburg 16

Page 17: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Agenda

1 Type-safe Message Passing

2 Scheduling Infrastructure

3 Runtime Inspection & Debugging

4 Conclusion & Outlook

Dominik Charousset iNET – HAW Hamburg 17

Page 18: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Debugging of distributed systems is inherently complexNon-trivial program flowNo global clockDiverging states

Recording messages crucial for on-line or post-mortem debuggingErroneous behavior can be reproduced using message replaying 6

Visualization tools can help understanding complex errors 7

6Dennis Michael Geels, Gautam Altekar, Scott Shenker, and Ion Stoica. Replay debugging for distributedapplications.In Proc. of USENIX’06 Ann. Tech. Conf., pages 289–300. USENIX Assoc., 2006.7Terry Stanley, Tyler Close, and Mark S Miller. Causeway: A message-oriented distributed debugger.Technical Report HPL-2009-78, HP Laboratories, 2009.

Dominik Charousset iNET – HAW Hamburg 18

Page 19: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Nexus

Frontend(e.g. shell)

Node AP1

……

Node NPN

actorA

actorB

actorC

actorD

Dominik Charousset iNET – HAW Hamburg 19

Page 20: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Nexus

Frontend(e.g. shell)

Node AP1

……

Node NPN

actorA

actorB

actorC

actorD

Dominik Charousset iNET – HAW Hamburg 20

Page 21: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Nexus

Frontend(e.g. shell)

Node AP1

……

Node NPN

actorA

actorB

actorC

actorD

P1 … PN

ProbesIntercept & forward three kinds of messages to the Nexus:

Activity events: incoming & outgoing messagesError events: network & system failuresRuntime statistics: periodic collection of CPU load, etc.

Dominik Charousset iNET – HAW Hamburg 21

Page 22: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Nexus

Frontend(e.g. shell)

Node AP1

……

Node NPN

actorA

actorB

actorC

actorD

Nexus

The NexusProvides global view of the distributed systemReceives & collects events from ProbesStatefully configures verbosity of Probes

Dominik Charousset iNET – HAW Hamburg 22

Page 23: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Runtime Inspection & Debugging

Nexus

Frontend(e.g. shell)

Node AP1

……

Node NPN

actorA

actorB

actorC

actorD

Frontend(e.g. shell)

Frontend application categoriesObserving agents: monitoring & threshold-based alertsSupervising agents: active manipulation of running app.Monitoring & visualization: access to aggregate state) For instance, an interactive inspection shell

Dominik Charousset iNET – HAW Hamburg 23

Page 24: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Interactive Inspection Shell

Allows users to inspect distributed systemIn global mode:

Global view to the systemAccess to individual participating nodes

In node mode:Access to statistics such as RAM usage, CPU load, etc.Direct interaction with actors on that node

Dominik Charousset iNET – HAW Hamburg 24

Page 25: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Agenda

1 Type-safe Message Passing

2 Scheduling Infrastructure

3 Runtime Inspection & Debugging

4 Conclusion & Outlook

Dominik Charousset iNET – HAW Hamburg 25

Page 26: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Conclusion

CAF is a robust, scalable platform for native actor programmingStrong emphasis on low mem. footprint and performanceType-safe messaging interfacesOpen scheduling infrastructure with efficient defaultFirst step towards debugging distributed actors

Dominik Charousset iNET – HAW Hamburg 26

Page 27: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Outlook

Scale down to IoT devices (port CAF to RIOT-OS8)Load balancing for massively parallel, distributed systemsMonitoring and debugging tools based on current platformRobust security layer for the IoT: subsuming strong authenticationof actors in combination with opportunistic encryption

8http://riot-os.org

Dominik Charousset iNET – HAW Hamburg 27

Page 28: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

Thank you for your attention!

Homepage: http://actor-framework.org

Sources: https://github.com/actor-framework

iNET Working Group: http://inet.cpt.haw-hamburg.de

Dominik Charousset iNET – HAW Hamburg 28

Page 29: CAF - The C++ Actor Framework for Scalable and …...2014/10/16  · CAF - The C++ Actor Framework for Scalable and Resource-efficient Applications Dominik Charousset,RaphaelHiesgen,andThomasC.Schmidt

References

Carl Hewitt, Peter Bishop, and Richard Steiger.A Universal Modular ACTOR Formalism for Artificial Intelligence.In Proceedings of the 3rd IJCAI, pages 235–245, San Francisco, CA, USA, 1973. Morgan Kaufmann PublishersInc.

M.L. Dertouzos and AK. Mok.Multiprocessor Online Scheduling of Hard-Real-Time Tasks.Software Engineering, IEEE Transactions on, 15(12):1497–1506, Dec 1989.

Robert D. Blumofe and Charles E. Leiserson.Scheduling Multithreaded Computations by Work Stealing.J. ACM, 46(5):720–748, September 1999.

Vivek Kumar, Daniel Frampton, Stephen M. Blackburn, David Grove, and Olivier Tardieu.Work-stealing Without the Baggage.In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages andApplications, OOPSLA ’12, pages 297–314, New York, NY, USA, 2012. ACM.

Dennis Michael Geels, Gautam Altekar, Scott Shenker, and Ion Stoica.Replay debugging for distributed applications.In Proc. of USENIX’06 Ann. Tech. Conf., pages 289–300. USENIX Assoc., 2006.

Terry Stanley, Tyler Close, and Mark S Miller.Causeway: A message-oriented distributed debugger.Technical Report HPL-2009-78, HP Laboratories, 2009.

Dominik Charousset iNET – HAW Hamburg 29