Skip to Content.
Sympa Menu

freetds - Re: [freetds] Connection Pool crashing problems?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: craigs <s.craig AT andronics.com>
  • To: brian AT bruns.com, FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Cc:
  • Subject: Re: [freetds] Connection Pool crashing problems?
  • Date: Fri, 10 Dec 2004 10:30:24 +0000

here is a detailed list of what we are running! we have a suse 9.2 linux server, using tds version 4.2 for connection pooling, snapshot freetds-0.64.dev.20041207, client programs written in C using db-lib. the pool goes down at least a few times every hour, we are using 3 max connections and receiving approx 1200 clients an hour and each client does at least 2 querys and an insert with few doing 1 or 2 more.

we have written a process watcher that watchs the connection pool and restarts it if it crashes, before we added a patch it would take the connection pool nearly a minute to come back up, it wouldnt release the socket, or the socket had to wait to time out, now the pool comes back up again within a few seconds.

here is the function we have changed, basically all we did was add 2 lines. Location of file changed: /freetds//src/pool/main.c
Function changed: void pool_main_loop(TDS_POOL * pool)

here is a copy of the function with changes highlighted in ******

Hope this is off use to someone!

void pool_main_loop(TDS_POOL * pool)
{
TDS_POOL_USER *puser;
TDS_POOL_MEMBER *pmbr;
struct sockaddr_in sin;
int s, maxfd, i;
int retval;
fd_set rfds;

/* fix me -- read the interfaces file and bind accordingly */
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(pool->port);
sin.sin_family = AF_INET;

if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket");
exit(1);
}

********************************************************************************
/* Set socket options so we can restart the pool */
int socktrue = 1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,&socktrue,sizeof socktrue);
*********************************************************************************

fprintf(stderr, "Listening on port %d\n", pool->port);
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
perror("bind");
exit(1);
}
listen(s, 5);

FD_ZERO(&rfds);
FD_SET(s, &rfds);
maxfd = s;

while (!term) {
fprintf(stderr, "waiting for a connect\n");
retval = select(maxfd + 1, &rfds, NULL, NULL, NULL);
if (term)
continue;

/* process the sockets */
if (FD_ISSET(s, &rfds)) {
puser = pool_user_create(pool, s, &sin);
}
pool_process_users(pool, &rfds);
pool_process_members(pool, &rfds);
/* back from members */
if (waiters) {
pool_schedule_waiters(pool);
}

FD_ZERO(&rfds);
/* add the listening socket to the read list */
FD_SET(s, &rfds);
maxfd = s;

/* add the user sockets to the read list */
for (i = 0; i < pool->max_users; i++) {
puser = (TDS_POOL_USER *) & pool->users[i];
/* skip dead connections */
if (!IS_TDSDEAD(puser->tds)) {
if (puser->tds->s > maxfd)
maxfd = puser->tds->s;
FD_SET(puser->tds->s, &rfds);
}
}

/* add the pool member sockets to the read list */
for (i = 0; i < pool->num_members; i++) {
pmbr = (TDS_POOL_MEMBER *) & pool->members[i];
if (!IS_TDSDEAD(pmbr->tds)) {
if (pmbr->tds->s > maxfd)
maxfd = pmbr->tds->s;
FD_SET(pmbr->tds->s, &rfds);
}
}
} /* while !term */
close(s);
for (i = 0; i < pool->max_users; i++) {
puser = (TDS_POOL_USER *) & pool->users[i];
if (!IS_TDSDEAD(puser->tds)) {
fprintf(stderr, "Closing user %d\n", i);
tds_close_socket(puser->tds);
}
}
for (i = 0; i < pool->num_members; i++) {
pmbr = (TDS_POOL_MEMBER *) & pool->members[i];
if (!IS_TDSDEAD(pmbr->tds)) {
fprintf(stderr, "Closing member %d\n", i);
tds_close_socket(pmbr->tds);
}
}
}

Brian Bruns wrote:

Craig,

Wanna send along the patch for that? I'll merge it. I've been
planning on spending some time on this, and may get around to it this
weekend. What is your server/version?

I'll try to do some load testing and see if I can reproduce your error
locally, and failing that scan the code for something.

Brian

On Thu, 09 Dec 2004 09:17:32 +0000, craigs <s.craig AT andronics.com> wrote:

Frediano Ziglio wrote:




Il mer, 2004-12-08 alle 13:52, craigs ha scritto:



Brian Bruns wrote:

Program received signal SIGSEGV, Segmentation fault.
0x0804b5b0 in pool_process_users (pool=0x804d008, fds=0xbfffdbd0) at
user.c:131
131 if (FD_ISSET(puser->tds->s, fds)) {

is this any help?

Shaun.




Yes, probably puser->tds == NULL or puser->tds->s < 0. In other words
connection closed

freddy77




Any ideas why the connection is closing, would it be on my C clients
side or maybe something to do with ms sql. when it does crash it takes
nearly a minute to come up again which can cause problems for ourselfs,
we have added a line in pool_main_loop which releases the socket as soon
it crashes, our up time again has been greatly reduced because of this
line, would this be of any use to anyone?




_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds



_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds


_______________________________________________
FreeTDS mailing list
FreeTDS AT lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds






Archive powered by MHonArc 2.6.24.

Top of Page