SlideShare a Scribd company logo
1 of 13
quick’n’dirty
TORNADO intro

                   Teemu Kurppa
           www.dirtyaura.org/blog
                   Twitter: teemu

                Huikea Experience
       Social mobile gaming startup
                  www.huikea.com
TORNADO


 scalable, non-blocking web server
TORNADO
  asynchronous requests
  simple clean DB API, no ORM
  programmer-friendly templates
  readable codebase
  proven in production: FriendFeed
TORNADO
Probably good for
real-time web services (hanging GETs to poll)
super-popular dynamic sites
non-web REST services
non-CMS sites
for devs like me
Our Tornado instance
               app



cheap, async call


                    Twitter
Our Tornado instance
db.slow_synchronous_query()

 cheap, async call
                               ?
                     Twitter
Our Tornado instance



               cheap, async calls

  Another Tornado instance
                                    Twitter
db.slow_synchronous_query()
Programmer-friendly templates


    {% for index,value in entries.iteritems() %}
      {{ index }} : {{ value }
    {% end %}


    {% for value in entries %}
      {{ forloop.counter0 }} : {{ value }}
    {% endfor %}
CODE DEMO
class TwitterBadgeHandler(tornado.web.RequestHandler):
   @tornado.web.asynchronous
   def get(self, username):
      http = tornado.httpclient.AsyncHTTPClient()
      url = "http://api.twitter.com/1/users/show/%s.json" % username
      http.fetch(url, callback=self.on_response)

  def on_response(self, response):
    if response.error:
        self.render("badge_error.html")
    else:
        user = tornado.escape.json_decode(response.body)
        self.render("twitter_badge.html", **user)
....
    <style type="text/css">
      .badge {
         background: #{{profile_background_color}} url({{profile_background_image_url}});

... rest of wrapping and css left-out ...

  <div class="badge">
   <img class="badge-photo” src="{{ profile_image_url }}">
   <div class="badge-title">{{ screen_name }}</div>
   <div class="badge-description">{{ description }}</div>
   <div class="clear"></div>
   <div class="badge-status">{{ status['text'] }}</div>
  </div>
Quick'n'Dirty Tornado Intro

More Related Content

Similar to Quick'n'Dirty Tornado Intro

Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
ikailan
 

Similar to Quick'n'Dirty Tornado Intro (20)

Rails missing features
Rails missing featuresRails missing features
Rails missing features
 
Real time server
Real time serverReal time server
Real time server
 
Motion Django Meetup
Motion Django MeetupMotion Django Meetup
Motion Django Meetup
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Integrating WordPress With Web APIs
Integrating WordPress With Web APIsIntegrating WordPress With Web APIs
Integrating WordPress With Web APIs
 
Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365Develop iOS and Android apps with SharePoint/Office 365
Develop iOS and Android apps with SharePoint/Office 365
 
Building TweetEngine
Building TweetEngineBuilding TweetEngine
Building TweetEngine
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 
Api
ApiApi
Api
 
Web performance optimization
Web performance optimizationWeb performance optimization
Web performance optimization
 
Monitoring distributed (micro-)services
Monitoring distributed (micro-)servicesMonitoring distributed (micro-)services
Monitoring distributed (micro-)services
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
Monitoring as Code: Getting to Monitoring-Driven Development - DEV314 - re:In...
 
Rhodes Overview
Rhodes OverviewRhodes Overview
Rhodes Overview
 
Rust: Systems Programming for Everyone
Rust: Systems Programming for EveryoneRust: Systems Programming for Everyone
Rust: Systems Programming for Everyone
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...
Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...
Think Async: Understanding the Complexity of Multithreading - Avi Kabizon & A...
 
Introduction to CloudStack API
Introduction to CloudStack APIIntroduction to CloudStack API
Introduction to CloudStack API
 
Service Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and KubernetesService Discovery using etcd, Consul and Kubernetes
Service Discovery using etcd, Consul and Kubernetes
 
Serverless for Developers
Serverless for DevelopersServerless for Developers
Serverless for Developers
 

More from Teemu Kurppa

More from Teemu Kurppa (7)

React + Redux + d3.js
React + Redux + d3.jsReact + Redux + d3.js
React + Redux + d3.js
 
fast.ai - Learning Deep Learning
fast.ai - Learning Deep Learningfast.ai - Learning Deep Learning
fast.ai - Learning Deep Learning
 
Managing data workflows with Luigi
Managing data workflows with LuigiManaging data workflows with Luigi
Managing data workflows with Luigi
 
Early stage startups
Early stage startupsEarly stage startups
Early stage startups
 
Mobile Startups - Why to focus on mobile?
Mobile Startups - Why to focus on mobile?Mobile Startups - Why to focus on mobile?
Mobile Startups - Why to focus on mobile?
 
Platform = Stage. How to choose a mobile development platform?
Platform = Stage. How to choose a mobile development platform?Platform = Stage. How to choose a mobile development platform?
Platform = Stage. How to choose a mobile development platform?
 
Leaks & Zombies
Leaks & ZombiesLeaks & Zombies
Leaks & Zombies
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Quick'n'Dirty Tornado Intro

  • 1. quick’n’dirty TORNADO intro Teemu Kurppa www.dirtyaura.org/blog Twitter: teemu Huikea Experience Social mobile gaming startup www.huikea.com
  • 2.
  • 4. TORNADO asynchronous requests simple clean DB API, no ORM programmer-friendly templates readable codebase proven in production: FriendFeed
  • 5. TORNADO Probably good for real-time web services (hanging GETs to poll) super-popular dynamic sites non-web REST services non-CMS sites for devs like me
  • 6. Our Tornado instance app cheap, async call Twitter
  • 8. Our Tornado instance cheap, async calls Another Tornado instance Twitter db.slow_synchronous_query()
  • 9. Programmer-friendly templates {% for index,value in entries.iteritems() %} {{ index }} : {{ value } {% end %} {% for value in entries %} {{ forloop.counter0 }} : {{ value }} {% endfor %}
  • 11. class TwitterBadgeHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self, username): http = tornado.httpclient.AsyncHTTPClient() url = "http://api.twitter.com/1/users/show/%s.json" % username http.fetch(url, callback=self.on_response) def on_response(self, response): if response.error: self.render("badge_error.html") else: user = tornado.escape.json_decode(response.body) self.render("twitter_badge.html", **user)
  • 12. .... <style type="text/css"> .badge { background: #{{profile_background_color}} url({{profile_background_image_url}}); ... rest of wrapping and css left-out ... <div class="badge"> <img class="badge-photo” src="{{ profile_image_url }}"> <div class="badge-title">{{ screen_name }}</div> <div class="badge-description">{{ description }}</div> <div class="clear"></div> <div class="badge-status">{{ status['text'] }}</div> </div>

Editor's Notes