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

 
 

커넥션 풀은 프로그램(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 86229
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78693
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95434
72 [R library] library(XML) # install.packages("XML") 인스톨 에러 졸리운_곰 2023.05.06 1177
71 [R 데이터 분석] Titanic: Machine Learning from Disaster (타이타닉 생존 예측) file 졸리운_곰 2023.04.29 1178
70 [R 데이터 분석] R 유명한 패키지 정리 졸리운_곰 2023.04.24 1906
69 [R 데이터 분석] Shiny : 대시보드 배포하기 file 졸리운_곰 2023.03.19 1414
68 [stat(통계) R 언어] 유명하고 많이 사용하는 R 패키지 정리 졸리운_곰 2022.04.19 1297
67 [R 데이터 분석] anaconda에서 R 사용하기 file 졸리운_곰 2022.01.16 1307
66 [R 데이터 분석] Using C/C++ in R , R언어에서 C/C++ 사용하기 졸리운_곰 2021.11.21 1647
65 [데이터 통계분석 R언어] Shiny 웹앱 개발 졸리운_곰 2021.02.14 1389
64 How to Deploy Interactive R Apps with Shiny Server file 졸리운_곰 2021.02.13 1214
63 [통계, 데이터분석 언어 R] R Shiny Server를 사용해 보자. 졸리운_곰 2021.02.13 1415
62 통계분석툴 R & MongoDB 연동 방법 file 졸리운_곰 2020.12.12 1822
61 Reading OECD.Stat into R file 졸리운_곰 2019.04.04 1871
60 Scrape OECD Data by R lang : R언어로 OECD.net 데이터 가져오기 졸리운_곰 2019.04.04 1485
59 윈도우에서 통계 분석 프로그램 R Project 활용 방안 file 졸리운_곰 2018.12.24 1699
58 C#과 R을 연동하기 file 졸리운_곰 2018.12.24 1555
57 Use R in C# : C#에서 R 사용 졸리운_곰 2018.12.24 1549
56 R 언어_ 범주형 자료(factor) 함수 사용 file 졸리운_곰 2018.12.22 1665
55 R - 도수분포표/교차표, table( )함수 file 졸리운_곰 2018.12.22 1429
54 주피터 노트북에 R 커널 설치하기 + 아나콘다 설치 file 졸리운_곰 2018.12.21 2312
53 R기초입문_r_book_mac_v3.pdf file 졸리운_곰 2018.12.20 1590
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED