먼저 아래 글에 대한 답변 감사드립니다.
오늘 테스트를 해본 결과 ConnectionIdleLifetime (기본값=300초, 5분) 과 관련이 있었습니다.
postgres.exe 는 DB 오픈시 마다 1개씩 열렸습니다.
using (SqlConnection connection = new SqlConnection(serverConnectionString))
{
try
{
connection.Open(); ---> 이때 서버에서 postgres.exe 생성됩니다.
connection.Close();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "DB 접속 오류");
return false;
}
finally
{
Cursor.Current = cur;
}
}
제가 개발 중인 프로그램의 경우는 UnitOfWork 를 사용하기 때문에
그리드당 DB 오픈을 하게 됩니다.
보통 화면당 6개 정도 postgres.exe 가 실행되고
100명이 동시 접속한다고 가정하면 600개의 postgres.exe 가 5분간 실행될 것입니다.
그래서 아래 코드처럼 ConnectionIdleLifetime = 3; 으로 지정하고
실행시키니 3-5 초뒤에 postgres.exe 가 모두 종료되었습니다.
public static NpgsqlConnection ConnectNpgsql(string host, int port, string userName, string password, string database)
{
var builder = new NpgsqlConnectionStringBuilder();
builder.Host = host;
builder.Port = port;
builder.Username = userName;
builder.Password = password;
builder.Database = database;
builder.ConnectionIdleLifetime = 3; // 3 초뒤 postgress.exe 종료시킵니다.
builder.ApplicationName = database;
return new NpgsqlConnection(builder.ToString());
}
결국 동시 접속 사용자 수가 많은 경우는 ConnectionIdleLifetime 을 최대한 줄여서
postgres.exe 를 종료되게 하는 것이 맞지 않을까 판단됩니다.
postgreSQL 초보자 인지라 이 방법이 맞는지 모르겠습니다.
감사합니다.
|