database.sarang.net
UserID
Passwd
Database
ㆍDBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DBMS Tutorials 1065 게시물 읽기
 News | Q&A | Columns | Tutorials | Devel | Files | Links
No. 1065
[참고자료] 공개커넥션풀 프로그램 (connection pooling)
작성자
문태준(taejun)
작성일
2004-12-24 16:23ⓒ
2004-12-25 11:01ⓜ
조회수
22,995

공개커넥션 풀 프로그램 설명

http://tunelinux.pe.kr

http://database.sarang.net

2004.12.24

문태준

 

커넥션 풀은 프로그램(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

 

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

 

mysql 의 경우 최소 수정할것

id : instance id. sqlr-start 할때 필요함

dbase : mysql

connections : 초기 연결할 갯수

maxconnections : 최대 접속자

 

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

 

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

 

 

 

 

 

 

 

이제 커넥션풀을 시작합니다.

# 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)

 

 

 

** SQLB

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.

 

** 기타 참고자료

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 설치 문서

http://www.openphp.com/board/board_center.html?Type=View&tb_name=board_php_study&id=50&start=0&id_no=16 : [DB] DB Connection Pool 에 대해 간략한 설명 (여기 사이트에 sqlb와 sqlrelay 에 대한 소개자료는 있지만 상세한 사용법은 없음)

[Top]
No.
제목
작성자
작성일
조회
1065[참고자료] 공개커넥션풀 프로그램 (connection pooling)
문태준
2004-12-24
22995
1057Howto Install Tomcat 5 + Apache 2 in WinXP
정재익
2004-12-09
14887
923Apache Module mod_authn_dbi
정재익
2004-02-15
15509
916Client/Server Database System
정재익
2004-02-05
13806
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.052초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다