From 38f9ebc60695766399f99193cfcd959cbbf9d98a Mon Sep 17 00:00:00 2001 From: jeromew Date: Thu, 21 Mar 2019 15:16:49 +0000 Subject: [PATCH] Add benchmark to measure memory usage during copy-from --- README.md | 2 ++ bench/copy-from-memory.js | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bench/copy-from-memory.js diff --git a/README.md b/README.md index 3651fe5..7b6c535 100644 --- a/README.md +++ b/README.md @@ -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 * 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 diff --git a/bench/copy-from-memory.js b/bench/copy-from-memory.js new file mode 100644 index 0000000..370e225 --- /dev/null +++ b/bench/copy-from-memory.js @@ -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()