If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!


  • 0
    hillmanov  14 years ago
    It takes over 8.5 seconds to render the response for a table containing 10,000 rows when talking to a MySQL database. I think I have identified "chattiness" in the code. If all fields are being selected (even though they will not be displayed as per the grid.fields parameter), I would not expect additional select statements outside of the COUNT(*) statement. The data is already in memory and just needs to be parsed. What does everyone think? Model snippet:
    db.define_table('allstats',
                    Field('pdate','datetime'),
                    Field('class','string',length=45),
                    Field('instance','string',length=45),
                    Field('parameter','string',length=45),
                    Field('hostname','string',length=45),
                    Field('lastv','double'),
                    Field('minv','double'),
                    Field('maxv','double'),
                    Field('avgv','double'),
                    Field('cntv','integer'),
                    Field('peaktime','datetime'),
                    Field('sumv','integer'),
                    Field('sitelocation','string',length=30),
                    migrate=False)
    webgrid = local_import('webgrid')
    
    Controller snippet:
    grid = webgrid.WebGrid(crud)
        grid.datasource = db(db.allstats.id<30000) # Set
        grid.crud_function = 'index' # Set the function where crud will be exposed.
        grid.fields = ['allstats.pdate','allstats.parameter','allstats.peaktime']
        grid.pagesize = 100
        return dict(grid=grid()) #notice the ()
    
    Wireshark capture from client:
    SET FOREIGN_KEY_CHECKS=1;
    SET sql_mode='NO_BACKSLASH_ESCAPES';
    SELECT allstats.id, allstats.pdate, allstats.class, allstats.instance, allstats.parameter, allstats.hostname, allstats.lastv, allstats.minv, allstats.maxv, allstats.avgv, allstats.cntv, allstats.peaktime, allstats.sumv, allstats.sitelocation FROM allstats WHERE allstats.id<30000 LIMIT 100 OFFSET 0;
    SELECT count(*) FROM allstats WHERE allstats.id<30000;
    SELECT allstats.id, allstats.pdate FROM allstats WHERE allstats.id>0;
    SELECT allstats.id, allstats.parameter FROM allstats WHERE allstats.id>0;
    SELECT allstats.id, allstats.peaktime FROM allstats WHERE allstats.id>0;
    commit
    

Commented on:

This is a module that lets you build a table on the server that supports paging, sorting, editing and totals easily. It requires no javascript or sessions to work.

Hosting graciously provided by:
Python Anywhere