SlideShare une entreprise Scribd logo
1  sur  20
Télécharger pour lire hors ligne
Twisted
                       Présentation & Usecases




Monday, June 1, 2009
Twisted?

                       • Framework pour applis réseau
                       • 100% Python, quelques optimisations en C
                       • Projet opensource stable, bien maintenu
                       • Programmation asynchrone

Monday, June 1, 2009
Asynchrone?

                       • Synonymes : “event-driven”, “non-blocking”
                       • Toutes les fonctions doivent retourner
                         “rapidement”
                       • 1 seul thread
                       • Reactor pattern

Monday, June 1, 2009
Sync vs. Async
         def google_sync(search)
             html = urllib.urlopen(“http://google.com/?q=”+search”).read()
             return [r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]

         print google_sync(“pycon fr”)
         print google_sync(“pycon us”)




         def google_async(search)
             async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”)
             async_call.addCallback(gotresults)

         def gotresults(html)
             print [r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]

         google_async(“pycon fr”)
         google_async(“pycon us”)

         twisted.internet.reactor.run()



Monday, June 1, 2009
“C’est plus compliqué!”
                       • Oui mais
                       • 100 requêtes en parallèle ?




Monday, June 1, 2009
“C’est plus compliqué!”
                       • Oui mais
                       • 100 requêtes en parallèle ?
         results = []

         class google_thread(Thread):
             def __init__(self,search):
                 self.search = search

                def run():
                    html = urllib.urlopen(“http://google.com/?q=”+search”).read()
                    results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)])

         threads = [google_thread(“pycon fr”), google_thread(“pycon us”)]
         [thread.start() for thread in threads]
         print results



Monday, June 1, 2009
Et là ?
         results = []

         class google_thread(Thread):
             def __init__(self,search):
                 self.search = search

                def run():
                    html = urllib.urlopen(“http://google.com/?q=”+search”).read()
                    results.append(“Resultats pour ‘%s’ :” % self.search)
                    results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)])

         threads = [google_thread(“pycon fr”), google_thread(“pycon us”)]
         [thread.start() for thread in threads]




Monday, June 1, 2009
Thread safety
         results = []

         class google_thread(Thread):
             def __init__(self,search):
                 self.search = search

                def run():
                    html = urllib.urlopen(“http://google.com/?q=”+search”).read()
                    acquire_lock(results)
                    results.append(“Resultats pour ‘%s’ :” % self.search)
                    results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)])
                    release_lock(results)

         threads = [google_thread(“pycon fr”), google_thread(“pycon us”)]
         [thread.start() for thread in threads]




Monday, June 1, 2009
Thread safety

                       • Locks
                       • Queues
                       • Semaphores
                       • ...

Monday, June 1, 2009
Thread safety




Monday, June 1, 2009
Version asynchrone

         def google_async(search)
             async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”)
             async_call.addCallback(gotresults)

         def gotresults(html)
             print [r[1] for r in re.split(“<h3>(.*?)</h3>”)]

         google_async(“pycon fr”)
         google_async(“pycon us”)

         twisted.internet.reactor.run()




Monday, June 1, 2009
Version asynchrone
                       • 1 seul thread!
         results = []

         def google_async(search)
             async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”)
             async_call.addCallback(gotresults,search)

         def gotresults(html,search)
             results.append(“Resultats pour ‘%s’ :” % search)
             results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)])

         google_async(“pycon fr”)
         google_async(“pycon us”)

         twisted.internet.reactor.run()




Monday, June 1, 2009
Deferreds
          def google_async(search)
              async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”)
              async_call.addCallback(gotresults)




                       • Promesse d’un resultat futur
                       • addCallback
                       • addErrback
                       • Chains
                       • DeferredLists
Monday, June 1, 2009
Deferreds




Monday, June 1, 2009
Reactor

                       • “Dont call us, we’ll call you”
                       • Event Loop
                       • S’occupe d’appeller tous les callbacks
                       • “Remplace” le GIL, thread switching
                       • “Pluggable” : select/poll, epoll, GUI, ...

Monday, June 1, 2009
Autres avantages
                       • Librairie très complète : HTTP, SSH, IRC,
                         DNS, IMAP, Jabber, SMTP, Telnet, ...
                       • Ne pas réinventer la roue / patterns
                       • Déploiement rapide d’applis complexes
                       • Threadpool
                       • Encapsulation/design
                       • Moins de surprises
Monday, June 1, 2009
Utilisateurs de Twisted
                       • Apple
                       • NASA
                       • Justin.tv
                       • Bittorrent / Zope / Freevo / Buildbot / ...
                       • ???
                       • Jamendo :)
Monday, June 1, 2009
Twisted chez Jamendo

                       • Upload servers
                       • Log servers
                       • Radio servers
                       • Widget servers
                       • Streaming / Download servers

Monday, June 1, 2009
Download servers
                       • 10k lignes de code
                       • HTTP “sécurisé”, download queues
                       • FTP avec virtual filesystem
                       • Génération de zips à la volée
                       • Seeds BitTorrent
                       • Logs UDP / Monitoring
                       • twisted.manhole
Monday, June 1, 2009
Merci de votre attention!

                                 Sylvain Zimmer
                         sylvain@jamendo.com
                            twitter.com/sylvinus




Monday, June 1, 2009

Contenu connexe

Similaire à Twisted presentation & Jamendo usecases

[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) Johnny Sung
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In BrowsersGoogleTecTalks
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsersjeresig
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPPStoyan Zhekov
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0GrUSP
 
Generator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersGenerator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersHiroshi Ono
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptjeresig
 
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)PROIDEA
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to GoCloudflare
 
Performance tests with Gatling (extended)
Performance tests with Gatling (extended)Performance tests with Gatling (extended)
Performance tests with Gatling (extended)Andrzej Ludwikowski
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoxeo Corp
 
2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdfUtabeUtabe
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about goDvir Volk
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)Wilfried Schobeiri
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015Igor Laborie
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会Ippei Ogiwara
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with CometSimon Willison
 

Similaire à Twisted presentation & Jamendo usecases (20)

[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
 
Performance Improvements In Browsers
Performance Improvements In BrowsersPerformance Improvements In Browsers
Performance Improvements In Browsers
 
Performance Improvements in Browsers
Performance Improvements in BrowsersPerformance Improvements in Browsers
Performance Improvements in Browsers
 
Microblogging via XMPP
Microblogging via XMPPMicroblogging via XMPP
Microblogging via XMPP
 
Symfony 2.0
Symfony 2.0Symfony 2.0
Symfony 2.0
 
Generator Tricks for Systems Programmers
Generator Tricks for Systems ProgrammersGenerator Tricks for Systems Programmers
Generator Tricks for Systems Programmers
 
Performance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScriptPerformance, Games, and Distributed Testing in JavaScript
Performance, Games, and Distributed Testing in JavaScript
 
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
JDD 2017: Performance tests with Gatling (Andrzej Ludwikowski)
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
Performance tests with Gatling (extended)
Performance tests with Gatling (extended)Performance tests with Gatling (extended)
Performance tests with Gatling (extended)
 
Voicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.comVoicecon - Mashups with Tropo.com
Voicecon - Mashups with Tropo.com
 
2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf2015-GopherCon-Talk-Uptime.pdf
2015-GopherCon-Talk-Uptime.pdf
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
How go makes us faster (May 2015)
How go makes us faster (May 2015)How go makes us faster (May 2015)
How go makes us faster (May 2015)
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with Comet
 

Plus de Sylvain Zimmer

Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Ranking the Web with Spark
Ranking the Web with SparkRanking the Web with Spark
Ranking the Web with SparkSylvain Zimmer
 
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013Sylvain Zimmer
 
140byt.es - The Dark Side of Javascript
140byt.es - The Dark Side of Javascript140byt.es - The Dark Side of Javascript
140byt.es - The Dark Side of JavascriptSylvain Zimmer
 
Joshfire Framework 0.9 Technical Overview
Joshfire Framework 0.9 Technical OverviewJoshfire Framework 0.9 Technical Overview
Joshfire Framework 0.9 Technical OverviewSylvain Zimmer
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSSylvain Zimmer
 
no.de quick presentation at #ParisJS 4
no.de quick presentation at #ParisJS 4no.de quick presentation at #ParisJS 4
no.de quick presentation at #ParisJS 4Sylvain Zimmer
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJSSylvain Zimmer
 
Archicamp présentation
Archicamp présentationArchicamp présentation
Archicamp présentationSylvain Zimmer
 

Plus de Sylvain Zimmer (9)

Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Ranking the Web with Spark
Ranking the Web with SparkRanking the Web with Spark
Ranking the Web with Spark
 
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013
[fr] Introduction et Live-code Backbone.js à DevoxxFR 2013
 
140byt.es - The Dark Side of Javascript
140byt.es - The Dark Side of Javascript140byt.es - The Dark Side of Javascript
140byt.es - The Dark Side of Javascript
 
Joshfire Framework 0.9 Technical Overview
Joshfire Framework 0.9 Technical OverviewJoshfire Framework 0.9 Technical Overview
Joshfire Framework 0.9 Technical Overview
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJS
 
no.de quick presentation at #ParisJS 4
no.de quick presentation at #ParisJS 4no.de quick presentation at #ParisJS 4
no.de quick presentation at #ParisJS 4
 
Web Crawling with NodeJS
Web Crawling with NodeJSWeb Crawling with NodeJS
Web Crawling with NodeJS
 
Archicamp présentation
Archicamp présentationArchicamp présentation
Archicamp présentation
 

Dernier

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Dernier (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
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
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
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
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Twisted presentation & Jamendo usecases

  • 1. Twisted Présentation & Usecases Monday, June 1, 2009
  • 2. Twisted? • Framework pour applis réseau • 100% Python, quelques optimisations en C • Projet opensource stable, bien maintenu • Programmation asynchrone Monday, June 1, 2009
  • 3. Asynchrone? • Synonymes : “event-driven”, “non-blocking” • Toutes les fonctions doivent retourner “rapidement” • 1 seul thread • Reactor pattern Monday, June 1, 2009
  • 4. Sync vs. Async def google_sync(search) html = urllib.urlopen(“http://google.com/?q=”+search”).read() return [r[1] for r in re.split(“<h3>(.*?)</h3>”,html)] print google_sync(“pycon fr”) print google_sync(“pycon us”) def google_async(search) async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”) async_call.addCallback(gotresults) def gotresults(html) print [r[1] for r in re.split(“<h3>(.*?)</h3>”,html)] google_async(“pycon fr”) google_async(“pycon us”) twisted.internet.reactor.run() Monday, June 1, 2009
  • 5. “C’est plus compliqué!” • Oui mais • 100 requêtes en parallèle ? Monday, June 1, 2009
  • 6. “C’est plus compliqué!” • Oui mais • 100 requêtes en parallèle ? results = [] class google_thread(Thread): def __init__(self,search): self.search = search def run(): html = urllib.urlopen(“http://google.com/?q=”+search”).read() results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]) threads = [google_thread(“pycon fr”), google_thread(“pycon us”)] [thread.start() for thread in threads] print results Monday, June 1, 2009
  • 7. Et là ? results = [] class google_thread(Thread): def __init__(self,search): self.search = search def run(): html = urllib.urlopen(“http://google.com/?q=”+search”).read() results.append(“Resultats pour ‘%s’ :” % self.search) results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]) threads = [google_thread(“pycon fr”), google_thread(“pycon us”)] [thread.start() for thread in threads] Monday, June 1, 2009
  • 8. Thread safety results = [] class google_thread(Thread): def __init__(self,search): self.search = search def run(): html = urllib.urlopen(“http://google.com/?q=”+search”).read() acquire_lock(results) results.append(“Resultats pour ‘%s’ :” % self.search) results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]) release_lock(results) threads = [google_thread(“pycon fr”), google_thread(“pycon us”)] [thread.start() for thread in threads] Monday, June 1, 2009
  • 9. Thread safety • Locks • Queues • Semaphores • ... Monday, June 1, 2009
  • 11. Version asynchrone def google_async(search) async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”) async_call.addCallback(gotresults) def gotresults(html) print [r[1] for r in re.split(“<h3>(.*?)</h3>”)] google_async(“pycon fr”) google_async(“pycon us”) twisted.internet.reactor.run() Monday, June 1, 2009
  • 12. Version asynchrone • 1 seul thread! results = [] def google_async(search) async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”) async_call.addCallback(gotresults,search) def gotresults(html,search) results.append(“Resultats pour ‘%s’ :” % search) results.append([r[1] for r in re.split(“<h3>(.*?)</h3>”,html)]) google_async(“pycon fr”) google_async(“pycon us”) twisted.internet.reactor.run() Monday, June 1, 2009
  • 13. Deferreds def google_async(search) async_call = twisted.web.client.getPage(“http://google.com/?q=”+search”) async_call.addCallback(gotresults) • Promesse d’un resultat futur • addCallback • addErrback • Chains • DeferredLists Monday, June 1, 2009
  • 15. Reactor • “Dont call us, we’ll call you” • Event Loop • S’occupe d’appeller tous les callbacks • “Remplace” le GIL, thread switching • “Pluggable” : select/poll, epoll, GUI, ... Monday, June 1, 2009
  • 16. Autres avantages • Librairie très complète : HTTP, SSH, IRC, DNS, IMAP, Jabber, SMTP, Telnet, ... • Ne pas réinventer la roue / patterns • Déploiement rapide d’applis complexes • Threadpool • Encapsulation/design • Moins de surprises Monday, June 1, 2009
  • 17. Utilisateurs de Twisted • Apple • NASA • Justin.tv • Bittorrent / Zope / Freevo / Buildbot / ... • ??? • Jamendo :) Monday, June 1, 2009
  • 18. Twisted chez Jamendo • Upload servers • Log servers • Radio servers • Widget servers • Streaming / Download servers Monday, June 1, 2009
  • 19. Download servers • 10k lignes de code • HTTP “sécurisé”, download queues • FTP avec virtual filesystem • Génération de zips à la volée • Seeds BitTorrent • Logs UDP / Monitoring • twisted.manhole Monday, June 1, 2009
  • 20. Merci de votre attention! Sylvain Zimmer sylvain@jamendo.com twitter.com/sylvinus Monday, June 1, 2009