Last active
December 15, 2015 15:09
-
-
Save you21979/5279675 to your computer and use it in GitHub Desktop.
node-mysqlのconnect呼ぶだけで遅い。秒間100-300回程度しか回ってくれない
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
"use strict"; | |
var mysql = require('mysql'); | |
var mysqlConfig = { | |
host : "127.0.0.1", | |
port : 3306, | |
user : "root", | |
password : "", | |
database : "test", | |
debug : false, | |
}; | |
function db(){ | |
var conn = mysql.createConnection(mysqlConfig); | |
conn.connect(function(err){ | |
conn.end(); | |
}); | |
} | |
var cnt=0; | |
process.nextTick(function P(){ | |
db(); | |
process.nextTick(P); | |
console.log(++cnt); | |
}); |
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
"use strict"; | |
var mysql = require('mysql'); | |
var mysqlConfig = { | |
host : "127.0.0.1", | |
port : 3306, | |
user : "root", | |
password : "", | |
database : "test", | |
debug : false, | |
connectionLimit : 1000, | |
}; | |
var pool = mysql.createPool(mysqlConfig); | |
function db(){ | |
pool.getConnection(function(err, connection) { | |
if(err){ | |
console.log(err); | |
return; | |
} | |
connection.end(); | |
}); | |
} | |
var cnt=0; | |
process.nextTick(function P(){ | |
db(); | |
process.nextTick(P); | |
console.log(++cnt); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
プールした場合トランザクションをちゃんと切ってからにendしないと次に使いまわされた時に前のトランザクションの状態が残ったままになる。
状態管理しておかないと危ない