CouchDB slow List-Function -


in general know problem is, have no idea how solve it.

i have simple map-function:

function(doc) {    if(doc.type === 'mission'){       for(var in doc.sections){          emit(doc._id, {_id:doc.sections[i].id});       }    } } 

based on result of map-function, use list-function formatting:

function(head,req){     var result=[];    var row;     topo = require('lib/topojson');     while(row=getrow()){       if (row !== null) {          if(row.value._id){             row.doc.geometry.properties.ids.section_id = row.value._id;          }else{             row.doc.geometry.properties.ids.section_id = row.value;          }           geojson = {             type: "feature",             geometry: row.doc.geometry.geometry,             properties: row.doc.geometry.properties          };           result.push(geojson);       }else{          send(json.stringify({             status_code: 404          }));       }     }    send(json.stringify(result)); } 

the more documents matching map-function longer take processing list-function. limiting factor couchjs view server. first result map-function has serialized, after list-function can work.

as wrote, small amount of documents processing time isn't dramatical amount of documents increase time processing list function increase well.

has idea improve way format result? better let client work?

there exist several tricks speed _list functions.

  1. make list , map functions live in 2 different design docs, ensure run in different spidermonkey instances.
  2. send response in large chunks, tens or hundreds of kilobytes. find out optimal chunk size: large chunks bad in terms of ttfb , memory consumption, small chunks produce io overhead between sm , erlang.
  3. minimize overhead of storage->erlang->js serialize/deserialize. make map function emit strings serialized json , parse each row‘s json inside list fn plain string. more simple structure pass erlang, less time spent @ erlang side process , pass sm.

you can use cache approach, must understand you‘re doing. read more details here.


Comments