SlideShare a Scribd company logo
Actor-based concurrency 

in a modern Java Enterprise
Alexander Lukyanchikov
github.com/sqshq
Agenda
- Overview of concurrency models
- Introduc5on to Akka
- When to use it
- How we use it
- Akka with Java and Spring
- Pros&Cons, tricky things

- Live demo!
Free lunch is over
Amdahl's Law
S - speedup
α - serial part of the algorithm
p - number of the processors
Fundamental limita5on 

of parallel compu5ng
Gunther's Law
Overview of concurrency models
Threads
- the basic unit of concurrency, the closest to hardware
- has it's own stack (~ 1Mb)
- shared mutable state should be synchronized
- sync/locks/context switching are expensive
- race condi5ons, starva5on, dead- and live-locks
Overview of concurrency models
- helps to create, manage and u5lize the threads
- s5ll have to think about
- thread pool size
- task queue size
- overflow strategy
Thread pools
Overview of concurrency models
- let to aTach callbacks to the asynchronous task
- chaining mul5ple callbacks
- control the thread/pool for each task
- acceptEither(), thenCombine() and other 

helpful methods
Future composiDon
Overview of concurrency models
ReacDve Streams
- define a source and a consumer, library will take 

care of pushing the data
- transform, combine, split and compose streams
- non-blocking back pressure
- async error handling
Overview of concurrency models
- lightweight threads, scheduled at the applica5on level
- no performance penalty for context switch
- thread-like syntax
- requires bytecode modifica5on
Fibers
Overview of concurrency models
- extremely lightweigh, independent workers with state
- communicate with other actors only by message-passing
- can monitor child actors for failure and take measures
- that's how OOP was ini5ally thought of
Actor model
Akka
- Actor model on JVM
- inspired by Erlang

- Scala and Java API
- free and open-source
- Scale UP (concurrency)
- Scale OUT (Remo5ng + Cluster)
- 50 million msg/sec on single machine
- 2.5 million actors per GB of heap
Akka Actor
- Actor is state, behavior, mailbox, 

child actors and supervision strategy

- On receive it can:

- send messages to other actors

- create new actors

- change the state

- Each one has ActorRef and logical path
- Message sending: tell & ask

akka://my-system/user/my-actor/its-child/...
Akka Actor
"Happens before" rules:
- the send of the message to an actor happens before 

the receive of that message by the same actor
- processing of one message happens before processing 

of the next message by the same actor.
- Many actors share one thread
- Subsequent actor invoca5ons may be on different threads
System design
Pipes & Filters Content-based router
Message endpoint RouDng slipResequencer
ScaLer-gather
Classic Enterprise Integra5on PaTerns to the rescue
ReacDve Messaging PaLerns with the Actor Model: 

ApplicaDons and IntegraDon in Scala and Akka



Vaughn Vernon, 2015
Let it crash!
- Defensive programming is an an5-paTern

- Actors should be organized in a hierarchy
- Parent actor handle child actors failures

- Using thrown excep5on, parent decides what to do:

resume (skip faulty message), restart, stop 

or escalate the error

- One-for-one strategy
- All-for-one strategy

- hooks: preStart(), preRestart(), postStop(), etc
business-logic an error-handling 

flows are separated
Let it crash!
Dispatchers
- Dispatcher is an abstrac5on 

over resources (thread pools)

- 3 types:

- Dispatcher

- PinnedDispatcher

- CallingThreadDispatcher

- 2 executors:

- thread-pool-executor

- fork-join-executor

- min/max number of threads

and throughput are configurable
I/OCPU-intensive
default
Bulkhead Pattern
Routers
A router with specified dispatcher:
Router types:
- Pool (creates routees as child actors)
- Group (sends messages to the specified path)


Balancing strategies:
- Round robin
- Random
- Smallest mailbox
- Broadcast
- ScaTer gather first completed
ReacDve systems
https://www.lightbend.com/reactive-programming-versus-reactive-systems
ReacDve programming vs ReacDve Systems
ElasDc Resilent
Message driven
Responsive
Akka Remote
provides loca=on transparency for peer-to-peer communica5on -

one abstrac=on across all dimensions of scale
Node A
Node B
akka.<protocol>://<actor system name>@<host>:<port>/<actor path>
- Java Serializa5on by default, Kryo/Protobuf/Your-own-serializer supported
- SSL/TLS can be used as the remote transport

- Actors can be deployed on remote host
- Routers can use remote des5na5ons
Akka Cluster
AP System, based on Amazon's Dynamo 

paper (Riak DB approach)
- Communica5on via Gossip protocol
- Vector clocks to reconcile/merge conflicts
- Consistent hashing for par55oning
- No leader-elec5on process, it is just a role
- Failure detector to find unreachable nodes
- Seed nodes to start a cluster
provides membership service with no single point of failure
Cluster Singleton

Ensures that you have exactly one actor of a certain type running in the cluster


Cluster Sharding
Distributes actors across several nodes and supports interac8on with the actors

using their logical iden8fier without having to care about their physical loca8on

Cluster Client
Communica8on from an actor system that is not part of the cluster to actors 

running somewhere in the cluster
Distributed Publish Subscribe
Publish-subscribe and point-to-point messaging between actors in the 

cluster, sender doesn't have to know on which node the target actor is running

Distributed Data

Key-value store like API to share data between nodes in an the cluster
Akka is awesome!
- Simple and powerful way to abstract from 

low-level concurrency issues

- Ability to build reliable decentralized architecture

and scale out with no code changes

- Wonderful documenta5on & community
But.
- Need a new mindset

- Code complexity: actors communica5on graph might be tricky

Find Usages from IDE won't help here

- Loss of typesafety between actors

you can live with it, with proper tesAng

- Stacktraces lack meaning

what was the message? what's the internal state?
- Possible deadlocks

bounded mailboxes, synchronizaAon between actors

- Possible OutOfMemoryErrors

unbounded mailboxes under load
Tricky things
- Messages should be immutable

- By default, delivery is not guaranteed*

- Backpressure is important

Work Pulling? Bounded mailbox? Something else?

- Be careful with blocking opera5ons

Avoid shared state & synchronizaAon, 

use separate dispatcher for I/O
* Nobody Needs Reliable Messaging

hTps://www.infoq.com/ar5cles/no-reliable-messaging
When to use it
- Akka's creators: almost everywhere

- Transac5on processing (online gaming, finance, sta5s5cs)

- Service backend (any industry, any app)

- Snap-in concurrency/parallelism (any app)

- Batch processing (any industry)

- Communica5ons hub (telecom, web media, mobile media)

- BI/datamining/general purpose crunching

- Common sense: when performance and scalability is crucial

- Handle large number of concurrent ac5vi5es

- Be easily distributable & scalable over a network of machines

- Well known success stories:

Messaging systems, Search indexing, Web-crawling, 

Sol-real5me analy5cs, Game servers, etc
How we use it
Communica5on hub / Messaging system
- 500k concurrent websocket connec5ons
- 8 c4.xlarge (×1.5-2 overprovisioned)
- Receive rate per server: ~ 200 messages per second
- Send rate per server: ~ 1000 messages per second
- Round-trip latency within a system
- 80th pct: 20 ms
- 90th pct: 50 ms
- 95th pct: 200 ms

- Akka Java API
- Spring (DI, websockets, async controllers, etc)
Java
Scala
Scala vs Java API
Java
Scala
Scala vs Java API
Java Scala vs Java API
Scala Scala vs Java API
Scala is nice, nobody doubts
But someDmes business prefers to sDck with Java.
Akka Java API is too damn good to argue.
- Actor have a specific lifecycle + it's hidden behind the ActorRef

Luckily Akka Extens5ons mechanism allows to use external DI framework
Spring & Akka
- Actor is just a @Prototype bean:
Spring & Akka
Async Controllers
DEMO
Let's get coding, finally!
Robot Control System
Let's keep it simple 

for the demo
Cluster Aware Router
Distributed pub/sub
Distribute
across mulDple nodes
Distributed data
Scale out
the most overloaded service
Thank you!
hLps://github.com/sqshq/robot-control-system

More Related Content

What's hot

Database security and privacy
Database security and privacyDatabase security and privacy
Database security and privacy
Md. Ahasan Hasib
 
Data Privacy in the DMBOK - No Need to Reinvent the Wheel
Data Privacy in the DMBOK - No Need to Reinvent the WheelData Privacy in the DMBOK - No Need to Reinvent the Wheel
Data Privacy in the DMBOK - No Need to Reinvent the Wheel
DATAVERSITY
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
Trinath
 
Oracle 12c Multitenant architecture
Oracle 12c Multitenant architectureOracle 12c Multitenant architecture
Oracle 12c Multitenant architecture
naderattia
 
Introducing Azure SQL Data Warehouse
Introducing Azure SQL Data WarehouseIntroducing Azure SQL Data Warehouse
Introducing Azure SQL Data Warehouse
James Serra
 
Data models
Data modelsData models
Data models
RituBhargava7
 
Building an Effective Data Warehouse Architecture
Building an Effective Data Warehouse ArchitectureBuilding an Effective Data Warehouse Architecture
Building an Effective Data Warehouse Architecture
James Serra
 
20171019 data migration (rk)
20171019 data migration (rk)20171019 data migration (rk)
20171019 data migration (rk)
Ruud Kapteijn
 
Data Migration PowerPoint Presentation Slides
Data Migration PowerPoint Presentation Slides Data Migration PowerPoint Presentation Slides
Data Migration PowerPoint Presentation Slides
SlideTeam
 
Gathering Business Requirements for Data Warehouses
Gathering Business Requirements for Data WarehousesGathering Business Requirements for Data Warehouses
Gathering Business Requirements for Data Warehouses
David Walker
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
philipsinter
 
Database management systems components
Database management systems componentsDatabase management systems components
Database management systems components
muhammad bilal
 
Azure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse Analytics
WinWire Technologies Inc
 
Case study: Implementation of OLAP operations
Case study: Implementation of OLAP operationsCase study: Implementation of OLAP operations
Case study: Implementation of OLAP operations
chirag patil
 
Big Data Evolution
Big Data EvolutionBig Data Evolution
Big Data Evolution
itnewsafrica
 
A brief history of data warehousing
A brief history of data warehousingA brief history of data warehousing
A brief history of data warehousing
Rob Winters
 
Oracle Database 12c Multitenant for Consolidation
Oracle Database 12c Multitenant for ConsolidationOracle Database 12c Multitenant for Consolidation
Oracle Database 12c Multitenant for Consolidation
Yudi Herdiana
 
Oracle Sharding 18c - Technical Overview
Oracle Sharding 18c - Technical OverviewOracle Sharding 18c - Technical Overview
Oracle Sharding 18c - Technical Overview
Markus Michalewicz
 
Microstrategy
MicrostrategyMicrostrategy
Microstrategy
vijaykodlipet
 
Database development progress(database)
Database development progress(database)Database development progress(database)
Database development progress(database)welcometofacebook
 

What's hot (20)

Database security and privacy
Database security and privacyDatabase security and privacy
Database security and privacy
 
Data Privacy in the DMBOK - No Need to Reinvent the Wheel
Data Privacy in the DMBOK - No Need to Reinvent the WheelData Privacy in the DMBOK - No Need to Reinvent the Wheel
Data Privacy in the DMBOK - No Need to Reinvent the Wheel
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
 
Oracle 12c Multitenant architecture
Oracle 12c Multitenant architectureOracle 12c Multitenant architecture
Oracle 12c Multitenant architecture
 
Introducing Azure SQL Data Warehouse
Introducing Azure SQL Data WarehouseIntroducing Azure SQL Data Warehouse
Introducing Azure SQL Data Warehouse
 
Data models
Data modelsData models
Data models
 
Building an Effective Data Warehouse Architecture
Building an Effective Data Warehouse ArchitectureBuilding an Effective Data Warehouse Architecture
Building an Effective Data Warehouse Architecture
 
20171019 data migration (rk)
20171019 data migration (rk)20171019 data migration (rk)
20171019 data migration (rk)
 
Data Migration PowerPoint Presentation Slides
Data Migration PowerPoint Presentation Slides Data Migration PowerPoint Presentation Slides
Data Migration PowerPoint Presentation Slides
 
Gathering Business Requirements for Data Warehouses
Gathering Business Requirements for Data WarehousesGathering Business Requirements for Data Warehouses
Gathering Business Requirements for Data Warehouses
 
Fundamentals of Database system
Fundamentals of Database systemFundamentals of Database system
Fundamentals of Database system
 
Database management systems components
Database management systems componentsDatabase management systems components
Database management systems components
 
Azure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse Analytics
 
Case study: Implementation of OLAP operations
Case study: Implementation of OLAP operationsCase study: Implementation of OLAP operations
Case study: Implementation of OLAP operations
 
Big Data Evolution
Big Data EvolutionBig Data Evolution
Big Data Evolution
 
A brief history of data warehousing
A brief history of data warehousingA brief history of data warehousing
A brief history of data warehousing
 
Oracle Database 12c Multitenant for Consolidation
Oracle Database 12c Multitenant for ConsolidationOracle Database 12c Multitenant for Consolidation
Oracle Database 12c Multitenant for Consolidation
 
Oracle Sharding 18c - Technical Overview
Oracle Sharding 18c - Technical OverviewOracle Sharding 18c - Technical Overview
Oracle Sharding 18c - Technical Overview
 
Microstrategy
MicrostrategyMicrostrategy
Microstrategy
 
Database development progress(database)
Database development progress(database)Database development progress(database)
Database development progress(database)
 

Similar to Actor-based concurrency in a modern Java Enterprise

Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
Konrad Dusza
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
Guido Schmutz
 
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
Claus Ibsen
 
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
OSS EU:  Deep Dive into Building Streaming Applications with Apache PulsarOSS EU:  Deep Dive into Building Streaming Applications with Apache Pulsar
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
Timothy Spann
 
AKKA and Scala @ Inneractive
AKKA and Scala @ InneractiveAKKA and Scala @ Inneractive
AKKA and Scala @ Inneractive
Gal Aviv
 
CODEONTHEBEACH_Streaming Applications with Apache Pulsar
CODEONTHEBEACH_Streaming Applications with Apache PulsarCODEONTHEBEACH_Streaming Applications with Apache Pulsar
CODEONTHEBEACH_Streaming Applications with Apache Pulsar
Timothy Spann
 
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar) Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
Timothy Spann
 
[March sn meetup] apache pulsar + apache nifi for cloud data lake
[March sn meetup] apache pulsar + apache nifi for cloud data lake[March sn meetup] apache pulsar + apache nifi for cloud data lake
[March sn meetup] apache pulsar + apache nifi for cloud data lake
Timothy Spann
 
Integrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
Integrating R and the JVM Platform - Alpine Data Labs' R Execute OperatorIntegrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
Integrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
alpinedatalabs
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
RubiX BV
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
petabridge
 
Flink forward-2017-netflix keystones-paas
Flink forward-2017-netflix keystones-paasFlink forward-2017-netflix keystones-paas
Flink forward-2017-netflix keystones-paas
Monal Daxini
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around KafkaKafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Guido Schmutz
 
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integrationSouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
Claus Ibsen
 
Indeed Flex: The Story of a Revolutionary Recruitment Platform
Indeed Flex: The Story of a Revolutionary Recruitment PlatformIndeed Flex: The Story of a Revolutionary Recruitment Platform
Indeed Flex: The Story of a Revolutionary Recruitment Platform
HostedbyConfluent
 
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian PasternackiPLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
PROIDEA
 
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
Data science online camp   using the flipn stack for edge ai (flink, nifi, pu...Data science online camp   using the flipn stack for edge ai (flink, nifi, pu...
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
Timothy Spann
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Raymond Roestenburg
 

Similar to Actor-based concurrency in a modern Java Enterprise (20)

Actor model in .NET - Akka.NET
Actor model in .NET - Akka.NETActor model in .NET - Akka.NET
Actor model in .NET - Akka.NET
 
Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !Apache Kafka - Scalable Message-Processing and more !
Apache Kafka - Scalable Message-Processing and more !
 
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
Red Hat Nordics 2020 - Apache Camel 3 the next generation of enterprise integ...
 
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
OSS EU:  Deep Dive into Building Streaming Applications with Apache PulsarOSS EU:  Deep Dive into Building Streaming Applications with Apache Pulsar
OSS EU: Deep Dive into Building Streaming Applications with Apache Pulsar
 
AKKA and Scala @ Inneractive
AKKA and Scala @ InneractiveAKKA and Scala @ Inneractive
AKKA and Scala @ Inneractive
 
CODEONTHEBEACH_Streaming Applications with Apache Pulsar
CODEONTHEBEACH_Streaming Applications with Apache PulsarCODEONTHEBEACH_Streaming Applications with Apache Pulsar
CODEONTHEBEACH_Streaming Applications with Apache Pulsar
 
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar) Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
Using the FLiPN Stack for Edge AI (Flink, NiFi, Pulsar)
 
[March sn meetup] apache pulsar + apache nifi for cloud data lake
[March sn meetup] apache pulsar + apache nifi for cloud data lake[March sn meetup] apache pulsar + apache nifi for cloud data lake
[March sn meetup] apache pulsar + apache nifi for cloud data lake
 
Integrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
Integrating R and the JVM Platform - Alpine Data Labs' R Execute OperatorIntegrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
Integrating R and the JVM Platform - Alpine Data Labs' R Execute Operator
 
Reactive Streams - László van den Hoek
Reactive Streams - László van den HoekReactive Streams - László van den Hoek
Reactive Streams - László van den Hoek
 
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NETDotNext 2020 - When and How to Use the Actor Model and Akka.NET
DotNext 2020 - When and How to Use the Actor Model and Akka.NET
 
Flink forward-2017-netflix keystones-paas
Flink forward-2017-netflix keystones-paasFlink forward-2017-netflix keystones-paas
Flink forward-2017-netflix keystones-paas
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around KafkaKafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
Kafka Connect & Kafka Streams/KSQL - the ecosystem around Kafka
 
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integrationSouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
SouJava May 2020: Apache Camel 3 - the next generation of enterprise integration
 
Indeed Flex: The Story of a Revolutionary Recruitment Platform
Indeed Flex: The Story of a Revolutionary Recruitment PlatformIndeed Flex: The Story of a Revolutionary Recruitment Platform
Indeed Flex: The Story of a Revolutionary Recruitment Platform
 
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian PasternackiPLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
PLNOG16: Bezpieczeństwo w sieci operatora, Sebastian Pasternacki
 
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
Data science online camp   using the flipn stack for edge ai (flink, nifi, pu...Data science online camp   using the flipn stack for edge ai (flink, nifi, pu...
Data science online camp using the flipn stack for edge ai (flink, nifi, pu...
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011Real world Scala hAkking NLJUG JFall 2011
Real world Scala hAkking NLJUG JFall 2011
 

Recently uploaded

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 

Recently uploaded (20)

Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 

Actor-based concurrency in a modern Java Enterprise

  • 1. Actor-based concurrency 
 in a modern Java Enterprise Alexander Lukyanchikov github.com/sqshq
  • 2. Agenda - Overview of concurrency models - Introduc5on to Akka - When to use it - How we use it - Akka with Java and Spring - Pros&Cons, tricky things
 - Live demo!
  • 4. Amdahl's Law S - speedup α - serial part of the algorithm p - number of the processors Fundamental limita5on 
 of parallel compu5ng
  • 6. Overview of concurrency models Threads - the basic unit of concurrency, the closest to hardware - has it's own stack (~ 1Mb) - shared mutable state should be synchronized - sync/locks/context switching are expensive - race condi5ons, starva5on, dead- and live-locks
  • 7. Overview of concurrency models - helps to create, manage and u5lize the threads - s5ll have to think about - thread pool size - task queue size - overflow strategy Thread pools
  • 8. Overview of concurrency models - let to aTach callbacks to the asynchronous task - chaining mul5ple callbacks - control the thread/pool for each task - acceptEither(), thenCombine() and other 
 helpful methods Future composiDon
  • 9. Overview of concurrency models ReacDve Streams - define a source and a consumer, library will take 
 care of pushing the data - transform, combine, split and compose streams - non-blocking back pressure - async error handling
  • 10. Overview of concurrency models - lightweight threads, scheduled at the applica5on level - no performance penalty for context switch - thread-like syntax - requires bytecode modifica5on Fibers
  • 11. Overview of concurrency models - extremely lightweigh, independent workers with state - communicate with other actors only by message-passing - can monitor child actors for failure and take measures - that's how OOP was ini5ally thought of Actor model
  • 12. Akka - Actor model on JVM - inspired by Erlang
 - Scala and Java API - free and open-source - Scale UP (concurrency) - Scale OUT (Remo5ng + Cluster) - 50 million msg/sec on single machine - 2.5 million actors per GB of heap
  • 13. Akka Actor - Actor is state, behavior, mailbox, 
 child actors and supervision strategy
 - On receive it can:
 - send messages to other actors
 - create new actors
 - change the state
 - Each one has ActorRef and logical path - Message sending: tell & ask
 akka://my-system/user/my-actor/its-child/...
  • 14. Akka Actor "Happens before" rules: - the send of the message to an actor happens before 
 the receive of that message by the same actor - processing of one message happens before processing 
 of the next message by the same actor. - Many actors share one thread - Subsequent actor invoca5ons may be on different threads
  • 15. System design Pipes & Filters Content-based router Message endpoint RouDng slipResequencer ScaLer-gather Classic Enterprise Integra5on PaTerns to the rescue ReacDve Messaging PaLerns with the Actor Model: 
 ApplicaDons and IntegraDon in Scala and Akka
 
 Vaughn Vernon, 2015
  • 16. Let it crash! - Defensive programming is an an5-paTern
 - Actors should be organized in a hierarchy - Parent actor handle child actors failures
 - Using thrown excep5on, parent decides what to do:
 resume (skip faulty message), restart, stop 
 or escalate the error
 - One-for-one strategy - All-for-one strategy
 - hooks: preStart(), preRestart(), postStop(), etc business-logic an error-handling 
 flows are separated
  • 18. Dispatchers - Dispatcher is an abstrac5on 
 over resources (thread pools)
 - 3 types:
 - Dispatcher
 - PinnedDispatcher
 - CallingThreadDispatcher
 - 2 executors:
 - thread-pool-executor
 - fork-join-executor
 - min/max number of threads
 and throughput are configurable I/OCPU-intensive default Bulkhead Pattern
  • 19. Routers A router with specified dispatcher: Router types: - Pool (creates routees as child actors) - Group (sends messages to the specified path) 
 Balancing strategies: - Round robin - Random - Smallest mailbox - Broadcast - ScaTer gather first completed
  • 21. Akka Remote provides loca=on transparency for peer-to-peer communica5on -
 one abstrac=on across all dimensions of scale Node A Node B akka.<protocol>://<actor system name>@<host>:<port>/<actor path> - Java Serializa5on by default, Kryo/Protobuf/Your-own-serializer supported - SSL/TLS can be used as the remote transport
 - Actors can be deployed on remote host - Routers can use remote des5na5ons
  • 22. Akka Cluster AP System, based on Amazon's Dynamo 
 paper (Riak DB approach) - Communica5on via Gossip protocol - Vector clocks to reconcile/merge conflicts - Consistent hashing for par55oning - No leader-elec5on process, it is just a role - Failure detector to find unreachable nodes - Seed nodes to start a cluster provides membership service with no single point of failure Cluster Singleton
 Ensures that you have exactly one actor of a certain type running in the cluster 
 Cluster Sharding Distributes actors across several nodes and supports interac8on with the actors
 using their logical iden8fier without having to care about their physical loca8on
 Cluster Client Communica8on from an actor system that is not part of the cluster to actors 
 running somewhere in the cluster Distributed Publish Subscribe Publish-subscribe and point-to-point messaging between actors in the 
 cluster, sender doesn't have to know on which node the target actor is running
 Distributed Data
 Key-value store like API to share data between nodes in an the cluster
  • 23. Akka is awesome! - Simple and powerful way to abstract from 
 low-level concurrency issues
 - Ability to build reliable decentralized architecture
 and scale out with no code changes
 - Wonderful documenta5on & community
  • 24. But. - Need a new mindset
 - Code complexity: actors communica5on graph might be tricky
 Find Usages from IDE won't help here
 - Loss of typesafety between actors
 you can live with it, with proper tesAng
 - Stacktraces lack meaning
 what was the message? what's the internal state? - Possible deadlocks
 bounded mailboxes, synchronizaAon between actors
 - Possible OutOfMemoryErrors
 unbounded mailboxes under load
  • 25. Tricky things - Messages should be immutable
 - By default, delivery is not guaranteed*
 - Backpressure is important
 Work Pulling? Bounded mailbox? Something else?
 - Be careful with blocking opera5ons
 Avoid shared state & synchronizaAon, 
 use separate dispatcher for I/O * Nobody Needs Reliable Messaging
 hTps://www.infoq.com/ar5cles/no-reliable-messaging
  • 26. When to use it - Akka's creators: almost everywhere
 - Transac5on processing (online gaming, finance, sta5s5cs)
 - Service backend (any industry, any app)
 - Snap-in concurrency/parallelism (any app)
 - Batch processing (any industry)
 - Communica5ons hub (telecom, web media, mobile media)
 - BI/datamining/general purpose crunching
 - Common sense: when performance and scalability is crucial
 - Handle large number of concurrent ac5vi5es
 - Be easily distributable & scalable over a network of machines
 - Well known success stories:
 Messaging systems, Search indexing, Web-crawling, 
 Sol-real5me analy5cs, Game servers, etc
  • 27. How we use it Communica5on hub / Messaging system - 500k concurrent websocket connec5ons - 8 c4.xlarge (×1.5-2 overprovisioned) - Receive rate per server: ~ 200 messages per second - Send rate per server: ~ 1000 messages per second - Round-trip latency within a system - 80th pct: 20 ms - 90th pct: 50 ms - 95th pct: 200 ms
 - Akka Java API - Spring (DI, websockets, async controllers, etc)
  • 30. Java Scala vs Java API
  • 31. Scala Scala vs Java API
  • 32. Scala is nice, nobody doubts But someDmes business prefers to sDck with Java. Akka Java API is too damn good to argue.
  • 33. - Actor have a specific lifecycle + it's hidden behind the ActorRef
 Luckily Akka Extens5ons mechanism allows to use external DI framework Spring & Akka - Actor is just a @Prototype bean:
  • 34. Spring & Akka Async Controllers
  • 37. Let's keep it simple 
 for the demo
  • 38. Cluster Aware Router Distributed pub/sub Distribute across mulDple nodes Distributed data
  • 39. Scale out the most overloaded service