Created
April 24, 2017 22:20
-
-
Save abossard/b1367de3dceec155224f0c5b9bea7aed to your computer and use it in GitHub Desktop.
let's blow up azure table storage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const R = require('ramda'); | |
const azure = require('azure-storage'); | |
const retryOperations = new azure.ExponentialRetryPolicyFilter(); | |
const tableSvc = azure.createTableService().withFilter(retryOperations); | |
const data = 'Z'.repeat(64 * 100) | |
const tableName = 'shibbydatalist' | |
const defaultEntity = R.range(1, 30).reduce(function (result, bucketNumber) { | |
result['T' + bucketNumber] = data | |
return result; | |
}, {}); | |
const createEntitiesForDay = function (deviceid, year, month, day) { | |
return [0, 8, 16].map(function (hour) { | |
return Object.assign({ | |
PartitionKey: { '_': '' + deviceid + '-' + year + '-' + month }, | |
RowKey: { '_': day + '-' + hour }, | |
}, defaultEntity); | |
}) | |
} | |
const startQueryX = (new Date()).getTime(); | |
['1-0', '1-8', '1-16'].forEach(function (rowKey) { | |
tableSvc.retrieveEntity(tableName, '3-2016-1', '1-0', function (error, result, response) { | |
const tteQueryX = (new Date()).getTime() - startQueryX; | |
console.log('Key Access: ' + rowKey); | |
console.log('Key Access [ms]: ' + tteQueryX); | |
console.log('Key Access [kb]: ' + Math.floor(JSON.stringify(result).length / 1024)); | |
}); | |
}) | |
const query = new azure.TableQuery().top(99).where('PartitionKey eq ?', '3-2016-1') | |
const startQuery = (new Date()).getTime(); | |
tableSvc.queryEntities(tableName, query, null, function (error, result, response) { | |
const tteQuery = (new Date()).getTime() - startQuery; | |
console.log('Partition Scan [ms]: ' + tteQuery); | |
console.log('Partition Scan [kb]: ' + Math.floor(JSON.stringify(result).length / 1024)); | |
if (!error) { | |
console.log(result.entries.length); | |
} else { | |
console.error(error); | |
} | |
}); | |
tableSvc.createTableIfNotExists(tableName, function (error, result, response) { | |
if (!error) { | |
console.log("GO"); | |
R.range(3, 4).forEach(function (deviceid) { | |
R.range(1, 13).forEach(function (month) { | |
R.range(1, 32).forEach(function (day) { | |
createEntitiesForDay(deviceid, 2016, month, day).forEach(function (entity) { | |
tableSvc.insertOrReplaceEntity(tableName, entity, function (error, result, response) { | |
if (!error) { | |
console.log(deviceid, 2016, month, day); | |
} else { | |
console.log(error); | |
} | |
}) | |
}); | |
}); | |
}); | |
}); | |
} else { | |
console.log(error); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment