mysql c api 設定執行時的 timeout 時間

int fnSetTimeout(int timeout) {
  char **row;
  char sql[100];
  char data[200];

  sprintf(sql,"set session wait_timeout=%d",timeout);
  if ( mysql_real_query( &mysql, sql, strlen(sql) ) ) {
    printf("FAILED : %s\n",sql);
    exit(3);
  }

  sprintf(sql,"set session interactive_timeout=%d",timeout);
  if ( mysql_real_query( &mysql, sql, strlen(sql) ) ) {
    printf("FAILED : %s\n",sql);
    exit(3);
  }

  strcpy(sql,"select @@session.interactive_timeout" );
  if ( mysql_real_query( &mysql, sql, strlen(sql) ) ) {
    printf("FAILED : %s\n",sql);
    exit(3);
  }

  if ( (result=mysql_store_result(&mysql)) != NULL ) {
    row=mysql_fetch_row(result);
    strcpy( data, row[0] );
    mysql_free_result( result );
    timeout=atoi(data);
  } else {
    timeout=0;
  }

  return(timeout);
}

adject file descriptors

On Unix, each TCP/IP connection uses a file descriptor, so you must increase the total number of descriptors available to the operating system, and also increase the maximum number of descriptors each process is allowed to use. All Unix style operating systems have a “ulimit” shell command (sh and bash) which can allow more open file descriptors to commands started in that shell, once the appropriate kernel tweak has been made. We recommend “ulimit -n 8192”. Here are our recommended kernel tweaks:

Linux: “echo 65536 > /proc/sys/fs/file-max” changes the number of system-wide file descriptors

FreeBSD: append to /etc/sysctl (or you can use sysctl -w to add these)

kern.maxfiles=65536
kern.maxfilesperproc=32768

Solaris: add the following to /etc/system and reboot:

set rlim_fd_max=0x8000
set rlim_fd_cur=0x8000