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
운영게시판
최근게시물
MySQL Columns 16454 게시물 읽기
 News | Q&A | Columns | Tutorials | Devel | Files | Links
No. 16454
최대 동시접속자수 테스트 프로그램
작성자
김주현(mania1217)
작성일
2002-07-10 13:42
조회수
20,775

최대 동시접속자 수 테스트용 프로그램입니다.

 

컴파일 방법:

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;

}

[Top]
No.
제목
작성자
작성일
조회
19889MySQL 4.0이상에서 형변환 함수, CAST(), CONVERT()
강병기
2003-08-26
75165
16737MySQL 4.1에서 구현 예정인 기능들 [3]
김주현
2002-08-06
19255
16455MySQL 최적화 configure 옵션 [1]
김주현
2002-07-10
16608
16454최대 동시접속자수 테스트 프로그램
김주현
2002-07-10
20775
16451InnoDB Performance tuning tips
김주현
2002-07-10
15898
16394MySQL에서도 Procedure를 MyLua [1]
김주현
2002-07-03
9513
13686MySQL 을 지원하는 Database Design Tool [3]
정재익
2001-11-19
11170
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.049초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다