SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Gearman nu este ceva ce trebuie de lasat in frunzis!
Ce criterii descriu serverul de job-uri Gearman
Open Source                  Wow, asta e un news bun!
Multi-language               C, PHP, Perl, MySql UDF, Python, Java, Ruby, Go
Flexible                     Nu esti legat de nici un design pattern specific
Fast                         Are un protocol simplu si este realizat in C
Embeddable                   Introducerea intr-o aplicatie este triviala
No single point of failure   Actioneaza intr-un mod tolerant la erori
Ce trebuie de luat in considerare inainte sa
                 incepem

1. Gearman transmite datele de la client la worker in forma de
string.

    SOLUTIE: folositi serializarea datelor

    BEST PRACTICE: MsgPack- serializare binary foarte rapida(la
                     fel realizata pentru multiple limbaje)


2. Gearman necesita workeri porniti, insa ei pot “muri” din mai
    multe   cauze.

    SOLUTIE: supravegheati workerii cu alti daemoni

    BEST PRACTICE: folositi Supervisor pentru supraveghere
Kick Ass Start...

# puteti descarca sursa http://gearman.org/index.php?id=download
sudo apt-get install gearman libgearman-dev

# compilati si instalati biblioteca p-tru PHP
pecl download gearman-0.8.0
tar -xvf gearman-0.8.0.tgz
cd gearman-0.8.0
phpize
./configure
make
make install

# porniti serverul (inserati -vvv pentru debugging)
sudo gearmand -d -u root
Ce trebuie sa stim despre modul de lucru
1. Lucrul consta din 2 parti(+ Gearman ca mediator): Client si Worker

2. Internal, Gearman se poate compara cu Priority Queue(Coada, FIFO)

3. Se imparte in 3 tiputi dupa prioritate:
    I- Low
    II- Normal
    III- High

4. Se imparte in 2 tipuri dupa modul de rulare:
    I- Normal
    II- Background(nu interactioneaza cu clientul)

5. Se imparte in 2 tipuri dupa modul de executie:
    I- Sync (sincronizate)
    II- Async (paralele)
Din ce este constituita partea PHP


GearmanClient- este cel ce adauga taskuri in gearman p-tru workeri

GearmanTask- obiectul taskului care contine metodele necesare p-tru lucru

GearmanWorker- workerul(daemon) care primeste job-uri de la clienti

GearmanJob- este obiectul job-ului transmis de la client si este emis ca
            argument in callback-ul inregistrat de worker p-tru o functie

+ GearmanException ca exceptie folosita de aceasta biblioteca
Exemple de taskuri p-tru Gearman

Task sincronizat:

$rev = $client->do(
     "reverse",
     msgpck_pack(['v1', 'v2' /* ... much more */])
);

Task Paralel:

for($i = 0; $i < 10; $i++) {
     $client->addTask("reverse", "Hello World!");
}

P.S
      Setarea clientului din php:
          $client = new GearmanClient();
          $client->addServer(); // localhost by default
Exemplu de worker p-tru Gearman
// setam workerul
$worker = new GearmanWorker();
$worker->addServer(); // localhost by default

// adaugam o functie
$worker->addFunction("reverse", "reverse_fn");

// ciclu in care workerul asteapta joburi si controleaza starea conexiunii
// cu serverul Gearman
while ($worker->work()) {
  if ($worker->returnCode() != GEARMAN_SUCCESS) beak;
}

// definim functia
function reverse_fn($job)
{
  $result= strrev($job->workload(););
  return $result;
}
Leave oldies at museum!!!
Leave oldies at museum!!!

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Gearman presentation yopeso

  • 1. Gearman nu este ceva ce trebuie de lasat in frunzis!
  • 2. Ce criterii descriu serverul de job-uri Gearman Open Source Wow, asta e un news bun! Multi-language C, PHP, Perl, MySql UDF, Python, Java, Ruby, Go Flexible Nu esti legat de nici un design pattern specific Fast Are un protocol simplu si este realizat in C Embeddable Introducerea intr-o aplicatie este triviala No single point of failure Actioneaza intr-un mod tolerant la erori
  • 3. Ce trebuie de luat in considerare inainte sa incepem 1. Gearman transmite datele de la client la worker in forma de string. SOLUTIE: folositi serializarea datelor BEST PRACTICE: MsgPack- serializare binary foarte rapida(la fel realizata pentru multiple limbaje) 2. Gearman necesita workeri porniti, insa ei pot “muri” din mai multe cauze. SOLUTIE: supravegheati workerii cu alti daemoni BEST PRACTICE: folositi Supervisor pentru supraveghere
  • 4. Kick Ass Start... # puteti descarca sursa http://gearman.org/index.php?id=download sudo apt-get install gearman libgearman-dev # compilati si instalati biblioteca p-tru PHP pecl download gearman-0.8.0 tar -xvf gearman-0.8.0.tgz cd gearman-0.8.0 phpize ./configure make make install # porniti serverul (inserati -vvv pentru debugging) sudo gearmand -d -u root
  • 5. Ce trebuie sa stim despre modul de lucru 1. Lucrul consta din 2 parti(+ Gearman ca mediator): Client si Worker 2. Internal, Gearman se poate compara cu Priority Queue(Coada, FIFO) 3. Se imparte in 3 tiputi dupa prioritate: I- Low II- Normal III- High 4. Se imparte in 2 tipuri dupa modul de rulare: I- Normal II- Background(nu interactioneaza cu clientul) 5. Se imparte in 2 tipuri dupa modul de executie: I- Sync (sincronizate) II- Async (paralele)
  • 6. Din ce este constituita partea PHP GearmanClient- este cel ce adauga taskuri in gearman p-tru workeri GearmanTask- obiectul taskului care contine metodele necesare p-tru lucru GearmanWorker- workerul(daemon) care primeste job-uri de la clienti GearmanJob- este obiectul job-ului transmis de la client si este emis ca argument in callback-ul inregistrat de worker p-tru o functie + GearmanException ca exceptie folosita de aceasta biblioteca
  • 7. Exemple de taskuri p-tru Gearman Task sincronizat: $rev = $client->do( "reverse", msgpck_pack(['v1', 'v2' /* ... much more */]) ); Task Paralel: for($i = 0; $i < 10; $i++) { $client->addTask("reverse", "Hello World!"); } P.S Setarea clientului din php: $client = new GearmanClient(); $client->addServer(); // localhost by default
  • 8. Exemplu de worker p-tru Gearman // setam workerul $worker = new GearmanWorker(); $worker->addServer(); // localhost by default // adaugam o functie $worker->addFunction("reverse", "reverse_fn"); // ciclu in care workerul asteapta joburi si controleaza starea conexiunii // cu serverul Gearman while ($worker->work()) { if ($worker->returnCode() != GEARMAN_SUCCESS) beak; } // definim functia function reverse_fn($job) { $result= strrev($job->workload();); return $result; }
  • 9. Leave oldies at museum!!!
  • 10. Leave oldies at museum!!!