Your SlideShare is downloading. ×
Twisted presentation & Jamendo usecases
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Twisted presentation & Jamendo usecases

1,710

Published on

Presentation I gave 30/05/2009 at PyCon FR in Paris http://pycon.fr …

Presentation I gave 30/05/2009 at PyCon FR in Paris http://pycon.fr

I'm not a twisted guru but I tried to explain to the audience as simply as I could the idea of asynchronous programming and the benefits of Twisted.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,710
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
22
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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
  • 10. Thread safety 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
  • 14. Deferreds 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

×