Skip to content

Instantly share code, notes, and snippets.

@madushan1000
Created February 17, 2016 11:40
Show Gist options
  • Save madushan1000/7d4993dc19a24a01eb84 to your computer and use it in GitHub Desktop.
Save madushan1000/7d4993dc19a24a01eb84 to your computer and use it in GitHub Desktop.
import influx from 'influx';
import {promisifyAll} from 'bluebird';
const client = promisifyAll(influx({
hosts: [
{
host: 'mad-influx1'
},
{
host: 'mad-influx2'
}
],
database: 'test',
username: 'username',
password: 'password'
}));
const values = {
count: 1,
sessions: 2,
eventLoopTime: 0,
eventLoopCount: 0,
totalTime: 0,
memory: 100.86328125,
loadAverage: 0,
pcpu: 2.7,
cputime: 0,
pcpuUser: 0,
pcpuSystem: 0,
newSessions: 0,
gcScavengeCount: 0,
gcScavengeDuration: 0,
gcFullCount: 0,
gcFullDuration: 0
};
const tags = {
appId: 'randomletters',
host: 'somerandomletters',
res: '1min'
};
const n = 10000;
let c = 0;
async function write() {
console.time('Individual writes');
for (let i = n; i > 0; i--) {
await client.writePointAsync('individual', values, tags);
}
console.timeEnd('Individual writes');
}
async function writeBatch() {
c++;
console.log(c);
console.time('Batch writes');
const points = [];
for (let i = n; i > 0; i--) {
values.time = new Date();
points.push([ values, tags ]);
}
await client.writePointsAsync('batch', points);
console.timeEnd('Batch writes');
}
async function read() {
console.time('Query all');
await client.queryAsync('SELECT * from individual');
console.timeEnd('Query all');
}
async function run() {
console.time('Loop');
while (1) {
await writeBatch();
}
console.timeEnd('Loop');
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment