이상한 문제가 발생하여 제대로 된 것처럼 보일 수 없습니다.Node.js pg 두 번째 실행시 풀이 느림
Node.js 응용 프로그램에서 pg pooling을 사용하고 있으며 처음 실행시 정말 빠르게 실행되고 두 번째 실행에서는 매우 느리게 실행됩니다 (30/50 초).
나는 다음과 같이 내가 할 시도한 여러 풀을 만들하기 위해 전역 변수의 사용을 필요로 보인다 GitHub의 페이지 https://github.com/brianc/node-postgres/wiki/Example
에 대한 설명서를 읽었습니다.
는 나는 그것을 빨리 한 번 정말 실행하는 노선 GET 요청을 할 때 데이터베이스 쿼리var express = require("express");
var router = express.Router();
var pg = require("pg");
var credentials = {
host: "127.0.0.1",
port: "5432",
database: "altaltalt",
user: "postgres",
password: "postgres",
max: 100,
idleTimeoutMillis: 30000
};
var pool = new pg.Pool(credentials);
// this bit of code is executed
// when a button is clicked
router.get("/exec", function(req, res) {
pool.connect (
function(error, client, done) {
if(error) {
console.log("connection failed");
}
client.query(
"select * from dummytable",
function(error, result) {
done();
if(error) {
console.log(error);
}
alert(result.rows);
}
);
}
);
});
module.exports = router;
을 수행하는 경로의 파일을 사용
var express = require("express");
var path = require("path");
var app = express();
var port = 3000;
app.use("/public", express.static(process.cwd() + "/public"));
app.set("views", process.cwd() + "/public/views");
app.set("view engine", "ejs");
var login_route = require("./public/logic/login/login_route.js");
app.use(login_route);
app.listen(port, function() {
var message = "Server Started: Port " + port;
console.log(message);
});
우는 소리 내 주요 서버 파일이 버튼이 눌려져 있지만 그 후에 그것이 눌려지면 언제든지 몹시 느려집니다.
코드에 뭔가 빠졌습니까? 여러 요청을 처리하기위한 추가 단계가 있습니까?
,이 라이브러리 (노드 그레스)를 사용하여 미친 얻었다. 그런 다음 나는 당신을 위해 고객을 폐쇄하는 모든 일을하고 약속을 기반으로하는 [pg-promise] [1]를 발견합니다. 내 인생이 바뀌 었어. [1] : http://github.com/vitaly-t/pg-promise –
소리가 정말 좋네요. – Trent
트렌트가 [pg-promise] (https :// /github.com/vitaly-t/pg-promise)는 연결 풀 및 해당 관리와 관련된 모든 문제를 제거합니다. –