Google apps script slow parsing -


i trying parse vmstat using google apps script in company use create graph of data. can find code here code slow. there can make better or isn't google apps script suitable this? problem ammount of rows needs processed. suggestions welcome.

  function doget(){    var file = driveapp.getfilebyid(id)    var doccontent = file.getas('application/octet-stream').getdataasstring();   var data = charts.newdatatable()                    .addcolumn(charts.columntype.string, 'time')                    .addcolumn(charts.columntype.number, 'memory');    var lines = doccontent.split("\n");   logger.log(lines.length);   var = 1;    lines.foreach(function(line) {     if ((line.indexof('mem') < 0) && (line.indexof('free') < 0)) {       var values = line.match(/\s+/g);       data.addrow(['5',parseint(values[3])]);        logger.log(i)     }     if (i == 20){      return;     }     i++;   });     for( var i=0;i< lines.length;i++){       data.addrow(['5',10]);    }   data.build();    var chart = charts.newareachart()       .setdatatable(data)       .setstacked()       .setrange(0, 400)       .settitle('memory')       .build();   return uiapp.createapplication().add(chart);  } 

this isn't problem of code optimization (although code isn't perfect), as division of work.

the accepted approach web application performance optimization involves separating 3 concerns; presentation, business logic , data accessref. exception of generation of vmstat output, you've got of in 1 place, making user wait while locate file on google drive (using 2 exhaustive searches, btw) , parse charts datatable, , generate html (via uiapp).

you may find accessibility of google apps script presentation useful organization. (i know in workplace our folks clamp down on in-house web servers, example.) if so, consider have prototype, , refactor give better perceived performance.

  • presentation: move uiapp + charts htmlservice + google visualization. moves generation of chart web client, instead of keeping in server. give faster page load, start.

  • business logic: rules map data visualization. charts service built on it, gviz uses datatables column definitions , rows of data.

    one option here repeat column definition & data load have, except on client in javascript. doing faster via google apps script.

    a second option, faster, large datasets, load data array.

    google.visualization.arraytodatatable(...) 

    either way, need data javascript function build chart.

  • data access: (i assume) you're running shell script in linux calls vmstat , pipes output file in local google drive folder. (alternatively, script may using drive api push file google drive.) file plain text.

    the change i'd make here produce csv output vmstat, , use google apps script import csv spreadsheet. then, can use sheet.getsheetvalues() read data in 1 shot, in server side function called client javascript.

this not fast local server solution, it's best way using google apps script environment.

edit: see more in blog post, converting uiapp + chart service html service + google visualization api.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -