Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add batch benchmark - handle named parameter - correct null handling when streaming - correct strange node.js behaviour about not reusing buffer send to socket - handle error - with multi-packets - query array parameter listing
- Loading branch information
Showing
13 changed files
with
1,593 additions
and
383 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const assert = require("assert"); | ||
|
||
const basechars = "123456789abcdefghijklmnop\\Z"; | ||
const chars = basechars.split(""); | ||
chars.push("😎"); | ||
chars.push("🌶"); | ||
chars.push("🎤"); | ||
chars.push("🥂"); | ||
|
||
function randomString(length) { | ||
let result = ""; | ||
for (let i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; | ||
return result; | ||
} | ||
|
||
let sqlTable = | ||
"CREATE TABLE testn.perfTestTextPipe (id MEDIUMINT NOT NULL AUTO_INCREMENT,t0 text" + | ||
", PRIMARY KEY (id))"; | ||
sqlInsert = "INSERT INTO testn.perfTestTextPipe(t0) VALUES (?)"; | ||
|
||
module.exports.title = | ||
"100 * insert 100 characters using promise and batch method (for mariadb only, since doesn't exist for others)"; | ||
module.exports.displaySql = "INSERT INTO testn.perfTestTextPipe VALUES (?) (into BLACKHOLE ENGINE)"; | ||
const iterations = 100; | ||
module.exports.promise = true; | ||
module.exports.benchFct = function(conn, deferred, connType) { | ||
const params = [randomString(100)]; | ||
// console.log(connType.desc); | ||
if (!connType.desc.includes("mariadb")) { | ||
//other driver doesn't have bulk method | ||
let ended = 0; | ||
for (let i = 0; i < iterations; i++) { | ||
conn | ||
.query(sqlInsert, params) | ||
.then(rows => { | ||
// let val = Array.isArray(rows) ? rows[0] : rows; | ||
// assert.equal(1, val.info ? val.info.affectedRows : val.affectedRows); | ||
if (++ended === iterations) { | ||
deferred.resolve(); | ||
} | ||
}) | ||
.catch(err => { | ||
throw err; | ||
}); | ||
} | ||
} else { | ||
//use batch capability | ||
const totalParams = new Array(iterations); | ||
for (let i = 0; i < iterations; i++) { | ||
totalParams[i] = params; | ||
} | ||
conn | ||
.batch(sqlInsert, totalParams) | ||
.then(rows => { | ||
deferred.resolve(); | ||
}) | ||
.catch(err => { | ||
throw err; | ||
}); | ||
} | ||
}; | ||
|
||
module.exports.initFct = function(conn) { | ||
return Promise.all([ | ||
conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe"), | ||
conn.query("INSTALL SONAME 'ha_blackhole'"), | ||
conn.query(sqlTable + " ENGINE = BLACKHOLE COLLATE='utf8mb4_unicode_ci'") | ||
]) | ||
.catch(err => { | ||
return Promise.all([ | ||
conn.query("DROP TABLE IF EXISTS testn.perfTestTextPipe"), | ||
conn.query(sqlTable + " COLLATE='utf8mb4_unicode_ci'") | ||
]); | ||
}) | ||
.catch(e => { | ||
console.log(e); | ||
throw e; | ||
}); | ||
}; | ||
|
||
module.exports.onComplete = function(conn) { | ||
conn.query("TRUNCATE TABLE testn.perfTestTextPipe").catch(e => { | ||
console.log(e); | ||
throw e; | ||
}); | ||
}; |
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
Oops, something went wrong.