Created
November 5, 2022 01:14
-
-
Save krisrice/59003f13ee6754bfec554e3fe1de7531 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var fetch = require('node-fetch'); | |
// | |
// generate random string | |
// | |
/* | |
Sample output | |
inserting :50000 rows | |
Rows:244,652 | |
http: 7.429s | |
Sent:50.489075 MBytes | |
Received:51.789223 MBytes | |
Rows:294,652 | |
*/ | |
const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
function generateString(length) { | |
let result = ' '; | |
const charactersLength = characters.length; | |
for ( let i = 0; i < length; i++ ) { | |
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
} | |
return result; | |
} | |
// | |
// http headers | |
// | |
var meta = new Map(); | |
meta.set('Content-Type','application/json'); | |
meta.set('Authorization','Basic ' + btoa("klrice" + ":" + "klrice") ); | |
const headers = new fetch.Headers(meta); | |
// | |
// setup payload for batch inserts | |
// | |
var payload ={ | |
"statementText": "insert into insertme(id,text)values(?,?);", | |
"binds":[{ | |
"index": 1, | |
"data_type": "NUMBER", | |
"batch": true, | |
"value": [] | |
},{ | |
"index": 2, | |
"data_type": "VARCHAR2", | |
"batch": true, | |
"value": [] | |
}] | |
}; | |
// | |
// make 50k rows | |
// | |
var size = 50000; | |
for(var i=0;i<size;i++){ | |
payload.binds[0].value.push(i); | |
payload.binds[1].value.push(generateString(1000)); | |
} | |
console.log("inserting :" + size +" rows"); | |
console.time('http'); | |
// | |
// send it | |
// | |
checkRows(); | |
const response = fetch('http://localhost:8080/ords/klrice/_/sql', { | |
method: 'post', | |
body: JSON.stringify(payload), | |
headers: headers | |
}).then(function(res){ | |
// | |
// print time and how much was sent | |
// | |
console.timeEnd('http'); | |
console.log("Sent:"+ (JSON.stringify(payload).length/1000/1000) + " MBytes") | |
return res.text(); | |
}) | |
.then(function(text){ | |
console.log("Received:" + (text.length/1000/1000) + " MBytes"); | |
checkRows(); | |
} | |
); | |
function checkRows(){ | |
var meta = new Map(); | |
meta.set('Content-Type','application/sql'); | |
meta.set('Authorization','Basic ' + btoa("klrice" + ":" + "klrice") ); | |
var headers = new fetch.Headers(meta); | |
var response = fetch('http://localhost:8080/ords/klrice/_/sql', { | |
method: 'post', | |
body: "select count(1) c from insertme", | |
headers: headers | |
}).then(function(res){ | |
return res.text() | |
}).then(function(text){ | |
console.log("Rows:" + JSON.parse(text).items[0].resultSet.items[0].c) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment