Skip to content

Instantly share code, notes, and snippets.

@isc-rsingh
Last active July 26, 2016 16:26
Show Gist options
  • Save isc-rsingh/06720f82a5d3957c201ced84f8834b16 to your computer and use it in GitHub Desktop.
Save isc-rsingh/06720f82a5d3957c201ced84f8834b16 to your computer and use it in GitHub Desktop.
A simple Node.js script to test Cloudant geo queries for load and/or coverage. `npm install superagent` then `node geotest.js`
var request = require('superagent');
// Replace these 3 variables with your own information
// Note: The database must be world readable
const CLOUDANT_ACCOUNT = 'opendata';
const CLOUDANT_DB = 'pois';
const GEO_INDEX = '_design/idx/_geo/spatial';
for (var index = 0; index < 500; index++) {
runQuery(index)
}
function runQuery(idx) {
const t = new Date();
console.log("here's the start time on run " + idx + ": "+t.toISOString());
var rlat = (Math.random() * 180) - 90; // cover the globe
// var rlat = (Math.random() * 18) +31; // cover only the US
var rlon = (Math.random() * 360) - 180; // cover the globe
// var rlon = (Math.random() * 51) - 123; // var rrad = Math.floor(100*(Math.random() * 8) - 2); // cover only the US
var rrad = Math.floor(10000*((Math.random() * 5) + 7)); // 7000 to 12000 meters
var url = 'https://'+CLOUDANT_ACCOUNT+'.cloudant.com';
url += '/'+CLOUDANT_DB+'/'+GEO_INDEX;
url += '?limit=200&relation=contains&lat='+rlat+'&lon='+rlon+'&radius='+rrad;
request
.get(url)
.set('Accept', 'application/json')
.end(function (err, res) {
console.log('REQUEST: '+url);
var te = new Date();
var diff = new Date(te.getTime() - t.getTime());
// console.log("here's the end time on run " + idx + ": "+te.toISOString());
if (err || !res.ok) {
console.log('Oh no! error');
} else {
console.log('Run '+idx+': '+res.body.rows.length+' rows returned in '+diff/1000+' seconds\n ');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment