-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use json datatype for Postgres insert (#582)
fixes: #565
- Loading branch information
Showing
3 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { Readable } = require('stream') | ||
const cds = require('../../cds.js') | ||
const bookshop = cds.utils.path.resolve(__dirname, '../../bookshop') | ||
|
||
// Stress test should not be run in the pipeline | ||
describe.skip('Bookshop - Insert', () => { | ||
cds.test(bookshop) | ||
|
||
test('Large (~33 mil rows)', async () => { | ||
const { Books } = cds.entities('sap.capire.bookshop') | ||
|
||
// Postgres | ||
// json (1 << 25) -> 5 min (with WAL warnings) | ||
// jsonb (1 << 24) -> size limit reached | ||
// json (1 << 23) -> 82.148 sec | ||
// jsonb (1 << 23) -> 52.148 sec | ||
// json (1 << 10) -> 2.35 sec | ||
// jsonb (1 << 10) -> 2.62 sec | ||
|
||
let totalRows = (1 << 20) | ||
let totalSize = 0 | ||
const bufferSize = 1 << 16 | ||
const stream = Readable.from((function* () { | ||
let buffer = '[' | ||
let i = 1000 | ||
const target = i + totalRows | ||
buffer += `{"ID":${i++}}` | ||
for (; i < target;) { | ||
buffer += `,{"ID":${i++}}` | ||
if (buffer.length >= bufferSize) { | ||
totalSize += buffer.length | ||
yield buffer | ||
buffer = '' | ||
} | ||
} | ||
buffer += ']' | ||
totalSize += buffer.length | ||
yield buffer | ||
})(), { objectMode: false }) | ||
const s = performance.now() | ||
await INSERT(stream).into(Books) | ||
process.stdout.write(`total size: ${totalSize} total rows: ${totalRows} rows/ms: (${totalRows / (performance.now() - s)})\n`) | ||
}, 60 * 60 * 1000) | ||
}) |