Changes between Version 27 and Version 28 of DeveloperGuidelines/Optimisation


Ignore:
Timestamp:
06/18/10 08:03:13 (14 years ago)
Author:
Dominic König
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/Optimisation

    v27 v28  
    3030
    3131 7. Consider having configurations which are read from DB frequently but written-to rarely, be set in configuration files which are written-out from the DB (like the CSS from themes)
     32
     33== Specific Examples ==
     34NB These vary on cases, so use the Profiler to see how they work in your cases...
     35{{{
     36for i in range(0, len(rows)):
     37     row = rows[i]
     38}}}
     39runs much faster than:
     40{{{
     41 for row in rows:
     42}}}
     43(0.05 vs. 0.001 seconds in one test case, 2x improvement in another & a slight negative improvement in a 3rd).
     44----
     45{{{
     46value = db(table.id == id).select(table.field, limitby=(0, 1)).first()
     47}}}
     48runs 1.5x faster than:
     49{{{
     50value = table[id].field
     51}}}
     52(0.012 vs. 0.007 seconds vs in a test case)
     53
     54NB If only expecting one record then the limitby provides a big speedup!
     55
     56Javascript string concatenation:
     57 * http://aymanh.com/9-javascript-tips-you-may-not-know#String_Concatenation_vs._Array.join
     58
     59== Profiling ==
     60 * Web2Py can [http://www.mail-archive.com/web2py@googlegroups.com/msg06267.html use cProfile]:
     61  * {{{web2py.py -F profiler.log}}}
     62  * or if running as service, edit {{{options.py}}}: {{{profiler_filename = 'profiler.log'}}}
     63 * http://docs.python.org/library/profile.html
     64 * http://www.cherrypy.org/wiki/Testing#Profiling
     65 * http://mg.pov.lt/profilehooks/
     66 * YSlow plugin for Firebug: http://developer.yahoo.com/yslow/
     67 *  You can also use [http://www.pylot.org Pylot] to test the application's behavior under load, and get more reliable results (+ in a nicer report form).
     68
     69{{{
     70I tested the "Welcome" application and found that it executes up to 86
     71request/second on my local environment. A similar value has been reported to
     72the web2py group, and it seems to be the maximum we can expect (considering
     73that the "Welcome" application is really thin).
     74
     75UltraCore requires response times for interactive views strictly below 250ms
     76on an average computer, so that we can execute up to 4 requests/second. That
     77sounds perhaps very slow, but compared with what we currently have, this
     78would be a 4x speed-up.
     79
     80So, if you implement a new view, please check whether it loads that fast on
     81your local computer (use FireBug to test), and if not - look at first at the
     82model, then at the static contents (ExtJS? Load only necessary components,
     83not ext_all.js!), and then at the controller (you will find that the
     84controller is mostly the fastest component of all).
     85}}}
    3286
    3387== Golden Rules for DB Queries ==
     
    110164}}}
    111165
    112 === Specific Examples ===
    113 NB These vary on cases, so use the Profiler to see how they work in your cases...
    114 {{{
    115 for i in range(0, len(rows)):
    116      row = rows[i]
    117 }}}
    118 runs much faster than:
    119 {{{
    120  for row in rows:
    121 }}}
    122 (0.05 vs. 0.001 seconds in one test case, 2x improvement in another & a slight negative improvement in a 3rd).
    123 ----
    124 {{{
    125 value = db(table.id == id).select(table.field, limitby=(0, 1)).first()
    126 }}}
    127 runs 1.5x faster than:
    128 {{{
    129 value = table[id].field
    130 }}}
    131 (0.012 vs. 0.007 seconds vs in a test case)
    132 
    133 NB If only expecting one record then the limitby provides a big speedup!
    134 
    135 Javascript string concatenation:
    136  * http://aymanh.com/9-javascript-tips-you-may-not-know#String_Concatenation_vs._Array.join
    137 
    138 === Profiling ===
    139  * Web2Py can [http://www.mail-archive.com/web2py@googlegroups.com/msg06267.html use cProfile]:
    140   * {{{web2py.py -F profiler.log}}}
    141   * or if running as service, edit {{{options.py}}}: {{{profiler_filename = 'profiler.log'}}}
    142  * http://docs.python.org/library/profile.html
    143  * http://www.cherrypy.org/wiki/Testing#Profiling
    144  * http://mg.pov.lt/profilehooks/
    145  * YSlow plugin for Firebug: http://developer.yahoo.com/yslow/
    146  *  You can also use [http://www.pylot.org Pylot] to test the application's behavior under load, and get more reliable results (+ in a nicer report form).
    147 
    148 {{{
    149 I tested the "Welcome" application and found that it executes up to 86
    150 request/second on my local environment. A similar value has been reported to
    151 the web2py group, and it seems to be the maximum we can expect (considering
    152 that the "Welcome" application is really thin).
    153 
    154 UltraCore requires response times for interactive views strictly below 250ms
    155 on an average computer, so that we can execute up to 4 requests/second. That
    156 sounds perhaps very slow, but compared with what we currently have, this
    157 would be a 4x speed-up.
    158 
    159 So, if you implement a new view, please check whether it loads that fast on
    160 your local computer (use FireBug to test), and if not - look at first at the
    161 model, then at the static contents (ExtJS? Load only necessary components,
    162 not ext_all.js!), and then at the controller (you will find that the
    163 controller is mostly the fastest component of all).
    164 }}}
    165 
    166166----
    167167DeveloperGuidelines