Even faster django
Upcoming SlideShare
Loading in...5
×
 

Even faster django

on

  • 1,842 views

Even Faster Django shared at PyCon Taiwan 2012.

Even Faster Django shared at PyCon Taiwan 2012.

Statistics

Views

Total Views
1,842
Views on SlideShare
1,828
Embed Views
14

Actions

Likes
5
Downloads
13
Comments
0

4 Embeds 14

http://www.linkedin.com 5
http://localhost 4
https://twitter.com 4
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Even faster django Even faster django Presentation Transcript

  • Even Faster Django Mongodb + Jinja2 + Bigpipe Gage Tseng / GenieCapital gagedark@gmail.com
  • About Gage 2008 Yahoo! F2E Intern 2009 Master of CS NTU 2010 Genie Capital 2011 Gulu.com 2012 PYCON Start my Python life TechCrunch Hackathon 北京
  • Web Framework Easy Quick
  • Performance ? Hmm.... it is OK
  • How to make it Fast ?
  • What is Fast ?
  • Fast is about User Experience and Response Time
  • http://fast.example.com 1 2 GO
  • http://crazy.fast.example.com 0.1 GO
  • It is almost Impossible
  • We are talking about large scale and dynamic web site
  • Definition of Fast Page start to render in 1 second Show important content in 2 seconds
  • Request and Response HTTP Request DNS Lookup Data Transfer DB Render and Execute JS Parse HTML Download CSS, JS Web Server Data Transfer Response DB Query Render Response
  • 50% Database & Template Engine
  • Database Good Query Performance High Scalability Easy to Use
  • NoSQL Database Schema Free BSON Javascript High Scalability
  • Django-Nonrel Django Mongodb Engine
  • Migration-Free No more South $ python manage.py migrate
  • Embedded Model Less Query and lookup class UserProfile(models.Model): contact = EmbeddedModelField('ContactModel') ... > print my_profile.contact.phone > u"0919xxxxxx"
  • SetField / ListFiled / DictField Easy to use & Query Fast class UserProfile(models.Model): skill = ListField(models.CharField(max_length=24)) ... > print my_profile.skill > [u"python", u"javascript", u"erlang"] > UserProfile.objects.filter(skill="python") > [<UserProfile Gage>, <UserProfile Jason>]
  • Template Engine High Render Speed Easy to Use
  • Jinja2 Fast Extensible Django template like
  • Jinja2 Coffin https://github.com/coffin/coffin
  • With Jinja2 You can <h1>{{ user1.get_nickname() }}</h1> <h1>{{ user1.fun().attr }}</h1> No more Complicated template tags
  • Benchmark
  • It is faster now
  • http://faster.example.com 0.9 GO
  • Can it be Even Faster
  • What is Even Faster Page start to render in 0.5 second Show important content in 1 second
  • BigPipe ! Facebook 2009
  • http://bigpipe.example.com 0.2 0.9 GO
  • http://bigpipe.example.com 0.2 0.9 GO
  • Bigpipe Break web pages into multiple chunks (Pagelet) Server render a pagelet and response Prepare CSS Render Page (HTML DOM) Execute JS when JS resources are ready
  • Request and Response HTTP Request DNS Lookup Data Transfer DB Render and Execute JS Parse HTML Download CSS, JS Web Server Data Transfer Response DB Query Render Response
  • HTTP Request DNS Lookup Data Transfer DB Render and Execute JS Web Server DB Query DB Query Parse HTML Download CSS, JS DB Query Data Transfer Render Response
  • http://bigpipe.example.com 0.2 0.9 GO
  • How fast is it (from facebook)
  • Facebook BigPipe Streaming HttpResponse https://code.djangoproject.com/ticket/7581 BigPipe Javascript https://github.com/msroot/bigpipe/blob/master/bigpipe.js
  • Django Part def home(request): def stream_generator(): base = render_to_string("base.html") yield base.ljust(4096) yield main_content(request).ljust(4096) #pagelet yield footer(request).ljust(4096) #pagelet yield "</body></html>" return HttpResponse(stream_generator(), mimetype='text/html', stream_content=True) main_content and footer will prepare CSS and JS resource for pagelet.
  • <!DOCTYPE html> <html> yield base.ljust(4096) <head> <title>I'm BigPipe</title> <script type="text/javascript" src="bigpipe.js"></script> </head> <body> <script> yield main_content(request).ljust(4096) bigPipe.onPageletArrive({"html":"...", "css":{...},"js":{...}}) </script> <script> yield footer(request).ljust(4096) bigPipe.onPageletArrive({"html":"...", "css":{...},"js":{...}}) </script> </body> </html> yield "</body></html>"
  • http://bigpipe.example.com 0.2 0.9 GO
  • Even Faster Django MongoDB + Jinja2 + Bigpipe + Genie Dev Team