0
Django + GAE@wingchen83
WINGCHEN••   java            compiler (antlr parser generator)•          python••    GAE                   djangoappengine
WHY DJANGO       www.djangoproject.com•   / /              web framework (me!)•     ruby         me!•   python (me!)•     ...
INSTALLATION         docs.djangoproject.com/en/1.3/intro/install/•       python• download   django official release• (linux...
FIRST DJANGO APP: A BLOG!!        docs.djangoproject.com/en/1.3/intro/tutorial01• django-admin.py   startproject gtugproj•...
DB SETUP          docs.djangoproject.com/en/1.3/intro/tutorial01• Let’s   use sqlite!                    DATABASES = {    ...
COMMENCE THE BLOG APP• python   manage.py startapp blog
DJANGO MVC• Diagram   form: metodologiasdesistemas.blogspot.com
DJANGO MVC                          urls.py/          modles.py                          views.py                         ...
THE BLOG MODEL   docs.djangoproject.com/en/dev/topics/db/models/from django.db import modelsfrom datetime import datetimec...
THE BLOG VIEW     docs.djangoproject.com/en/dev/topics/db/queries• Show   Blogs:def blog_view(request):   blogs = Blog.obj...
THE BLOG VIEW    docs.djangoproject.com/en/dev/topics/db/queries• New   Blog:@csrf_exemptdef blog_add(request):   title = ...
THE BLOG CONTROLLER• gtugproj/urls.py       (^blog/, include(blog.urls)),• gtugproj/blog/urls.py       (^blog_add, blog_ad...
PUT IT IN SETTINGS.PY             INSTALLED_APPS = (               django.contrib.auth,               django.contrib.conte...
DJANGOAPPENGINE            ...• Django   Nonrel               Django      NoSQL Database    ORM
DJANGO NONREL         ?• Developers      Model• Django   ORM• SQL• Django-dbindexer• No-Sql   DB Calls
DJANGO NONREL?•            non-relational DBs•       PO   SQL DBs•   /             Denormalization•        querie•        ...
DJANGO NONREL• GAE     djangoappengine• MongoDB     MongoDB backend (                     LittleQ)
DJANGO NONREL• ElasticSearch• Cassandra
DJANGOAPPENGINE     www.allbuttonspressed.com/projects/djangoappengin•          Django App Engine     :    • DB    • Email...
BLOG APP                           GAE• django-nonrel/django   => gtugproj/django• djangotoolbox/djangotoolbox   => gtugpr...
• gtugproj/django• gtugproj/djangotoolbox• gtugproj/autoload• gtugproj/dbindexer• gtugproj/djangoappengine
COPY SAMPLE• app.yaml• cron.yaml• index.yaml• indexes.py• manage.py    (overwrite)
SETTINGS.PY• [please   follow up]
TRAIL RUN• python   manage.py runserver
DEPLOY TO GAE•        GAE APP•        app.yaml•    python manage.py deploy
DJANGOAPPENGINE•       JOIN !! (       ,         ,JOIN   )•   many-to-many•   Aggregates•   transactions•       GAE       ...
DEPENDENCIES•       source code     gtugproj•                      3000    •   zip-packages
CACHE•   Django memcache module API•    GAE       – memcache backend
CACHE•from django.core.cache import cacheinsureme_blog_rss_url = http://blog.insureme.com.tw/feeds/posts/defaultdef get_bl...
CACHE•insureme_blog_rss_url = http://blog.insureme.com.tw/feeds/posts/defaultdef get_blog_rss_feeds():   refresh_cache_blo...
CACHE•   ab- 10 connections    10- 2000 requests in total     2000   request
CACHE    Cache                                       CacheConcurrency Level:      10                    Concurrency Level:...
/    www.allbuttonspressed.com/projects/django-filetransfers•          django-filetransfers    •     “filetransfers”    •    ...
TASKING    bitbucket.org/wkornewald/django-defer••
Q&A?• url: http://techblog.insureme.com.tw• twitter: wingchen83
THANK YOU!!• url: http://techblog.insureme.com.tw• twitter: wingchen83
Upcoming SlideShare
Loading in...5
×

國民雲端架構 Django + GAE

2,686

Published on

就要應邀到GTug分享 djangoappengine 了!

另外,我有準備了一個範例專案,請到這邊下載:
http://www.2shared.com/file/c6Y8xbPv/gtugproj.html

好險有科技:
http://techblog.insureme.com.tw/

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

No Downloads
Views
Total Views
2,686
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
32
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "國民雲端架構 Django + GAE"

    1. 1. Django + GAE@wingchen83
    2. 2. WINGCHEN•• java compiler (antlr parser generator)• python•• GAE djangoappengine
    3. 3. WHY DJANGO www.djangoproject.com• / / web framework (me!)• ruby me!• python (me!)• (me!)
    4. 4. INSTALLATION docs.djangoproject.com/en/1.3/intro/install/• python• download django official release• (linux: sudo) python setup.py install
    5. 5. FIRST DJANGO APP: A BLOG!! docs.djangoproject.com/en/1.3/intro/tutorial01• django-admin.py startproject gtugproj• Tryit: python manage.py runserver (8080)
    6. 6. DB SETUP docs.djangoproject.com/en/1.3/intro/tutorial01• Let’s use sqlite! DATABASES = { default: { ENGINE: django.db.backends.sqlite3, NAME: gtugproj.sqlite, } }• Updateit: python manage.py syncdb• Voila, the project is UP!
    7. 7. COMMENCE THE BLOG APP• python manage.py startapp blog
    8. 8. DJANGO MVC• Diagram form: metodologiasdesistemas.blogspot.com
    9. 9. DJANGO MVC urls.py/ modles.py views.py views.py/ templates• Diagram form: metodologiasdesistemas.blogspot.com
    10. 10. THE BLOG MODEL docs.djangoproject.com/en/dev/topics/db/models/from django.db import modelsfrom datetime import datetimeclass Blog(models.Model): blog_id = models.AutoField(primary_key=True) title = models.CharField(max_length=50) content = models.TextField() pub_date = models.DateTimeField(default=datetime.now)
    11. 11. THE BLOG VIEW docs.djangoproject.com/en/dev/topics/db/queries• Show Blogs:def blog_view(request): blogs = Blog.objects.all() output = output += <FORM action="blog_add" method="post"> output += <INPUT name="title" type="text" id="title"/><BR> output += <textarea rows="10" cols="20" id="content" name="content"></textarea><BR> output += <INPUT type="submit" id="submit" value="Go"/><BR> output += </FORM><br> for blog in blogs: output += title: + blog.title + <br> output += pub_date: + str(blog.pub_date) + <br> output += content: + blog.content + <br><br> return HttpResponse(output, mimetype=text/html)
    12. 12. THE BLOG VIEW docs.djangoproject.com/en/dev/topics/db/queries• New Blog:@csrf_exemptdef blog_add(request): title = request.REQUEST.get(title, default title) content = request.REQUEST.get(content, default content) Blog(title=title, content=content).save() return redirect(/blog/)
    13. 13. THE BLOG CONTROLLER• gtugproj/urls.py (^blog/, include(blog.urls)),• gtugproj/blog/urls.py (^blog_add, blog_add), (, blog_view),
    14. 14. PUT IT IN SETTINGS.PY INSTALLED_APPS = ( django.contrib.auth, django.contrib.contenttypes, django.contrib.sessions, django.contrib.sites, blog )• Then: python manage.py syncdb
    15. 15. DJANGOAPPENGINE ...• Django Nonrel Django NoSQL Database ORM
    16. 16. DJANGO NONREL ?• Developers Model• Django ORM• SQL• Django-dbindexer• No-Sql DB Calls
    17. 17. DJANGO NONREL?• non-relational DBs• PO SQL DBs• / Denormalization• querie• (GAE, etc.)
    18. 18. DJANGO NONREL• GAE djangoappengine• MongoDB MongoDB backend ( LittleQ)
    19. 19. DJANGO NONREL• ElasticSearch• Cassandra
    20. 20. DJANGOAPPENGINE www.allbuttonspressed.com/projects/djangoappengin• Django App Engine : • DB • Email• Django Nonrel
    21. 21. BLOG APP GAE• django-nonrel/django => gtugproj/django• djangotoolbox/djangotoolbox => gtugproj/djangotoolbox• django-autoload/autoload => gtugproj/autoload• django-dbindexer/dbindexer => gtugproj/dbindexer• djangoappengine => gtugproj/djangoappengine
    22. 22. • gtugproj/django• gtugproj/djangotoolbox• gtugproj/autoload• gtugproj/dbindexer• gtugproj/djangoappengine
    23. 23. COPY SAMPLE• app.yaml• cron.yaml• index.yaml• indexes.py• manage.py (overwrite)
    24. 24. SETTINGS.PY• [please follow up]
    25. 25. TRAIL RUN• python manage.py runserver
    26. 26. DEPLOY TO GAE• GAE APP• app.yaml• python manage.py deploy
    27. 27. DJANGOAPPENGINE• JOIN !! ( , ,JOIN )• many-to-many• Aggregates• transactions• GAE run_in_transaction()
    28. 28. DEPENDENCIES• source code gtugproj• 3000 • zip-packages
    29. 29. CACHE• Django memcache module API• GAE – memcache backend
    30. 30. CACHE•from django.core.cache import cacheinsureme_blog_rss_url = http://blog.insureme.com.tw/feeds/posts/defaultdef get_blog_rss_feeds(): feeds = cache.get(blog_rss_feeds) if feeds == None: refresh_cache_blog_rss_feeds() return cache.get(blog_rss_feeds) return feeds
    31. 31. CACHE•insureme_blog_rss_url = http://blog.insureme.com.tw/feeds/posts/defaultdef get_blog_rss_feeds(): refresh_cache_blog_rss_feeds() return cache.get(blog_rss_feeds)
    32. 32. CACHE• ab- 10 connections 10- 2000 requests in total 2000 request
    33. 33. CACHE Cache CacheConcurrency Level: 10 Concurrency Level: 10Time taken for tests: 590.238 seconds Time taken for tests: 237.262 secondsComplete requests: 2000 Complete requests: 2000Failed requests: 1 Failed requests: 0Write errors: 0 Write errors: 0Total transferred: 1619817 bytes Total transferred: 1620000 bytesHTML transferred: 1313809 bytes HTML transferred: 1314000 bytesRequests per second: 3.39 [#/sec] (mean) Requests per second: 8.43 [#/sec] (mean)Time per request: 2951.190 [ms] (mean) Time per request: 1186.308 [ms] (mean)Time per request: 295.119 [ms] (mean, Time per request: 118.631 [ms] (mean,across all concurrent requests) across all concurrent requests)Transfer rate: 2.68 [Kbytes/sec] Transfer rate: 6.67 [Kbytes/sec]received received
    34. 34. / www.allbuttonspressed.com/projects/django-filetransfers• django-filetransfers • “filetransfers” • “filetransfers” INSTALLED_APPS
    35. 35. TASKING bitbucket.org/wkornewald/django-defer••
    36. 36. Q&A?• url: http://techblog.insureme.com.tw• twitter: wingchen83
    37. 37. THANK YOU!!• url: http://techblog.insureme.com.tw• twitter: wingchen83
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×