최대 동시접속자수 테스트 프로그램
최대 동시접속자 수 테스트용 프로그램입니다.
컴파일 방법:
g++ -o mysql-con-stress -I/usr/local/mysql/include/mysql/ -L/usr/local/mysql/lib/mysql/ -lmysqlclient mysql-con-stress.cc
사용방법:
./mysql-con-stress host user pass max_tries
host : 예를 들면 localhost
user : root
pass : 암호
max_tries : 최대동시접속자 수
성공시:
Successefully established 1500 connections
Never failed
Cleaning up 1500 connections ...
Clean up complete
실패시:
Successefully established 1501 connections
Failed because Too many connections
Cleaning up 1501 connections ...
Clean up complete
MySQL Client 상에서 최대 동시접속 확인법:
show status like max_used_connections;
이 결과값이 max_tries와 일치하여야 함.
주의사항: mysql_connect 함수가 deprecate 되었으므로 mysql_real_connect 함수로 수정하였습니다. 자신의 MySQL버젼에서 오류가 발상할 경우 mysql_init() 부분을 삭제하고 mysql_real_connect 함수를 mysql_connect()함수로 수정바랍니다.
/*
* mysql-con-stress.cc by Sasha Pachev
* Stresses a running mysqld to see the maximum number of additional concurrent
* connections it can handle
* to compile: g++ -o mysql-con-stress -I<where_mysql.h_is_found> r
-L<where-libmysqlclient-is-found> mysql-con-stress.cc -lmysqlclient
* to use: mysql-con-stress host user pass max_tries
* If the first three parameters are not obvious, you should not be using this program
* max_tries is the maximum number of concurrent connection mysql-con-stress will try to
* estabilsh
*/
#include <mysql.h>
#include <iostream.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
int num_cons = 0;
MYSQL* glob_cons = NULL;
void clean_up(int )
{
int i;
cerr << Cleaning up << num_cons << connections ... << endl;
for(i = 0; i < num_cons; i++)
{
mysql_close(glob_cons + i);
}
cerr << Clean up complete << endl;
exit(0);
}
void usage()
{
cerr << Usage: mysql-con-stress host user pass max_tries << endl;
exit(1);
}
int main(int argc, char** argv)
{
if(argc != 5) usage();
char* user, *host, *pass;
int max_tries;
user = argv[2];
host = argv[1];
pass = argv[3];
max_tries = atoi(argv[4]);
MYSQL cons[max_tries];
glob_cons = cons;
int i;
int never_failed = 1;
int port = 0;
// if we get a signal, clean up first
signal(SIGTERM, clean_up);
signal(SIGINT, clean_up);
// establish as many connections as we can
for(i = 0; i < max_tries; i++)
{
mysql_init(&cons);
mysql_real_connect(cons + i, host, user, pass, test, 0, NULL, 0);
num_cons = i ;
if((mysql_error(cons + i))[0])
{
never_failed = 0;
cout << Successefully established << num_cons << connections << r
endl; cout << Failed because << mysql_error(cons + i) << endl;
break;
}
}
if(never_failed)
{
num_cons = i ;
cout << Successefully established << num_cons << connections << endl;
cout << Never failed << endl;
}
// this is really not necessary, because exiting will close all the connection,
// but it is good practice to clean up
clean_up(0);
return 0;
}
[출처] rootman | rootman (http://www.rootman.co.kr/bbs/zboard.php?id=linux&no=1900)
'리눅스 > MySQL' 카테고리의 다른 글
my.cnf에 wait_timeout설정하는 문제 (0) | 2015.01.16 |
---|---|
오라클 클라이언트(Oracle Client) 설치 (0) | 2015.01.16 |
error while loading shared libraries: libmysqlclient.so.10: cannot open shared object file: No such file or directory (0) | 2015.01.16 |
zmanda를 사용한 쉬운 MySQL 백업과 복구 (증분백업 가능) (0) | 2015.01.16 |
[그누보드] mysql 4.0 이하에서 4.1 이상으로 서버이전후 로그인 안될때 (0) | 2015.01.16 |