SlideShare une entreprise Scribd logo
1  sur  46
Télécharger pour lire hors ligne
Beyond Horizontal Scalability:
    Concurrency & Messaging Using Spring
    Bruce Snyder, Senior Software Engineer, SpringSource/VMware




Friday, July 8, 2011
Problem Statement

    • Software systems are growing larger than ever before
           –   Virtual Machines
           –   Physical Machines
           –   More CPUs
           –   Multi-core CPUs
           –   More requests
           –   More data


    • With so many hardware changes, shouldn’t our software
      practices change too?




Friday, July 8, 2011
Typical Application Layers




                                 3

Friday, July 8, 2011
Typical Code Construction

    • Command-and-control scheme
           – One method calls another
           – Blocking calls


    • Assumptions
           –   One task takes place at a time
           –   The order of operations in known
           –   The provider of a particular function is known
           –   All execution happens in a single JVM




                                                                4

Friday, July 8, 2011
Typical Component Interaction

    • Single memory space
    • Using the call stack
    • Sequential execution

    • Assumptions
           – No separation between:
                 • Knowing what needs to happen next
                 • Knowing which method to invoke
           – Interactions are always known at compile time




                                                             5

Friday, July 8, 2011
Typical Assumptions

    • All work must take place in a single call stack
    • Example:
           –   Receive request
           –   Verify data
           –   Save data
           –   Query data
           –   Generate PDF
           –   Send email
           –   Render response




                                                        6

Friday, July 8, 2011
• The higher the number of assumptions, the more tightly
      coupled the system
                                                               7

Friday, July 8, 2011
Typical Client Request




                             8

Friday, July 8, 2011
Typical Request Growth




                             9

Friday, July 8, 2011
Typical Strategy For Horizontal Scaling




                                              10

Friday, July 8, 2011
Typical Assumptions

    • All work must take place on a single machine
    • Example:
           –   Receive request
           –   Verify data
           –   Save data
           –   Query data
           –   Generate PDF
           –   Send email
           –   Render response




                                                     11

Friday, July 8, 2011
Treating the Symptoms

    • Horizontal scale is good to a point
           – Treat the symptoms instead of fixing the cause of the illness


    • Throughput of functions should not equal response time!

    • This is not the case at forward-thinking companies
           – Amazon.com




                                                                        12

Friday, July 8, 2011
The Problem With Distributed Systems

    • Most developers don’t understand them
           – Call stack provides specific interaction style
           – Most object-oriented systems focus on structure vs.
             interaction

    • Interaction becomes more important than structure
           – Mediator pattern - encapsulates how objects interact
           – Observer pattern - notifies dependent objects of state change


    • The real point of service-orientated design
           – Composition rules are rather simple
           – Loosely coupled interaction becomes very important

                                                                       13

Friday, July 8, 2011
Is There a Better Solution?

    • Insert a level of indirection
           – Remove direct interaction between components
           – Extract the interaction into a separate element
           – Enterprise Integration Patterns (EIP)
                 • http://enterpriseintegrationpatterns.com/


    • Simplify the rules of component interaction
           – Remove the coordination and continuation style of interaction
           – Just send data




                                                                       14

Friday, July 8, 2011
Concurrency

    • Concurrency is a style of asynchronous execution




                                                         15

Friday, July 8, 2011
Concurrency With Spring

    • Spring provides the TaskExecutor interface
           – Abstracts the execution of a Runnable, i.e., asynchronous work
           – SimpleAsyncTaskExecutor
                 • Creates a new thread for each task
           – ThreadPoolTaskExecutor
                 • Uses a JDK 1.5 ThreadPoolExecutor to create a pool of threads
           – org.springframework.scheduling.concurrent package
                 • Many scheduling related utility classes
           – WorkManagerTaskExecutor
                 • Delegates to a JCA 1.5 CommonJ WorkManager




                                                                             16

Friday, July 8, 2011
JDK ExecutorService


   ExecutorService executorService = Executors.newSingleThreadExecutor();
   executorService.execute(task);
   executorService.shutdown();


   executorService = Executors.newFixedThreadPool(10);
   executorService.execute(task);
   executorService.shutdown();


   int corePoolSize = 5;
   int maxPoolSize = 10;
   long keepAliveTime = 5000;
   executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize,
        keepAliveTime, TimeUnit.MILLISECONDS,
        new LinkedBlockingQueue<Runnable>());
   executorService.execute(task);
   executorService.shutdown();

                                                                            17

Friday, July 8, 2011
Spring TaskExecutor


     <bean id="myTask" class="org.bsnyder.spring.concurrency.MyTask" />

    <bean id="springConcurrencyExample"
   class="org.bsnyder.spring.concurrency.SpringConcurrencyExample" />

    <bean id="simpleAsyncTaskExecutor"
   class="org.springframework.core.task.SimpleAsyncTaskExecutor"
     p:daemon="false" />

    <bean id="taskExecutor"
   class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"
     p:corePoolSize="5" p:maxPoolSize="10" p:queueCapacity="30" />




                                                                              18

Friday, July 8, 2011
Spring TaskExecutor

   public class SpringConcurrencyExample {
   !    @Autowired
   !    private Runnable task;
   !    @Autowired
   !    private SimpleAsyncTaskExecutor simpleAsyncTaskExecutor;
   !    @Autowired
   !    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
   !
   !    public void runExamples() {
   !    !     simpleAsyncTaskExecutor.execute(task);
   !    !     threadPoolTaskExecutor.execute(task);
   !    }
   !
   !    public static void main(String[] args) {
   !    !     ApplicationContext context =
   !    !     !     new ClassPathXmlApplicationContext("/META-INF/spring/executor-context.xml",
                    SpringConcurrencyExample.class);
   !    !     SpringConcurrencyExample example =
                    context.getBean(SpringConcurrencyExample.class);
   !    !     example.runExamples();
   !    }
   }


                                                                                             19

Friday, July 8, 2011
Messaging

    • Messaging is a style of communication
    • Often used for integration purposes




                                              20

Friday, July 8, 2011
Messaging With Spring

    • JMS Support
           – JmsTemplate for sync send and receive
           – DefaultMessageListenerContainer and
             SimpleMessageListenerContainer for async receive
                 • javax.jms.MessageListener
                 • org.springframework.jms.listener.SessionAwareMessageListener
                 • org.springframework.jms.listener.adapter.MessageListenerAdapter
    • AMQP Support
           – RabbitTemplate for sync send and receive
           – SimpleMessageListenerContainer for async receive
                 • org.springframework.amqp.core.MessageListener
                 • org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter


                                                                                     21

Friday, July 8, 2011
Spring JmsTemplate
                                                                      Synchronous

   <bean id="connectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory"
    p:brokerURL="tcp://localhost:61616" />

     <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
      <constructor-arg value="FOO.TEST" />
     </bean>

     <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
      p:connectionFactory-ref="connectionFactory"
      p:defaultDestination-ref="destination" />

     <bean id="messageProducer"
      class="org.bsnyder.spring.jms.producer.SimpleMessageProducer"
      p:jmsTemplate-ref="jmsTemplate" />




                                                                                 22

Friday, July 8, 2011
Spring JmsTemplate
                                                                           Synchronous


         // Use the default destination
         jmsTemplate.convertAndSend("Hello World!");

         // Use a different destination
         jmsTemplate.convertAndSend(“TEST.BAR”, “Hello World!”);



         // Use a different destination
         String textMessage1 = (String) jmsTemplate.receiveAndConvert();

         // Use a different destination
         String textMessage2 = (String) jmsTemplate.receiveAndConvert(“TEST.BAR”);




                                                                                     23

Friday, July 8, 2011
DefaultMessageListenerContainer
                                                                          Asynchronous
    • XML configuration

         <bean id="connectionFactory"
         class="org.apache.activemq.ActiveMQConnectionFactory"
           p:brokerURL="tcp://localhost:61616" />

          <bean id="messageListener"
           class="org.bsnyder.spring.jms.listener.SimpleMessageListener" />

          <jms:listener-container concurrency="5-10">
           <jms:listener destination="FOO.TEST" ref="messageListener"/>
          </jms:listener-container>




                                                                                   24

Friday, July 8, 2011
Spring RabbitTemplate
                                                                        Synchronous

     <bean id="rabbitAdmin"
      class="org.springframework.amqp.rabbit.core.RabbitAdmin">
      <constructor-arg ref="connectionFactory"/>
     </bean>

     <bean id="connectionFactory"
      class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"
      p:host="localhost" p:port="5672" p:username="guest" p:password="guest"/>

     <bean id="rabbitTemplate"
      class="org.springframework.amqp.rabbit.core.RabbitTemplate"
      p:connectionFactory-ref="connectionFactory" p:routingKey="TEST.FOO"
      p:queue="TEST.FOO" />

     <bean id="messageProducer"
      class="org.bsnyder.spring.amqp.producer.SimpleMessageProducer"
      p:rabbitAdmin-ref="rabbitAdmin" p:rabbitTemplate-ref="rabbitTemplate"/>


                                                                                   25

Friday, July 8, 2011
Spring RabbitTemplate
                                                                           Synchronous


      // Use the default destination
      rabbitTemplate.convertAndSend("Hello World!");

      // Use a different destination
      rabbitTemplate.send(“TEST.FOO”, “TEST.FOO”, message);



      // Use a different destination
      Message message1 = rabbitTemplate.receiveAndConvert();

      // Use a different destination
      String textMessage2 = (String) rabbitTemplate.receive(“TEST.FOO”);




                                                                                   26

Friday, July 8, 2011
SimpleMessageListenerContainer
                                                                              Asynchronous

  <bean id="connectionFactory"
    class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"
    p:host="localhost" p:port="5672" p:username="guest" p:password="guest"/>

    <bean id="rabbitAdmin"
     class="org.springframework.amqp.rabbit.core.RabbitAdmin">
     <constructor-arg ref="connectionFactory"/>
    </bean>

    <bean id="rabbitTemplate"
     class="org.springframework.amqp.rabbit.core.RabbitTemplate"
     p:connectionFactory-ref="connectionFactory" p:routingKey="TEST.FOO"
     p:queue="TEST.FOO" />

  <bean id="messageListener" class="org.bsnyder.spring.amqp.listener.SimpleMessageListener"
   p:rabbitTemplate-ref="rabbitTemplate"/>

  <bean id="listenerContainer"
    class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"
    p:connectionFactory-ref="connectionFactory" p:queueName="TEST.FOO"
    p:concurrentConsumers="5" p:listener="messageListener" />

                                                                                              27

Friday, July 8, 2011
Best of Both Worlds

    • What if concurrency and messaging was provided
      together?




                                                       28

Friday, July 8, 2011
Spring Integration

    • A framework for integration

    • Styles of integration
           – Intra-application integration
           – Inter-application integration
           – External system integration




                                             29

Friday, July 8, 2011
Enterprise Integration Patterns (EIP)




                       http://enterpriseintegrationpatterns.com/
                                                                   30

Friday, July 8, 2011
Spring Integration

    • Provides both concurrency and messaging
           – Message Endpoints
                 • Connections between services
           – Channel Adapters
                 • Adapter between application and message broker
           – Messaging Gateways
                 • Provides uni-directional or bi-directional messaging
           – Service Activators
                 • Invokes a services based on an incoming message
           – Routers
                 • Determines where to dispatch a message
           – Splitters and Aggregators
                 • Breaks up a message and reassembles it after processing

                                                                             31

Friday, July 8, 2011
Spring Integration

    • Supports
           –   AMQP
           –   Email
           –   File system
           –   Gemfire
           –   JMS
           –   JMX
           –   MongoDB
           –   Redis
           –   Spring Batch
           –   Testing
           –   Web Services

                              32

Friday, July 8, 2011
Spring Integration




                         33

Friday, July 8, 2011
Spring Integration




                         34

Friday, July 8, 2011
Spring Integration




                         35

Friday, July 8, 2011
Spring Integration




                         36

Friday, July 8, 2011
Spring Integration




                         37

Friday, July 8, 2011
Spring Integration




                         38

Friday, July 8, 2011
Spring Integration




                         39

Friday, July 8, 2011
Spring Integration




                         40

Friday, July 8, 2011
Spring Integration




                         41

Friday, July 8, 2011
Spring Integration




                         42

Friday, July 8, 2011
Your Coffee Shop Does Not Use 2PC

    •    Order is accepted
    •    Cup is labeled and placed in the queue
    •    Money is exchanged
    •    Coffee drink is processed

    •    Multiple baristas = competing consumers
    •    Drinks are processed out of order = correlation id (label)
    •    Cannot pay for drink = discard (write-off)
    •    Erroneous drink = retry
    •    Drink machine fails = compensating action (refund, etc.)


                                                                      43

Friday, July 8, 2011
Conversation Pattern

    • Interaction between two parties
           – Short synchronous interaction
           – Longer asynchronous interaction


    • Other examples
           – Amazon.com




                                               44

Friday, July 8, 2011
Cafe Demo




                       45

Friday, July 8, 2011
Thank You!




           Q&A




Friday, July 8, 2011

Contenu connexe

Similaire à Beyond Horizontal Scalability: Concurrency and Messaging Using Spring

ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In ActionBruce Snyder
 
MongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema DesignMongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema DesignDATAVERSITY
 
Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringBruce Snyder
 
From Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEEFrom Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEEjaxconf
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackabilityPuppet
 
PushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design DocumentPushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design DocumentClever Moe
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performancejeresig
 
Infusion for the birds
Infusion for the birdsInfusion for the birds
Infusion for the birdscolinbdclark
 
Making Life Easier with PowerShell - SPSRIC
Making Life Easier with PowerShell - SPSRICMaking Life Easier with PowerShell - SPSRIC
Making Life Easier with PowerShell - SPSRICMichael Greene
 
2011 july-gtug-high-replication-datastore
2011 july-gtug-high-replication-datastore2011 july-gtug-high-replication-datastore
2011 july-gtug-high-replication-datastoreikailan
 
Unit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainUnit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainnevenfi
 
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.WO Community
 
Jpa with spring data
Jpa with spring dataJpa with spring data
Jpa with spring dataSean Lee
 
Flowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock
 

Similaire à Beyond Horizontal Scalability: Concurrency and Messaging Using Spring (20)

ActiveMQ In Action
ActiveMQ In ActionActiveMQ In Action
ActiveMQ In Action
 
MongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema DesignMongoDB at Sailthru: Scaling and Schema Design
MongoDB at Sailthru: Scaling and Schema Design
 
Styles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using SpringStyles of Applicaton Integration Using Spring
Styles of Applicaton Integration Using Spring
 
STI Summit 2011 - Linked services
STI Summit 2011 - Linked servicesSTI Summit 2011 - Linked services
STI Summit 2011 - Linked services
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
From Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEEFrom Tomcat to Java EE, making the transition with TomEE
From Tomcat to Java EE, making the transition with TomEE
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
App Engine Meetup
App Engine MeetupApp Engine Meetup
App Engine Meetup
 
PushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design DocumentPushToTest TestMaker 6.5 Open Source Test Design Document
PushToTest TestMaker 6.5 Open Source Test Design Document
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Holistic JavaScript Performance
Holistic JavaScript PerformanceHolistic JavaScript Performance
Holistic JavaScript Performance
 
Infusion for the birds
Infusion for the birdsInfusion for the birds
Infusion for the birds
 
Making Life Easier with PowerShell - SPSRIC
Making Life Easier with PowerShell - SPSRICMaking Life Easier with PowerShell - SPSRIC
Making Life Easier with PowerShell - SPSRIC
 
Expert system
Expert systemExpert system
Expert system
 
2011 july-gtug-high-replication-datastore
2011 july-gtug-high-replication-datastore2011 july-gtug-high-replication-datastore
2011 july-gtug-high-replication-datastore
 
RunDeck
RunDeckRunDeck
RunDeck
 
Unit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainUnit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintain
 
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
Beyond Fluffy Bunny. How I leveraged WebObjects in my lean startup.
 
Jpa with spring data
Jpa with spring dataJpa with spring data
Jpa with spring data
 
Flowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDBFlowdock's full-text search with MongoDB
Flowdock's full-text search with MongoDB
 

Plus de Bruce Snyder

Using Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel JockeyUsing Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel JockeyBruce Snyder
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixBruce Snyder
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixBruce Snyder
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQBruce Snyder
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSBruce Snyder
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a RideBruce Snyder
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixBruce Snyder
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQBruce Snyder
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 

Plus de Bruce Snyder (11)

Using Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel JockeyUsing Enterprise Integration Patterns as Your Camel Jockey
Using Enterprise Integration Patterns as Your Camel Jockey
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
 
Service-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMixService-Oriented Integration With Apache ServiceMix
Service-Oriented Integration With Apache ServiceMix
 
Messaging With Apache ActiveMQ
Messaging With Apache ActiveMQMessaging With Apache ActiveMQ
Messaging With Apache ActiveMQ
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMS
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
EIP In Practice
EIP In PracticeEIP In Practice
EIP In Practice
 
Service Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMixService Oriented Integration With ServiceMix
Service Oriented Integration With ServiceMix
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQ
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 

Dernier

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 

Dernier (20)

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 

Beyond Horizontal Scalability: Concurrency and Messaging Using Spring

  • 1. Beyond Horizontal Scalability: Concurrency & Messaging Using Spring Bruce Snyder, Senior Software Engineer, SpringSource/VMware Friday, July 8, 2011
  • 2. Problem Statement • Software systems are growing larger than ever before – Virtual Machines – Physical Machines – More CPUs – Multi-core CPUs – More requests – More data • With so many hardware changes, shouldn’t our software practices change too? Friday, July 8, 2011
  • 3. Typical Application Layers 3 Friday, July 8, 2011
  • 4. Typical Code Construction • Command-and-control scheme – One method calls another – Blocking calls • Assumptions – One task takes place at a time – The order of operations in known – The provider of a particular function is known – All execution happens in a single JVM 4 Friday, July 8, 2011
  • 5. Typical Component Interaction • Single memory space • Using the call stack • Sequential execution • Assumptions – No separation between: • Knowing what needs to happen next • Knowing which method to invoke – Interactions are always known at compile time 5 Friday, July 8, 2011
  • 6. Typical Assumptions • All work must take place in a single call stack • Example: – Receive request – Verify data – Save data – Query data – Generate PDF – Send email – Render response 6 Friday, July 8, 2011
  • 7. • The higher the number of assumptions, the more tightly coupled the system 7 Friday, July 8, 2011
  • 8. Typical Client Request 8 Friday, July 8, 2011
  • 9. Typical Request Growth 9 Friday, July 8, 2011
  • 10. Typical Strategy For Horizontal Scaling 10 Friday, July 8, 2011
  • 11. Typical Assumptions • All work must take place on a single machine • Example: – Receive request – Verify data – Save data – Query data – Generate PDF – Send email – Render response 11 Friday, July 8, 2011
  • 12. Treating the Symptoms • Horizontal scale is good to a point – Treat the symptoms instead of fixing the cause of the illness • Throughput of functions should not equal response time! • This is not the case at forward-thinking companies – Amazon.com 12 Friday, July 8, 2011
  • 13. The Problem With Distributed Systems • Most developers don’t understand them – Call stack provides specific interaction style – Most object-oriented systems focus on structure vs. interaction • Interaction becomes more important than structure – Mediator pattern - encapsulates how objects interact – Observer pattern - notifies dependent objects of state change • The real point of service-orientated design – Composition rules are rather simple – Loosely coupled interaction becomes very important 13 Friday, July 8, 2011
  • 14. Is There a Better Solution? • Insert a level of indirection – Remove direct interaction between components – Extract the interaction into a separate element – Enterprise Integration Patterns (EIP) • http://enterpriseintegrationpatterns.com/ • Simplify the rules of component interaction – Remove the coordination and continuation style of interaction – Just send data 14 Friday, July 8, 2011
  • 15. Concurrency • Concurrency is a style of asynchronous execution 15 Friday, July 8, 2011
  • 16. Concurrency With Spring • Spring provides the TaskExecutor interface – Abstracts the execution of a Runnable, i.e., asynchronous work – SimpleAsyncTaskExecutor • Creates a new thread for each task – ThreadPoolTaskExecutor • Uses a JDK 1.5 ThreadPoolExecutor to create a pool of threads – org.springframework.scheduling.concurrent package • Many scheduling related utility classes – WorkManagerTaskExecutor • Delegates to a JCA 1.5 CommonJ WorkManager 16 Friday, July 8, 2011
  • 17. JDK ExecutorService ExecutorService executorService = Executors.newSingleThreadExecutor(); executorService.execute(task); executorService.shutdown(); executorService = Executors.newFixedThreadPool(10); executorService.execute(task); executorService.shutdown(); int corePoolSize = 5; int maxPoolSize = 10; long keepAliveTime = 5000; executorService = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); executorService.execute(task); executorService.shutdown(); 17 Friday, July 8, 2011
  • 18. Spring TaskExecutor <bean id="myTask" class="org.bsnyder.spring.concurrency.MyTask" /> <bean id="springConcurrencyExample" class="org.bsnyder.spring.concurrency.SpringConcurrencyExample" /> <bean id="simpleAsyncTaskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor" p:daemon="false" /> <bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" p:corePoolSize="5" p:maxPoolSize="10" p:queueCapacity="30" /> 18 Friday, July 8, 2011
  • 19. Spring TaskExecutor public class SpringConcurrencyExample { ! @Autowired ! private Runnable task; ! @Autowired ! private SimpleAsyncTaskExecutor simpleAsyncTaskExecutor; ! @Autowired ! private ThreadPoolTaskExecutor threadPoolTaskExecutor; ! ! public void runExamples() { ! ! simpleAsyncTaskExecutor.execute(task); ! ! threadPoolTaskExecutor.execute(task); ! } ! ! public static void main(String[] args) { ! ! ApplicationContext context = ! ! ! new ClassPathXmlApplicationContext("/META-INF/spring/executor-context.xml", SpringConcurrencyExample.class); ! ! SpringConcurrencyExample example = context.getBean(SpringConcurrencyExample.class); ! ! example.runExamples(); ! } } 19 Friday, July 8, 2011
  • 20. Messaging • Messaging is a style of communication • Often used for integration purposes 20 Friday, July 8, 2011
  • 21. Messaging With Spring • JMS Support – JmsTemplate for sync send and receive – DefaultMessageListenerContainer and SimpleMessageListenerContainer for async receive • javax.jms.MessageListener • org.springframework.jms.listener.SessionAwareMessageListener • org.springframework.jms.listener.adapter.MessageListenerAdapter • AMQP Support – RabbitTemplate for sync send and receive – SimpleMessageListenerContainer for async receive • org.springframework.amqp.core.MessageListener • org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter 21 Friday, July 8, 2011
  • 22. Spring JmsTemplate Synchronous <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" /> <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="FOO.TEST" /> </bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" p:connectionFactory-ref="connectionFactory" p:defaultDestination-ref="destination" /> <bean id="messageProducer" class="org.bsnyder.spring.jms.producer.SimpleMessageProducer" p:jmsTemplate-ref="jmsTemplate" /> 22 Friday, July 8, 2011
  • 23. Spring JmsTemplate Synchronous // Use the default destination jmsTemplate.convertAndSend("Hello World!"); // Use a different destination jmsTemplate.convertAndSend(“TEST.BAR”, “Hello World!”); // Use a different destination String textMessage1 = (String) jmsTemplate.receiveAndConvert(); // Use a different destination String textMessage2 = (String) jmsTemplate.receiveAndConvert(“TEST.BAR”); 23 Friday, July 8, 2011
  • 24. DefaultMessageListenerContainer Asynchronous • XML configuration <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" /> <bean id="messageListener" class="org.bsnyder.spring.jms.listener.SimpleMessageListener" /> <jms:listener-container concurrency="5-10"> <jms:listener destination="FOO.TEST" ref="messageListener"/> </jms:listener-container> 24 Friday, July 8, 2011
  • 25. Spring RabbitTemplate Synchronous <bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin"> <constructor-arg ref="connectionFactory"/> </bean> <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory" p:host="localhost" p:port="5672" p:username="guest" p:password="guest"/> <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate" p:connectionFactory-ref="connectionFactory" p:routingKey="TEST.FOO" p:queue="TEST.FOO" /> <bean id="messageProducer" class="org.bsnyder.spring.amqp.producer.SimpleMessageProducer" p:rabbitAdmin-ref="rabbitAdmin" p:rabbitTemplate-ref="rabbitTemplate"/> 25 Friday, July 8, 2011
  • 26. Spring RabbitTemplate Synchronous // Use the default destination rabbitTemplate.convertAndSend("Hello World!"); // Use a different destination rabbitTemplate.send(“TEST.FOO”, “TEST.FOO”, message); // Use a different destination Message message1 = rabbitTemplate.receiveAndConvert(); // Use a different destination String textMessage2 = (String) rabbitTemplate.receive(“TEST.FOO”); 26 Friday, July 8, 2011
  • 27. SimpleMessageListenerContainer Asynchronous <bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory" p:host="localhost" p:port="5672" p:username="guest" p:password="guest"/> <bean id="rabbitAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin"> <constructor-arg ref="connectionFactory"/> </bean> <bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate" p:connectionFactory-ref="connectionFactory" p:routingKey="TEST.FOO" p:queue="TEST.FOO" /> <bean id="messageListener" class="org.bsnyder.spring.amqp.listener.SimpleMessageListener" p:rabbitTemplate-ref="rabbitTemplate"/> <bean id="listenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer" p:connectionFactory-ref="connectionFactory" p:queueName="TEST.FOO" p:concurrentConsumers="5" p:listener="messageListener" /> 27 Friday, July 8, 2011
  • 28. Best of Both Worlds • What if concurrency and messaging was provided together? 28 Friday, July 8, 2011
  • 29. Spring Integration • A framework for integration • Styles of integration – Intra-application integration – Inter-application integration – External system integration 29 Friday, July 8, 2011
  • 30. Enterprise Integration Patterns (EIP) http://enterpriseintegrationpatterns.com/ 30 Friday, July 8, 2011
  • 31. Spring Integration • Provides both concurrency and messaging – Message Endpoints • Connections between services – Channel Adapters • Adapter between application and message broker – Messaging Gateways • Provides uni-directional or bi-directional messaging – Service Activators • Invokes a services based on an incoming message – Routers • Determines where to dispatch a message – Splitters and Aggregators • Breaks up a message and reassembles it after processing 31 Friday, July 8, 2011
  • 32. Spring Integration • Supports – AMQP – Email – File system – Gemfire – JMS – JMX – MongoDB – Redis – Spring Batch – Testing – Web Services 32 Friday, July 8, 2011
  • 33. Spring Integration 33 Friday, July 8, 2011
  • 34. Spring Integration 34 Friday, July 8, 2011
  • 35. Spring Integration 35 Friday, July 8, 2011
  • 36. Spring Integration 36 Friday, July 8, 2011
  • 37. Spring Integration 37 Friday, July 8, 2011
  • 38. Spring Integration 38 Friday, July 8, 2011
  • 39. Spring Integration 39 Friday, July 8, 2011
  • 40. Spring Integration 40 Friday, July 8, 2011
  • 41. Spring Integration 41 Friday, July 8, 2011
  • 42. Spring Integration 42 Friday, July 8, 2011
  • 43. Your Coffee Shop Does Not Use 2PC • Order is accepted • Cup is labeled and placed in the queue • Money is exchanged • Coffee drink is processed • Multiple baristas = competing consumers • Drinks are processed out of order = correlation id (label) • Cannot pay for drink = discard (write-off) • Erroneous drink = retry • Drink machine fails = compensating action (refund, etc.) 43 Friday, July 8, 2011
  • 44. Conversation Pattern • Interaction between two parties – Short synchronous interaction – Longer asynchronous interaction • Other examples – Amazon.com 44 Friday, July 8, 2011
  • 45. Cafe Demo 45 Friday, July 8, 2011
  • 46. Thank You! Q&A Friday, July 8, 2011