[참고자료] 공개커넥션풀 프로그램

 
 

커넥션 풀은 프로그램(java, c, php 등등)과 db사이에서 db연결을 pool로 만들어 제어해주는 것입니다.
PHP에서 사용할 수 있는 공개 커넥션 풀 프로그램을 찾은 것이 있어서 여기 올립니다.
여기서는 간단한 사용법만 설명합니다. 자세한건 설명서와 옵션을 열심히 보고 고민해야 할듯.

구조는 다음과 같습니다.
db접속요청 -> 커넥션 풀 대몬 -> db 접속
db접속요청이 늘어나도 db 프로세스 갯수는 일정합니다. 커넥션 풀을 이용하여 자원관리를 하는 것입니다.

SQL Relay
http://sqlrelay.sourceforge.net/

SQL Relay is a persistent database connection pooling, proxying and load balancing system for Unix and Linux.

지원 DB는 다음과 같습니다.
* Oracle
* MySQL
* mSQL
* PostgreSQL

 

* Sybase
* MS SQL Server
* IBM DB2
* Interbase

 

* Sybase
* SQLite
* Lago
* ODBC

지원 api
* C
* C++
* Perl

 

* Python
* PHP
* Ruby

 

* Java
* TCL
* Zope

설치방법
http://sqlrelay.sourceforge.net/download.html 에서 SRPM을 이용하여 새로 RPM을 만들었습니다.
설치설명서를 참고하면 여러가지 방법을 이용할 수 있습니다. http://sqlrelay.sourceforge.net/sqlrelay/installing.html

SRPM을 설치하고 RPM을 만들때 여러가지 RPM파일을 요구합니다. 나오는 내용을 보고 설치해주면 됩니다.
gtk-devel 등등.

PHP를 사용하는데 소스로 설치했더니 php-config (php 확장모듈 만들때 쓰지요?) 를 못 찾더군요. 아마도 경로를 지정해주면 될듯한데 그냥 귀찮아서 php rpm을 설치하였습니다. 임시테스팅이 목적이었으므로.

설치시 불필요한 db, api를 명시해주지 않으면 rpm을 만들다가 에러가 납니다.

rpm -ta -without oracle -without zope sqlrelay-xxx.tar.gz

위와 같은 식입니다.

rpmbuild -without db2 -without freetds --without oracle -without zope sqlrelay.spec

나온 파일을 필요에 따라 설치합니다.

[root@kdu i386]# ls -1
sqlrelay-0.35-1.i386.rpm
sqlrelay-client-devel-c-0.35-1.i386.rpm
sqlrelay-client-devel-c++-0.35-1.i386.rpm
sqlrelay-client-mysql-0.35-1.i386.rpm
sqlrelay-client-postgresql-0.35-1.i386.rpm
sqlrelay-client-runtime-c-0.35-1.i386.rpm
sqlrelay-client-runtime-c++-0.35-1.i386.rpm
sqlrelay-clients-0.35-1.i386.rpm
sqlrelay-config-gtk-0.35-1.i386.rpm
sqlrelay-doc-0.35-1.i386.rpm
sqlrelay-man-0.35-1.i386.rpm
sqlrelay-mysql-0.35-1.i386.rpm
sqlrelay-perl-0.35-1.i386.rpm
sqlrelay-php-0.35-1.i386.rpm

# rpm -ivh *.rpm

# rpm -ql sqlrelay | grep bin
/usr/bin/sqlr-cachemanager
/usr/bin/sqlr-listener
/usr/bin/sqlr-listener-debug
/usr/bin/sqlr-scaler
/usr/bin/sqlr-start
/usr/bin/sqlr-stop

# rpm -ql sqlrelay-php
/usr/lib/php4/sql_relay.so -> 이게 php모듈이지요.
/usr/share/pear/DB/sqlrelay.php

sqlrelay rpm으로 설치를 하면 /etc/sqlrelay.conf 파일을 만들어 설정합니다.
샘플은 /etc/sqlrelay.conf.example 입니다.

# ls /etc/sqlrelay.*
/etc/sqlrelay.conf /etc/sqlrelay.conf.example /etc/sqlrelay.dtd

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

아래와 같이 임시로 세팅했습니다.

mysql 의 경우 최소 수정할것
id : instance id. sqlr-start 할때 필요함
dbase : mysql
connections : 초기 연결할 갯수
maxconnections : 최대 접속자

users 는 해당 api에서 접속할때 필요한 사용자, 비밀번호입니다. 나중 php소스코드보면 이해감.

connections는 커넥션 풀을 만들때 사용하는 db, user 등의 정보임.

<?xml version="1.0"?>
<!DOCTYPE instances SYSTEM "sqlrelay.dtd">

<instances>

<instance id="example" port="9000" socket="/tmp/example.socket" dbase="mysql" connections="20" maxconnections="500" maxqueuelength="5" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="nobody" runasgroup="nobody" cursors="5" authtier="listener" handoff="pass" deniedips="" allowedips="" debug="none">
<users>
<user user="user1" password="password1"/>
<user user="user2" password="password2"/>
<user user="user3" password="password3"/>
</users>
<connections>
<connection connectionid="db1" string="user=aaaat;password=aaaa;db=test;host=localhost;port=3306;socket=/var/lib/mysql/mysql.sock;" metric="1"/>
<connection connectionid="db2" string="user=aaaa;password=aaaa;db=test;host=localhost;port=3306;socket=/var/lib/mysql/mysql.sock;" metric="1"/>
<connection connectionid="db3" string="user=aaaa;password=aaaa;db=test;host=localhost;port=3306;socket=/var/lib/mysql/mysql.sock;" metric="1"/>

</connections>
</instance>

</instances>

이제 커넥션풀을 시작합니다.
# sqlr-start -id example -config /etc/sqlrelay.conf

# ps auxw | grep sqlr
nobody 20725 0.0 0.2 3600 1408 ? S 16:11 0:00 sqlr-listener -id example -config /etc/sqlrelay.conf
nobody 20728 0.0 0.3 4288 1720 ? S 16:11 0:00 sqlr-connection-mysql -id example -connectionid db1 -config /etc/sqlr
nobody 20731 0.0 0.3 4292 1720 ? S 16:11 0:00 sqlr-connection-mysql -id example -connectionid db1 -config /etc/sqlr
nobody 20734 0.0 0.3 4292 1720 ? S 16:11 0:00 sqlr-connection-mysql -id example -connectionid db1 -config /etc/sqlr
nobody 20785 0.0 0.3 4288 1720 ? S 16:11 0:00 sqlr-connection-mysql -id example -connectionid db5 -config /etc/sqlr
nobody 20787 0.0 0.2 3572 1368 ? S 16:11 0:00 sqlr-scaler -id example -config /etc/sqlrelay.conf
root 20793 0.0 0.2 3488 1072 ? S 16:11 0:00 sqlr-cachemanager

위에서 보듯이 몇가지 프로세서로 이루어집니다.

끝내기
# sqlr-stop
id를 지정하지 않으면 몽땅 죽입니다.

mysqladmin pro 에서 보면 connections 만큼 mysql 과 연결되어있습니다.

샘플코드 php

# cat sql.php
<?
dl("sql_relay.so");

$con=sqlrcon_alloc("localhost",9000,"","user1","password1",0,1) or die ("connect error");
$cur=sqlrcur_alloc($con);

echo "sendquery";
sqlrcur_sendQuery($cur,"select * from test");

#sqlrcur_sendFileQuery($cur,"/usr/local/myprogram/sql","myquery.sql");
echo "endsession";
sqlrcon_endSession($con);

sqlrcur_sendQuery($cur,"select * from test");
sqlrcon_endSession($con);

sqlrcur_free($cur);
sqlrcon_free($con);
?>

사이트에 나온 소스코드에서는 아래와 같이 나와있는데 " 를 넣어주지 않으면 에러가 납니다. ; 도 빠져있구요.
dl(sql_relay.so)

** 기타참고사이트
http://sqlb.sourceforge.net/frameset.html
The SQLB project is used to improve SQL requests to a database. It supports MySQL, PostgreSQL and Oracle(tm).

It is a set of deamon programs that make multiple permanent connection to one or more database when they start. Then an external program, previously linked with the sqlb client library, can send SQL requests to these deamons and get the result without any need to make a connection/disconnection. The SQLB PHP and Perl modules provided here with SQLB are some examples of such programs.

** phpschool 참고자료
http://www.phpschool.com/bbs2/inc_view.html?id=6888&code=tnt2 : Too many connections 에러와 DB pool 사용
http://www.phpschool.com/bbs2/inc_view.html?id=8132&code=tnt2 : 새로운 요청 처리 방법
http://www.phpschool.com/bbs2/inc_view.html?id=10093&code=tnt2 : 데이터베이스 풀링에 대한 sqlrelay 설치 문서

 

[출처] https://kldp.org/node/45012

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86311
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78767
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95516
118 한국어 BERT, HanBert를 소개합니다. file 졸리운_곰 2020.09.25 2019
117 한국어 자연어 처리 데이터셋 목록 file 졸리운_곰 2020.09.20 2063
116 Google Colab 사용하기 file 졸리운_곰 2020.09.08 3673
115 Deep Learning (Keras) Models Deployment using SQL databases file 졸리운_곰 2020.08.04 1256
114 Deep Learning (Keras) Models Deployment using SQL databases 졸리운_곰 2020.08.04 1007
113 ubuntu에서 pytorch gpu 버전 설치 과정 정리 file 졸리운_곰 2020.07.28 1866
112 DCGAN in Tensorflow [적대적 신경망] file 졸리운_곰 2020.06.07 1304
111 char-rnn char-rnn-tensorflow-master [한글] [korean] file 졸리운_곰 2020.06.07 1015
110 This Repository is Reinforcement Learning Agent FrameWork file 졸리운_곰 2020.06.07 1354
109 anaconda에서 가상환경 삭제하기 졸리운_곰 2020.06.06 1346
108 Tensorflow 1.4 개발 환경 설치(Windows 10, CUDA 8.0, cuDNN v6.0, GPU 버전) file 졸리운_곰 2020.06.06 1054
107 [Tensorflow] Tensorflow GPU 버전 설치하기 file 졸리운_곰 2020.06.06 2303
106 Generative Adversarial Network : DCGAN을 이용한 이미지 생성 file 졸리운_곰 2020.04.20 1514
105 Question answering with TensorFlow file 졸리운_곰 2020.04.06 1395
104 scikit-learn을 활용한 기계 학습 file 졸리운_곰 2020.01.29 1128
103 사이킷런(Scikit-learn) vs 텐서플로우(TensorFlow) 졸리운_곰 2020.01.28 1041
102 char-lstm-rnn-keras, Kinetic korean 한글 file 졸리운_곰 2020.01.28 1518
101 min-char-rnn 한글 주해(3) - 손실값 계산, 그래디언트 계산, 문자 출력함수 file 졸리운_곰 2020.01.28 917
100 min-char-rnn 한글 주해(2) - 메인 루프 file 졸리운_곰 2020.01.28 1179
99 min-char-rnn 한글 주해(1) - 데이터 준비, 변수 초기화 file 졸리운_곰 2020.01.28 1256
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED