Add benchmark to measure memory usage during copy-from

This commit is contained in:
jeromew 2019-03-21 15:16:49 +00:00
parent ff39922e86
commit 38f9ebc606
2 changed files with 47 additions and 0 deletions

View File

@ -109,6 +109,8 @@ Since this isn't a module with tons of installs and dependent modules I hope we
* Small refactor in copy-from passing from 3 push to 2 push in every chunk transform loop * Small refactor in copy-from passing from 3 push to 2 push in every chunk transform loop
* Add bench/ directory for benchmarks * Add bench/ directory for benchmarks
* Add benchmark to compare performance of pg-copy-stream wrt psql during copy-from
* Add benchmark to measure memory usage of copy-from
### version 2.1.0 - published 2019-03-19 ### version 2.1.0 - published 2019-03-19

45
bench/copy-from-memory.js Normal file
View File

@ -0,0 +1,45 @@
var cp = require('duplex-child-process');
var pg = require('pg')
var copy = require('../').from
var client = function() {
var client = new pg.Client()
client.connect()
return client
}
var inStream = function() {
return cp.spawn('seq', ['0', '29999999']);
}
var running = true;
var c = client();
c.query('DROP TABLE IF EXISTS plugnumber', function() {
c.query('CREATE TABLE plugnumber (num int)', function() {
var seq = inStream()
var from = c.query(copy('COPY plugnumber FROM STDIN'))
seq.pipe(from);
from.on('end', function() {
running = false;
c.end();
})
})
})
var rssMin = process.memoryUsage().rss / 1024 / 1024
var rssMax = rssMin
memlog = function() {
var rss = process.memoryUsage().rss / 1024 / 1024
rssMin = Math.min(rss, rssMin)
rssMax = Math.max(rss, rssMax)
console.log('rss:' + Math.round(rss*100)/100 + 'MB rssMin:'+ Math.round(rssMin*100)/100 + 'MB rssMax:' + Math.round(rssMax*100)/100 + 'MB')
if (running) {
setTimeout(memlog, 1000);
}
}
memlog()