SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Northeast PHP August 12, 2012




A Job Server to Scale
       By Mike Willbanks
   Sr. Web Architect Manager
       NOOK Developer
Housekeeping…


    • Talk
       Slides will be online later!

    • Me
       Sr. Web Architect Manager at NOOK Developer

       Former MNPHP Organizer

       Open Source Contributor (Zend Framework and various others)

       Where you can find me:
        • Twitter: mwillbanks          G+: Mike Willbanks
        • IRC (freenode): mwillbanks   Blog: http://blog.digitalstruct.com
        • GitHub: https://github.com/mwillbanks


2
Agenda


    • What is Gearman
       A general introduction

    • Main Concepts
       Looking overall at how gearman works for you.

    • Quick Start
       Make it go do something.

    • Digging in
       A detailed look into gearman.

    • PHP Integration
       How you should work with it in PHP including use cases and samples.

    • Questions
       Although you can bring them up at anytime!
3
What is Gearman?
Official Statement
What it means
Visual understanding
Platforms
Official Statement




    “Gearman provides a generic application framework to farm
       out work to other machines or processes that are better
     suited to do the work. It allows you to do work in parallel,
      to load balance processing, and to call functions between
                             languages.”




5
What it Means


    • Gearman consists of a daemon, client and worker
       At the core, they are simply small programs.

    • The daemon handles the negotiation of work
       Workers and Clients

    • The worker does the work
    • The client requests work to be done




6
In Pictures




7
Platforms


    • OS
       Linux

       Windows (cygwin)

    • API implementations available
       PHP

       Perl

       Java

       Ruby

       Python




8
Main Concepts
Client -> Daemon -> Worker communication
Distributed Model
Client -> Daemon -> Worker communication




10
Distributed Model




11
Quick Start
Installation
Simple Bash Example
PHP Related (sorry, I’m all about the PHP)
Installation


     • Head to gearman.org
     • Click Download
     • Click on the LaunchPad download
     • Download the Binary
     • Unpack the binary
     • ./configure && make && make install
     • Bam! You’re off!
        For more advanced configuration see ./configure –help

     • Starting
        gearmand -d
13
Gearmand Usage


     • gearmand
        -d          Run as background daemon
        -u [user]   Run as user
        -L [host]   Listen on host/ip
        -p [port]   Listen on port
        -t [threads] Number of threads to use

        -v[vv]      Verbosity




14
Simple Bash Example


     • Starting the Daemon
        gearmand –d

     • Worker – command line style
        nohup gearman -w -f wc -- wc –l &
         • Run the worker in the background.

     • Client – command line style
        gearman -f wc < /etc/passwd
         • Outputs the number of lines.




15
Gearman Client Command Line Usage


     • gearman
        -w          Worker mode
        -f [function] Function name to use

        -h [host]    Job server host
        -p [port]    Job server port
        -t [timeout] Timeout in milliseconds

        -H           Full options for both clients and workers.




16
Digging In
Persistence
Workers
Monitoring
Persistence


     • Gearman by default is an in-memory queue
        Leaving this as the default is ideal; however, does not work in all
        environments.
     • Persistent Queues
        Libdrizzle

        Libsqlite3

        Libmemcached

        Postgres

        TokyoCabinet

        MySQL

        Redis
18
Getting Up and Running with Persistence


     • Persistent queues require specific configuration during the
       compilation of gearman.
     • Additionally, arguments to the gearman daemon need to be
       passed to talk to the specific persistence layer.
     • Each persistence layer is actually built as a plugin to
       gearmand
        http://bazaar.launchpad.net/~tangent-org/gearmand/trunk/files/
        head:/libgearman-server/plugins/queue/




19
Configuration Options




20
Clients


     • Clients send work to the gearmand server
        This is called the workload; it can be anything that can become a
        string.
        Utilize an open format; it will make life easier in the event you
        use multiple programming languages, are debugging or the like.
         • XML, JSON, etc.
         • Yes, you can serialize objects if you wanted to.
           –  I recommend against this.




21
Workers


     • Workers are the dudes in the factory doing all the work
     • Generally they will run as a daemon in the background
     • Workers register a function that they perform
        They should ONLY be doing a single task.

        This makes them far easier to manage.

     • The worker does the work and “can” return results
        If you are doing the work asynchronously you generally do not
        return the result.
        Synchronous work you will return the result.




22
Workers – special notes


     • Utilizing the Database
        If you keep a database connection
         • Must have the ability to reconnect to the database.
         • Watch for connection timeouts

     • Handling Memory Leaks
        Watch the amount of memory and detect leaks then kill the
        worker.
     • Request Languages
        PHP for instance, sometimes slows down after hundreds of
        executions, kill it off if you know this will happen.



23
Keeping the Daemon Running


     • Workers sometimes have issues and die, or you need to boot
       them back up after a restart
        Utilizing a service to watch your workers and ensure they are
        always running is a GOOD thing.
     • Supervisord
        Can watch processes, restart them if they die or get killed

        Can manage multiple processes of the same program

        Can start and stop your workers.

        Running: supervisord –c myconfig.conf

     • When running workers, BE SURE to handle KILL signals such
       as SIGKILL.

24
Supervisord Example Add Proram




25
Monitoring


     • Gearman Status
        telnet on port 4730

        Write “STATUS”
         • Gives you the registered functions, number of workers and items in the
           queue.

     • Gearman Monitor – PHP Project
        Basic monitoring; but works and it is open source so you can
        improve it!
        https://github.com/yugene/Gearman-Monitor




26
PHP Integration
Usage (PEAR / PECL)
Frameworks / Integration
Handling Conditions
Use Cases
Usage


     • Two Options
        Net::Gearman (PEAR)
        • Implemented through sockets with PHP.
        • https://pear.php.net/package/Net_Gearman/
        Gearman Extension (PECL)
        • Implemented through the C API from libgearman
        • http://pecl.php.net/package/gearman




28
Frameworks and Integration


     • GearmanManager - agnostic
        https://github.com/brianlmoon/GearmanManager/

     • Zend Framework 1: Zend_Gearman
        https://github.com/mwillbanks/Zend_Gearman

     • Zend Framework 2: mwGearman
        https://github.com/mwillbanks/mwGearman

     • Drupal
        http://drupal.org/node/783294




29
Conditions


     • Watch for Memory Utilization
        Check peak usage then kill and restart the worker

     • Don’t execute too many times
        PHP is not great at unlimited loops

     • Keep your memory free
        Garbage collect when you can!

     • Databases
        Implement a callback to ensure that you do not timeout; otherwise
        implement a reconnection.



30
Images


     • If you resize images on your web server:
        Web servers should serve, not process images.

        Images require a lot of memory AND processing power
         • They are best to be processed on their own!

     • Processing in the Background
        Generally will require a change to your workflow and checking the
        status with XHR to see if the job has been completed.
         • This allows you to process them as you have resources available.
         • Have enough workers to process them “quickly enough”

     • Or just do it synchronously


31
Image Processing Example




32
Image Processing Example




33
Email


     • Sending email and/or generating templates and processing
       variables can take up time, time that is better spent getting
       the user to the next page.
     • The feedback on the mail doesn’t really make a difference
       so it is great to send it to the background.




34
Email Example




35
Email Example




36
Log Analysis / Aggregation


     • Get all of your logs to a single place
     • Process the logs to produce analytical data
     • Impression / Click Tracking
     • Why run introspection over the log file itself?
        Near real-time analysis is possible!




37
Log Analysis / Aggregation




38
Log Analysis / Aggregation




39
Executable Processes


     • You need to run an executable process…
     • This process takes a given name and tells you how many
       processes are running on your worker machine.
        Purely for example purposes; however, you might want to run SaaS
        against a CMS or something to that degree.




40
Executable Process Example




41
Executable Process Example




42
Questions?
These slides will be posted to SlideShare & SpeakerDeck.
  Slideshare: http://www.slideshare.net/mwillbanks

  SpeakerDeck: http://speakerdeck.com/u/mwillbanks

  Twitter: mwillbanks

  G+: Mike Willbanks

  IRC (freenode): mwillbanks

  Blog: http://blog.digitalstruct.com

  GitHub: https://github.com/mwillbanks

Mais conteúdo relacionado

Mais procurados

An Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord AulkeAn Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord Aulke
dpc
 
The View - Best practices to write, deploy and monitor scheduled agents
The View - Best practices to write, deploy and monitor scheduled agentsThe View - Best practices to write, deploy and monitor scheduled agents
The View - Best practices to write, deploy and monitor scheduled agents
Bill Buchan
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
elliando dias
 
Framework and Application Benchmarking
Framework and Application BenchmarkingFramework and Application Benchmarking
Framework and Application Benchmarking
Paul Jones
 

Mais procurados (20)

An Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord AulkeAn Infrastructure for Team Development - Gaylord Aulke
An Infrastructure for Team Development - Gaylord Aulke
 
A simple workflow system using state machines
A simple workflow system using state machinesA simple workflow system using state machines
A simple workflow system using state machines
 
Reactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactorReactive solutions using java 9 and spring reactor
Reactive solutions using java 9 and spring reactor
 
From silex to symfony and viceversa
From silex to symfony and viceversaFrom silex to symfony and viceversa
From silex to symfony and viceversa
 
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
JavaOne 2010: Top 10 Causes for Java Issues in Production and What to Do When...
 
Process Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race conditionProcess Synchronization in operating system | mutex | semaphore | race condition
Process Synchronization in operating system | mutex | semaphore | race condition
 
Ginsbourg.com presentation of open source performance validation
Ginsbourg.com presentation of open source performance validationGinsbourg.com presentation of open source performance validation
Ginsbourg.com presentation of open source performance validation
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
Devel::NYTProf v3 - 200908 (OUTDATED, see 201008)
 
Nimbus project
Nimbus projectNimbus project
Nimbus project
 
Optimize TempDB
Optimize TempDB Optimize TempDB
Optimize TempDB
 
Memory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryMemory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memory
 
Being Agile with Scrum - koders.co
Being Agile with Scrum - koders.coBeing Agile with Scrum - koders.co
Being Agile with Scrum - koders.co
 
Vmth project
Vmth projectVmth project
Vmth project
 
Threads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess CommunicationThreads in Operating System | Multithreading | Interprocess Communication
Threads in Operating System | Multithreading | Interprocess Communication
 
Zero mq logs
Zero mq logsZero mq logs
Zero mq logs
 
The View - Best practices to write, deploy and monitor scheduled agents
The View - Best practices to write, deploy and monitor scheduled agentsThe View - Best practices to write, deploy and monitor scheduled agents
The View - Best practices to write, deploy and monitor scheduled agents
 
Inside The Java Virtual Machine
Inside The Java Virtual MachineInside The Java Virtual Machine
Inside The Java Virtual Machine
 
PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...
PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...
PipelineAI + TensorFlow AI + Spark ML + Kuberenetes + Istio + AWS SageMaker +...
 
Framework and Application Benchmarking
Framework and Application BenchmarkingFramework and Application Benchmarking
Framework and Application Benchmarking
 

Destaque

Power Play in Paraguay
Power Play in ParaguayPower Play in Paraguay
Power Play in Paraguay
Robert Ward
 
Room Service Furniture Rentals
Room Service Furniture RentalsRoom Service Furniture Rentals
Room Service Furniture Rentals
RoomServiceRentals
 
Responding to student writing
Responding to student writingResponding to student writing
Responding to student writing
Elizabeth Nesius
 
Les 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van OrganisatiesLes 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van Organisaties
Mediena Business School
 
Humour Sports
Humour SportsHumour Sports
Humour Sports
7X3or10nR
 

Destaque (20)

Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012Varnish Cache - International PHP Conference Fall 2012
Varnish Cache - International PHP Conference Fall 2012
 
0 to enterprise
0 to enterprise0 to enterprise
0 to enterprise
 
Catalogo di Innova Day Motor Sport Technologies 2013
Catalogo di Innova Day Motor Sport Technologies 2013Catalogo di Innova Day Motor Sport Technologies 2013
Catalogo di Innova Day Motor Sport Technologies 2013
 
Global Bundle Screenshots
Global Bundle ScreenshotsGlobal Bundle Screenshots
Global Bundle Screenshots
 
סטארטאפ - איך? כמה? ולמה
סטארטאפ - איך? כמה? ולמהסטארטאפ - איך? כמה? ולמה
סטארטאפ - איך? כמה? ולמה
 
Google Platform Overview (April 2014)
Google Platform Overview (April 2014)Google Platform Overview (April 2014)
Google Platform Overview (April 2014)
 
Create 2015 Event
Create 2015 EventCreate 2015 Event
Create 2015 Event
 
Startup Innovative Decreto Sviluppo : intervento Prof. Basenghi su Assunzioni
Startup Innovative Decreto Sviluppo : intervento Prof. Basenghi su AssunzioniStartup Innovative Decreto Sviluppo : intervento Prof. Basenghi su Assunzioni
Startup Innovative Decreto Sviluppo : intervento Prof. Basenghi su Assunzioni
 
IRL: How Geeks Undermine Their Presentations & Conversations With Body Language
IRL: How Geeks Undermine Their Presentations & Conversations With Body LanguageIRL: How Geeks Undermine Their Presentations & Conversations With Body Language
IRL: How Geeks Undermine Their Presentations & Conversations With Body Language
 
Balance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game designBalance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game design
 
Dg Analysis Haiti Earthquake 14 Jan2010
Dg Analysis Haiti Earthquake 14 Jan2010Dg Analysis Haiti Earthquake 14 Jan2010
Dg Analysis Haiti Earthquake 14 Jan2010
 
mediator
mediatormediator
mediator
 
Power Play in Paraguay
Power Play in ParaguayPower Play in Paraguay
Power Play in Paraguay
 
Room Service Furniture Rentals
Room Service Furniture RentalsRoom Service Furniture Rentals
Room Service Furniture Rentals
 
Rwservlet
RwservletRwservlet
Rwservlet
 
Memories of Japan
Memories of JapanMemories of Japan
Memories of Japan
 
Responding to student writing
Responding to student writingResponding to student writing
Responding to student writing
 
Les 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van OrganisatiesLes 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van Organisaties
 
About me
About meAbout me
About me
 
Humour Sports
Humour SportsHumour Sports
Humour Sports
 

Semelhante a Gearman - Northeast PHP 2012

Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
Bill Buchan
 
Dev buchan best practices
Dev buchan best practicesDev buchan best practices
Dev buchan best practices
Bill Buchan
 

Semelhante a Gearman - Northeast PHP 2012 (20)

Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Lotuscript for large systems
Lotuscript for large systemsLotuscript for large systems
Lotuscript for large systems
 
Serverless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From ProductionServerless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From Production
 
Dev buchan best practices
Dev buchan best practicesDev buchan best practices
Dev buchan best practices
 
Cognos Performance Tuning Tips & Tricks
Cognos Performance Tuning Tips & TricksCognos Performance Tuning Tips & Tricks
Cognos Performance Tuning Tips & Tricks
 
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling StoryPHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
Intro to Service Worker API and its use cases
Intro to Service Worker API and its use casesIntro to Service Worker API and its use cases
Intro to Service Worker API and its use cases
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
 
Performance tuning Grails applications
Performance tuning Grails applicationsPerformance tuning Grails applications
Performance tuning Grails applications
 
OSMC 2014 | Naemon 1, 2, 3, N by Andreas Ericsson
OSMC 2014 | Naemon 1, 2, 3, N by Andreas EricssonOSMC 2014 | Naemon 1, 2, 3, N by Andreas Ericsson
OSMC 2014 | Naemon 1, 2, 3, N by Andreas Ericsson
 
Best And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM ConnectionsBest And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM Connections
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
Your Inner Sysadmin - Tutorial (SunshinePHP 2015)
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
Dockerize All The Things
Dockerize All The ThingsDockerize All The Things
Dockerize All The Things
 
The Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF AdministratorThe Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
 
IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning IBM Domino / IBM Notes Performance Tuning
IBM Domino / IBM Notes Performance Tuning
 

Mais de Mike Willbanks

Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.
Mike Willbanks
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push Notifications
Mike Willbanks
 
Varnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright CrazyVarnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright Crazy
Mike Willbanks
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
Mike Willbanks
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
Mike Willbanks
 

Mais de Mike Willbanks (19)

2015 ZendCon - Do you queue
2015 ZendCon - Do you queue2015 ZendCon - Do you queue
2015 ZendCon - Do you queue
 
ZF2: Writing Service Components
ZF2: Writing Service ComponentsZF2: Writing Service Components
ZF2: Writing Service Components
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
 
Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push Notifications
 
Varnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright CrazyVarnish, The Good, The Awesome, and the Downright Crazy
Varnish, The Good, The Awesome, and the Downright Crazy
 
Zend Framework Push Notifications
Zend Framework Push NotificationsZend Framework Push Notifications
Zend Framework Push Notifications
 
Mobile Push Notifications
Mobile Push NotificationsMobile Push Notifications
Mobile Push Notifications
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
 
Art Of Message Queues
Art Of Message QueuesArt Of Message Queues
Art Of Message Queues
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
 
The Art of Message Queues
The Art of Message QueuesThe Art of Message Queues
The Art of Message Queues
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
LiquiBase
LiquiBaseLiquiBase
LiquiBase
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Gearman - Northeast PHP 2012

  • 1. Northeast PHP August 12, 2012 A Job Server to Scale By Mike Willbanks Sr. Web Architect Manager NOOK Developer
  • 2. Housekeeping… • Talk   Slides will be online later! • Me   Sr. Web Architect Manager at NOOK Developer   Former MNPHP Organizer   Open Source Contributor (Zend Framework and various others)   Where you can find me: • Twitter: mwillbanks G+: Mike Willbanks • IRC (freenode): mwillbanks Blog: http://blog.digitalstruct.com • GitHub: https://github.com/mwillbanks 2
  • 3. Agenda • What is Gearman   A general introduction • Main Concepts   Looking overall at how gearman works for you. • Quick Start   Make it go do something. • Digging in   A detailed look into gearman. • PHP Integration   How you should work with it in PHP including use cases and samples. • Questions   Although you can bring them up at anytime! 3
  • 4. What is Gearman? Official Statement What it means Visual understanding Platforms
  • 5. Official Statement “Gearman provides a generic application framework to farm out work to other machines or processes that are better suited to do the work. It allows you to do work in parallel, to load balance processing, and to call functions between languages.” 5
  • 6. What it Means • Gearman consists of a daemon, client and worker   At the core, they are simply small programs. • The daemon handles the negotiation of work   Workers and Clients • The worker does the work • The client requests work to be done 6
  • 8. Platforms • OS   Linux   Windows (cygwin) • API implementations available   PHP   Perl   Java   Ruby   Python 8
  • 9. Main Concepts Client -> Daemon -> Worker communication Distributed Model
  • 10. Client -> Daemon -> Worker communication 10
  • 12. Quick Start Installation Simple Bash Example PHP Related (sorry, I’m all about the PHP)
  • 13. Installation • Head to gearman.org • Click Download • Click on the LaunchPad download • Download the Binary • Unpack the binary • ./configure && make && make install • Bam! You’re off!   For more advanced configuration see ./configure –help • Starting   gearmand -d 13
  • 14. Gearmand Usage • gearmand   -d Run as background daemon   -u [user] Run as user   -L [host] Listen on host/ip   -p [port] Listen on port   -t [threads] Number of threads to use   -v[vv] Verbosity 14
  • 15. Simple Bash Example • Starting the Daemon   gearmand –d • Worker – command line style   nohup gearman -w -f wc -- wc –l & • Run the worker in the background. • Client – command line style   gearman -f wc < /etc/passwd • Outputs the number of lines. 15
  • 16. Gearman Client Command Line Usage • gearman   -w Worker mode   -f [function] Function name to use   -h [host] Job server host   -p [port] Job server port   -t [timeout] Timeout in milliseconds   -H Full options for both clients and workers. 16
  • 18. Persistence • Gearman by default is an in-memory queue   Leaving this as the default is ideal; however, does not work in all environments. • Persistent Queues   Libdrizzle   Libsqlite3   Libmemcached   Postgres   TokyoCabinet   MySQL   Redis 18
  • 19. Getting Up and Running with Persistence • Persistent queues require specific configuration during the compilation of gearman. • Additionally, arguments to the gearman daemon need to be passed to talk to the specific persistence layer. • Each persistence layer is actually built as a plugin to gearmand   http://bazaar.launchpad.net/~tangent-org/gearmand/trunk/files/ head:/libgearman-server/plugins/queue/ 19
  • 21. Clients • Clients send work to the gearmand server   This is called the workload; it can be anything that can become a string.   Utilize an open format; it will make life easier in the event you use multiple programming languages, are debugging or the like. • XML, JSON, etc. • Yes, you can serialize objects if you wanted to. –  I recommend against this. 21
  • 22. Workers • Workers are the dudes in the factory doing all the work • Generally they will run as a daemon in the background • Workers register a function that they perform   They should ONLY be doing a single task.   This makes them far easier to manage. • The worker does the work and “can” return results   If you are doing the work asynchronously you generally do not return the result.   Synchronous work you will return the result. 22
  • 23. Workers – special notes • Utilizing the Database   If you keep a database connection • Must have the ability to reconnect to the database. • Watch for connection timeouts • Handling Memory Leaks   Watch the amount of memory and detect leaks then kill the worker. • Request Languages   PHP for instance, sometimes slows down after hundreds of executions, kill it off if you know this will happen. 23
  • 24. Keeping the Daemon Running • Workers sometimes have issues and die, or you need to boot them back up after a restart   Utilizing a service to watch your workers and ensure they are always running is a GOOD thing. • Supervisord   Can watch processes, restart them if they die or get killed   Can manage multiple processes of the same program   Can start and stop your workers.   Running: supervisord –c myconfig.conf • When running workers, BE SURE to handle KILL signals such as SIGKILL. 24
  • 26. Monitoring • Gearman Status   telnet on port 4730   Write “STATUS” • Gives you the registered functions, number of workers and items in the queue. • Gearman Monitor – PHP Project   Basic monitoring; but works and it is open source so you can improve it!   https://github.com/yugene/Gearman-Monitor 26
  • 27. PHP Integration Usage (PEAR / PECL) Frameworks / Integration Handling Conditions Use Cases
  • 28. Usage • Two Options   Net::Gearman (PEAR) • Implemented through sockets with PHP. • https://pear.php.net/package/Net_Gearman/   Gearman Extension (PECL) • Implemented through the C API from libgearman • http://pecl.php.net/package/gearman 28
  • 29. Frameworks and Integration • GearmanManager - agnostic   https://github.com/brianlmoon/GearmanManager/ • Zend Framework 1: Zend_Gearman   https://github.com/mwillbanks/Zend_Gearman • Zend Framework 2: mwGearman   https://github.com/mwillbanks/mwGearman • Drupal   http://drupal.org/node/783294 29
  • 30. Conditions • Watch for Memory Utilization   Check peak usage then kill and restart the worker • Don’t execute too many times   PHP is not great at unlimited loops • Keep your memory free   Garbage collect when you can! • Databases   Implement a callback to ensure that you do not timeout; otherwise implement a reconnection. 30
  • 31. Images • If you resize images on your web server:   Web servers should serve, not process images.   Images require a lot of memory AND processing power • They are best to be processed on their own! • Processing in the Background   Generally will require a change to your workflow and checking the status with XHR to see if the job has been completed. • This allows you to process them as you have resources available. • Have enough workers to process them “quickly enough” • Or just do it synchronously 31
  • 34. Email • Sending email and/or generating templates and processing variables can take up time, time that is better spent getting the user to the next page. • The feedback on the mail doesn’t really make a difference so it is great to send it to the background. 34
  • 37. Log Analysis / Aggregation • Get all of your logs to a single place • Process the logs to produce analytical data • Impression / Click Tracking • Why run introspection over the log file itself?   Near real-time analysis is possible! 37
  • 38. Log Analysis / Aggregation 38
  • 39. Log Analysis / Aggregation 39
  • 40. Executable Processes • You need to run an executable process… • This process takes a given name and tells you how many processes are running on your worker machine.   Purely for example purposes; however, you might want to run SaaS against a CMS or something to that degree. 40
  • 43. Questions? These slides will be posted to SlideShare & SpeakerDeck.  Slideshare: http://www.slideshare.net/mwillbanks  SpeakerDeck: http://speakerdeck.com/u/mwillbanks  Twitter: mwillbanks  G+: Mike Willbanks  IRC (freenode): mwillbanks  Blog: http://blog.digitalstruct.com  GitHub: https://github.com/mwillbanks